質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Circle CI

Circle CIは、クラウド上に簡単にCI環境を構築できるWebサービスです。GitHubと連携させ、CIしたいリポジトリーを選択しビルド・テストを行います。チャット等を利用して結果を確認することが可能です。

Q&A

1回答

692閲覧

circleCIで自動デプロイ と自動テストを実行したい

keisuke.F

総合スコア19

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Circle CI

Circle CIは、クラウド上に簡単にCI環境を構築できるWebサービスです。GitHubと連携させ、CIしたいリポジトリーを選択しビルド・テストを行います。チャット等を利用して結果を確認することが可能です。

0グッド

0クリップ

投稿2020/09/19 08:28

編集2022/01/12 10:55

お世話になっております。

現在docker環境でcircleCIで自動デプロイ 、自動テストに挑戦しています。
いろいろな記述方法を行う中で、とうとうciecleCIで出たエラーに詰まってしまいました。

#エラー文 circleCIより

#!/bin/bash -eo pipefail bundle exec rake db:create Unknown MySQL server host 'db' (-2) Couldn't create 'LuggageMGT_test' database. Please check your configuration. rake aborted!

#試した事
bundlerのバージョン指定でエラーが出ている様で、bundlerをuninstallし、新たにインストールしました。

rspecはインストール済みです。

config.yml

version: 2 jobs: build: docker: - image: circleci/ruby:2.5.3-node-browsers environment: RAILS_ENV: 'test' - image: circleci/mysql:5.6.47 environment: MYSQL_ROOT_PASSWORD: "password" MYSQL_ROOT_HOST: "%" working_directory: ~/app_name steps: - checkout - restore_cache: # キャッシュを読み込む keys: - gem-cache-v1-{{ checksum "Gemfile.lock" }} - gem-cache-v1- - run: name: Bundle Install command: bundle check --path vendor/bundle || bundle install --deployment - save_cache: # キャッシュを保存する key: gem-cache-v1-{{ checksum "Gemfile.lock" }} paths: - vendor/bundle - run: name: Wait for DB command: dockerize -wait tcp://127.0.0.1:3306 -timeout 120s - run: bundle exec rake db:create - run: bundle exec rake db:schema:load - run: name: run tests command: | mkdir /tmp/test-results TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)" bundle exec rspec --format progress \ --out /tmp/test-results/rspec.xml \ --format progress \ $TEST_FILES - store_test_results: path: /tmp/test-results - store_artifacts: path: /tmp/test-results destination: test-results - add_ssh_keys: fingerprints: - "1f:d5:4b:1c:ed:c1:92:6e:47:a1:e0:18:a0:ff:27:ca" - deploy: name: Capistrano deploy command: | if [ "${CIRCLE_BRANCH}" != "master" ]; then exit 0 fi bundle exec cap production deploy unicorn:restart

dockerfile

FROM ruby:2.5.3 RUN apt-get update -qq && \ apt-get install -y build-essential \ libpq-dev \ nodejs RUN mkdir /app_name ENV APP_ROOT /app_name WORKDIR $APP_ROOT ADD ./Gemfile $APP_ROOT/Gemfile ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock RUN bundle install ADD . $APP_ROOT

docker-compose.yml

version: '3' services: web: build: . ports: - "3000:3000" links: - db tty: true command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/app_name depends_on: - db db: image: mysql:5.6.47 environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: root ports: - "4306:3306" volumes: - ./tmp/db:/var/lib/mysql/data volumes: bundle: mysql_data:

database.yml.ci

test: adapter: mysql2 encoding: utf8 pool: 5 username: 'root' port: 3306 host: '127.0.0.1' database: LuggageMGT_test

下記コマンド実装結果です。

name@mbp リポジトリ名 % bundler -v Bundler version 1.17.3

追記です。

config.yml内の

- run: mv config/database.yml.ci config/database.yml

を削除したら、circleCIのエラーが変わりました。
下記がエラーです。

#!/bin/bash -eo pipefail bundle exec rake db:create Unknown MySQL server host 'db' (-2) Couldn't create 'LuggageMGT_test' database. Please check your configuration. rake aborted! Mysql2::Error::ConnectionError: Unknown MySQL server host 'db' (-2) /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `initialize' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `new' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `mysql2_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_handling.rb:118:in `retrieve_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/connection_handling.rb:90:in `connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/mysql_database_tasks.rb:6:in `connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/mysql_database_tasks.rb:14:in `create' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:119:in `create' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:313:in `each' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:138:in `create_current' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.4/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <top (required)>' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>' /usr/local/bundle/bin/bundle:23:in `load' /usr/local/bundle/bin/bundle:23:in `<main>' Tasks: TOP => db:create (See full trace by running task with --trace) Exited with code exit status 1 CircleCI received exit code 1

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

「db という MySQL サーバーのホストは見つかりません」
というエラーメッセージに気づいていますか?:

console

1Unknown MySQL server host 'db' (-2)

現在の実装では
「CircleCI 上で Docker Compose を使っていない」
ということを理解していますか?

Docker Compose を使わない場合の CircleCI 実装例はこちらです:
Database Configuration Examples - CircleCI

Docker Compose を使う場合の CircleCI 実装例はこちらです:
Installing and Using docker-compose - CircleCI

投稿2020/09/19 10:37

y_shinoda

総合スコア3272

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

keisuke.F

2020/09/20 06:56 編集

いつもお世話になっております。 理解ができておらず、どちらのやり方も試してみましただ、まだまだ時間がかかりそうでしたので、今回は使わない方法で実装しようと思います。 というのも、22日までに完成をさせなければいけない状況でして、アプリの内容自体は概ねできているのですが、まだまだ追加実装も必要なためです。 現状のconfig.ymlを本文に編集して記載しました。 現状も本文にございますエラーで止まってしまっています。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問