0
0

More than 1 year has passed since last update.

(未解決)[TravisCI]The command "docker-compose exec --env 'RAILS_ENV=test' web rails db:migrate" exited with 1.というエラー

Last updated at Posted at 2021-10-03

はじめに

本記事は、備忘録として現在解決中のエラーを記述します。

コード

Dockerfile
FROM ruby:2.5
RUN apt-get update && apt-get install -y \
    build-essential \
    libpq-dev \
    nodejs \
    postgresql-client \
    yarn

WORKDIR /product-register
COPY Gemfile Gemfile.lock /product-register/
RUN bundle install
docker-compose.yml
version: '3'

volumes:
  db-data:

services:
  web:
    build: .
    ports:
      - '3000:3000'
    volumes:
      - '.:/product-register'
    environment:
      - 'DATABASE_PASSWORD=postgres'
    tty: true
    stdin_open: true
    depends_on:
      - db
    links:
      - db

  db:
    image: postgres
    volumes:
      - 'db-data:/var/lib/postgresql/data'
    environment:
      - 'POSTGRES_USER=postgres'
      - 'POSTGRES_PASSWORD=postgres'
      - 'POSTGRES_HOST_AUTH_METHOD=trust'
travis.yml
sudo: required

services: docker

before_install:
  - docker-compose up --build -d

script:
  - docker-compose exec --env 'RAILS_ENV=test' web rails db:create
  - docker-compose exec --env 'RAILS_ENV=test' web rails db:migrate
  - docker-compose exec --env 'RAILS_ENV=test' web rails test

ここから、ターミナルにて以下を入力。

% git add .

% git commit -m 'update travis and compose'

% git push origin master  

TravisCIにて、確認したところ、
エラーが発生。

curl: (22) The requested URL returned error: 404 Not Found
Required ruby-2.5.9 is not installed - installing.
/home/travis/.rvm/scripts/fetch: line 104: log: command not found
Checking fallback: ftp://rubies.travis-ci.org/ubuntu/16.04/x86_64/ruby-2.5.9.tar.bz2?rvm=1.29.10
Checking fallback: https://www.mirrorservice.org/sites/rubies.travis-ci.org/ubuntu/16.04/x86_64/ruby-2.5.9.tar.bz2?rvm=1.29.10
No fallback URL could be found, try increasing timeout with:

line 104?

104  API version:      1.38 (minimum version 1.12)
Downloading https://rubies.travis-ci.org/ubuntu/16.04/x86_64/ruby-2.5.9.tar.bz2 failed.
Mounting remote ruby failed with status 2, stopping installation.
Checking requirements for ubuntu.
Requirements installation successful.
curl: (22) The requested URL returned error: 404 Not Found
Installing Ruby from source to: /home/travis/.rvm/rubies/ruby-2.5.9, this may take a while depending on your cpu(s)...
curl: (22) The requested URL returned error: 404 Not Found
Caused by:
KeyError: key not found: "DATABASE_PASSWORD"
.
.
.
The command "docker-compose exec --env 'RAILS_ENV=test' web rails db:create" exited with 1.
Caused by:
KeyError: key not found: "DATABASE_PASSWORD"
.
.
.
The command "docker-compose exec --env 'RAILS_ENV=test' web rails db:migrate" exited with 1.
Caused by:
KeyError: key not found: "DATABASE_PASSWORD"
.
.
.
The command "docker-compose exec --env 'RAILS_ENV=test' web rails test" exited with 1.

仮説

①まず、DATABASE_PASSWORDのキーが見つからないということは、docker-composeとpostgresがうまく繋がっていない。

ubuntuのrequirementsを確認しろと怒られているので、ubuntuのバージョンが違う。

③DockerfileにCMD記載がないのがダメ。

未解決

何とかして、明日にはエラーを解決したいと思います。
また、解決次第、編集いたします。

以下参考サイトです。
CICDパイプラインからローカルで開発中のアプリをherokuにデプロイするの巻(Rails / postgresql / Docker / TravisCI)
Quickstart: Compose and Rails
RVM fails to download truffleruby-head in TravisCI with 429 too many requests #4992
Not able to install ruby 2.2.4
Docker cannot establish connection with postgresql in Travis CI
PostgreSQL(Docker)にRails(Docker)が接続できなくなったから調べてみた。(could not translate host name "db" to address: Name or service not known)

引き続き頑張ります!

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