CICD 中的端口转发(Github Actions)

Asu*_*sur 6 ssh portforwarding github-actions cicd

我想在 Github Actions 中运行数据库迁移。数据库位于堡垒后面。

我的解决方案是通过堡垒将 Postgres 端口 5432 转发到数据库主机。

我尝试了下面的脚本,但似乎不起作用。

mkdir ~/.ssh
ssh-keyscan -H <bastion_ip>  >> ~/.ssh/known_hosts
echo "${{secrets.BASTION_SSH_KEY}}" >> key
chmod 600 ./key
ssh -T -i ./key -L 5432:<db_host_url>:5432 user@<bastion_ip> &
make migrate
rm ./key
Run Code Online (Sandbox Code Playgroud)

make migrate针对 运行迁移localhost:5432

当我运行管道时出现以下错误

Error:  AssertionError [ERR_ASSERTION]: ifError got unwanted exception: connect ECONNREFUSED 127.0.0.1:5432
Run Code Online (Sandbox Code Playgroud)

无论如何要修复它吗?我对其他方式持开放态度。

Asu*_*sur 4

谢谢@larsks,我已经成功了。为了让它正常工作,我必须改变一些事情。

  1. -fN按照@larsks的建议添加
  2. 用于ssh-agent处理钥匙

下面是工作代码片段:

mkdir ~/.ssh
ssh-keyscan -H <bastion_ip> >> ~/.ssh/known_hosts
eval `ssh-agent -s`
ssh-add - <<< "${{secrets.BASTION_SSH_KEY}}"
ssh -fN -v -L 5432:<db-host>:5432 user@<bastion_ip>
make migrate
Run Code Online (Sandbox Code Playgroud)