LoginSignup
3
1

More than 1 year has passed since last update.

github actions rspec

Last updated at Posted at 2020-01-03

成果物

.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

役に立った

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

3
1
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
3
1