##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