GitHub Actions是否可以定义主机映射?

12

现在我正在使用GitHub Actions来构建我的项目。在我的本地机器上,我使用/etc/hosts定义本地主机地址映射,如下所示:

11.19.178.213 postgres.dolphin.com

我的数据库配置如下:

spring.datasource.druid.post.master.jdbc-url = jdbc:postgresql://postgres.dolphin.com:5432/dolphin

在我的生产服务器上,我可以编辑映射来定位数据库的不同IP地址。但现在我正在GitHub Actions中运行单元测试。如何编辑主机映射以使数据库映射到GitHub Actions容器?我像这样在GitHub Actions中定义了容器:
jobs:
  build:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:13.2
        env:
          POSTGRES_PASSWORD: postgrespassword
          POSTGRES_DB: dolphin
          POSTGRES_USER: postgres
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

我应该怎样处理主机映射?我已经查阅了文档,但是没有找到有关这个问题的信息。

1个回答

25

就像这样做:

- name: Add hosts to /etc/hosts
  run: |
      sudo echo "127.0.0.1 postgres.dolphin.com" | sudo tee -a /etc/hosts

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接