2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PG::ConnectionBad: could not translate host name "db" to address: Temporary failure in name resolution

Posted at

##GitHubActionsにて
オリジナルアプリにGitHubActionsを入れるべく悪戦苦闘する中
こんなエラーが発生

PG::ConnectionBad:
  could not translate host name "db" to address: Temporary failure in name resolution

むむむ。。
データベースに接続できない。。

色々と調べた結果、以下を参考にし、修正しました。
https://qiita.com/kajirikajiri/items/bf0ead854bba58131040
https://stackoverflow.com/questions/3582552/postgresql-connection-url/20722229#20722229
Postgresqlのポートを指定し、DATABASE_URLを明示しました。

修正前

.github/workflows/ruby.yml

name: Ruby

on:
  pull_request:
    branches:
    - master
    

jobs:
  run_spec:
    name: Run spec

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1 
    - name: Set up Ruby 2.6
      uses: actions/setup-ruby@v1 # https://github.com/actions/setup-ruby/blob/master/action.yml
      with:
        ruby-version: 2.6.x
    - name: Test with Rspec
      run: |
        gem install bundler
        bundle install --path vendor/bundle --quiet --jobs 4 --retry 3
        bundle exec rspec

修正後

.github/workflows/ruby.yml
name: Ruby

on:
  pull_request:
    branches:
    - master

jobs:
  run_spec:
    name: Run spec

    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:10.3
        ports: ["5432:5432"]
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
    steps:
    - uses: actions/checkout@v1 
      uses: actions/setup-ruby@v1 
      with:
        ruby-version: 2.6.x
    - name: Test with Rspec
      env:
        RAILS_ENV: test
        DATABASE_URL: postgresql://postgres@localhost:5432/postgres?encoding=utf8&pool=5&timeout=5000
      run: |
        gem install bundler
        bundle install --path vendor/bundle --quiet --jobs 4 --retry 3
        bundle exec rspec

スクリーンショット 2020-07-01 17.43.13.png 無事に成功しました!
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?