成果物
.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
エラー2
Could not locate Gemfile
解決策
Gemfileが存在するdirectoryに移動する
cd docker/api/api
エラ-3
戦闘
エラーですぎ。うれしい。エラーでないと死ぬ
OSが本番環境と違うと思った。とりあえずOK
https://rocky-plateau-44026.herokuapp.com/
https://github.com/kajirikajiri/rails-api