Help us understand the problem. What is going on with this article?

github actions rspec

成果物

.github/workflows/ruby.yml
name: Ruby

on: [push]

jobs:
  build:

    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
    - name: Set up Ruby 2.5
      uses: actions/setup-ruby@v1
      with:
        ruby-version: 2.5
    - name: Install PostgreSQL client
      run: |
        sudo apt-get -yqq install libpq-dev dialog apt-utils
    - name: Build App
      env:
        RAILS_ENV: test
        DATABASE_URL: postgresql://postgres@localhost:5432/postgres?encoding=utf8&pool=5&timeout=5000
      run: |
        gem install bundler:1.16.1
        cd docker/api/api
        bundle install --quiet --jobs 4 --retry 3
        bin/rails db:migrate:reset RAILS_ENV=test
    - name: Build and test with Rspc
      env:
        RAILS_ENV: test
        DATABASE_URL: postgresql://postgres@localhost:5432/postgres?encoding=utf8&pool=5&timeout=5000
      run: |
        cd docker/api/api
        bundle exec rspec
config/database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgres
  password:
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myApi_development

test:
  <<: *default
  database: postgres_test
  url: <%= ENV['DATABASE_URL'].gsub('?', '_test?' ) %>

production:
  <<: *default
  database: myApi_production
  username: myApi
  password: <%= ENV['MYAPI_DATABASE_PASSWORD'] %>
  url: <%= ENV['DATABASE_URL'] %>

はまった

エラー1

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

役に立った

https://stackoverflow.com/a/20722229

postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]

stackoverflowを見る限り、localhostにしておけばいいっぽい。
てことで、これでなおった

before
      env:
        RAILS_ENV: test
        DATABASE_URL: postgresql://postgres@postgres:5432/postgres?encoding=utf8&pool=5&timeout=5000
----------
after
      env:
        RAILS_ENV: test
        DATABASE_URL: postgresql://postgres@localhost:5432/postgres?encoding=utf8&pool=5&timeout=5000

image.png


エラー2

Could not locate Gemfile

解決策

Gemfileが存在するdirectoryに移動する

        cd docker/api/api

エラ-3


戦闘

image.png

エラーですぎ。うれしい。エラーでないと死ぬ
OSが本番環境と違うと思った。とりあえずOK
https://rocky-plateau-44026.herokuapp.com/
https://github.com/kajirikajiri/rails-api

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした