如何解决CICD 中的端口转发Github Actions
我想在 Github Actions 中运行数据库迁移。 DB 在堡垒后面。
我的解决方案是通过堡垒将 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
make migrate
针对 localhost:5432
运行迁移。
运行管道时出现以下错误
Error: AssertionError [ERR_ASSERTION]: ifError got unwanted exception: connect ECONNREFUSED 127.0.0.1:5432
无论如何要修复它? 我愿意接受其他方式。
解决方法
我认为您的 ssh
命令不正确,试试这个:
ssh -fN -i ./key -L 5432:<db_host>:5432 user@<bastion_ip>
来自手册页:
-f Requests ssh to go to background just before command execution.
This is useful if ssh is going to ask for passwords or passphrases,but the user wants it in the background. This implies -n. The
recommended way to start X11 programs at a remote site is with
something like ssh -f host xterm.
还有:
-N Do not execute a remote command. This is useful for just
forwarding ports.
,
谢谢@larsks,我成功了。 有几件事我必须改变才能让它工作。
- 按照@larsks的建议添加了
-fN
- 使用
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。