You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从GitHub Actions工作流步骤容器访问Runner主机?

问题:GitHub Action容器内Liquibase无法通过SSM端口转发连接AWS RDS PostgreSQL

场景说明

需要在GitHub Action中执行Liquibase迁移至AWS RDS PostgreSQL实例,由于该RDS实例位于私有子网,使用EC2堡垒实例通过SSM会话管理器实现端口转发。但运行在容器内的Liquibase步骤无法正常连接数据库。

错误信息

Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections

GitHub Action工作流代码

- name: SSM Port Forward
    uses: enkhjile/aws-ssm-remote-port-forwarding-action@v1.0.0
    with:
      target: ${{ vars.TARGET }}
      host: ${{ vars.HOST }}
      port: 5432
      local-port: 5432

  - name: Run Liquibase Migration
    uses: liquibase-github-actions/update@v4.31.0
    with:
      username: ${{ secrets.USERNAME }}
      password: ${{ secrets.PASSWORD }}
      url: "jdbc:postgresql://________:5432/${{ vars.DB_NAME }}"

已尝试的排查操作

  • 在工作流中使用Telnet和NC工具验证5432端口可访问,结果正常
  • 在工作流中使用PSQL验证数据库连接,可成功连接
  • 为Liquibase步骤尝试多种URL主机参数:localhost、127.0.0.1、172.17.0.1、host.docker.internal、GitHub Runner的公网IP

内容的提问来源于stack exchange,提问作者Myrkytyn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:12:07