簡體   English   中英

無法將主機名“postgres”轉換為 github 操作上的地址

[英]Could not translate host name "postgres" to address on github actions

我正在配置我的第一個 Github 操作工作流。 它需要 postgres,所以我添加了這樣的服務:

    services:
      postgres:
        image: postgres:latest
        env:
          POSTGRES_DB: postgres_db
          POSTGRES_PASSWORD: postgres_password
          POSTGRES_PORT: 5432
          POSTGRES_USER: postgres_user
        ports:
          - 5432:5432
        # set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

但是 Github 操作無法使用postgres主機。 有以下步驟:

    steps:
    - uses: actions/checkout@v3

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v3
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install PostgreSQL client   
      run: |
        sudo apt-get update
        sudo apt-get install --yes postgresql-client

    - name: Test database connection
      run: psql -h postgres -d postgres_db -U postgres_user -c 'SELECT 1;'
      env:
        PGPASSWORD: postgres_password

而失敗:

Run psql -h postgres -d postgres_db -U postgres_user -c 'SELECT 1;'
psql: error: could not translate host name "postgres" to address: Temporary failure in name resolution

Github 操作工作流程頁面可在此處獲得: https://github.com/buxx/rolling/actions/runs/3092460076/jobs/5003751698 整個配置文件在這里: https://github.com/buxx/rolling/blob/3e4d200e5e111d3731d7fc8d18e5795a0b82ca9a/.github/workflows/pr-tests.yml

如何配置 Github 操作工作流才能使用 postgresql 服務?

沒有關於在容器中執行步驟的特殊指示,步驟正在運行器上運行。 因此,要使用的 postgres 主機是localhost

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM