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

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

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

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Ruby on Rails

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

Docker

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

Circle CI

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

Q&A

0回答

509閲覧

circleciでrspecテストを実行したい(docker, ruby on rails)

kazuyoshi-tech

総合スコア4

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Ruby on Rails

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

Docker

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

Circle CI

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

0グッド

0クリップ

投稿2020/01/08 02:16

編集2022/01/12 10:55

前提・実現したいこと

・環境
docker 3
ruby 2.5.7
rails 5.2.4

・やりたいこと
rails アプリケーションをgithubにpushした際にcircleciでrspecのテストを実行したい
しかし下記のエラーが出ているためうまくいかずに困っています。
原因分かるかたがお見えになりましたら、ご教授いただければと思います。

発生している問題・エラーメッセージ

circleci上でbundle exec rake db:createした時にMysql2::Error::ConnectionError: が発生する

# circleci #!/bin/bash -eo pipefail bundle exec rake db:create Access denied for user 'root'@'127.0.0.1' (using password: YES) Couldn't create 'myapp_test' database. Please check your configuration. rake aborted! Mysql2::Error::ConnectionError: Access denied for user 'root'@'127.0.0.1' (using password: YES) /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/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/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/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/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/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/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/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/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/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/lib/active_record/connection_handling.rb:118:in `retrieve_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4/lib/active_record/connection_handling.rb:90:in `connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.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/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/lib/active_record/tasks/database_tasks.rb:119:in `create' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.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/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/lib/active_record/tasks/database_tasks.rb:313:in `each' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.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/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/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/bin/bundle:30:in `block in <main>' /usr/local/bin/bundle:22:in `<main>' Tasks: TOP => db:create (See full trace by running task with --trace) Exited with code exit status 1

該当のソースコード

#dockerfile FROM ruby:2.5.7 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp
#docker-compose.yml version: '3' services: db: image: mysql:5.7 ports: - 4306:3306 volumes: - db-volume:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_HOST=127.0.0.1 web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/myapp - .:/rspec_sample ports: - "3000:3000" depends_on: - db tty: true stdin_open: true volumes: db-volume:
#datebase.yml default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: password port: 3306 host: db socket: /var/lib/mysql/mysql.sock development: <<: *default database: myapp_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: myapp_test username: <%= ENV['DB_USERNAME'] || 'root' %> password: <%= ENV['DB_PASSWORD'] || 'password' %> host: <%= ENV['DB_HOST'] || 'db' %>
#.circleci/config.yml version: 2 orbs: codecov: codecov/codecov@1.0.5 jobs: build: docker: # specify the version you desire here - image: circleci/ruby:2.5.7-node-browsers environment: RAILS_ENV: test DB_HOST: '127.0.0.1' DB_USERNAME: root DB_PASSWORD: password # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images # documented at https://circleci.com/docs/2.0/circleci-images/ - image: circleci/mysql:5.7 environment: RAILS_ENV: test DB_HOST: 127.0.0.1 DB_USERNAME: root DB_PASSWORD: password working_directory: ~/repo steps: - checkout # Download and cache dependencies - restore_cache: keys: - v1-dependencies-{{ checksum "Gemfile.lock" }} # fallback to using the latest cache if no exact match is found - v1-dependencies- - run: name: install dependencies command: | bundle install --jobs=4 --retry=3 --path vendor/bundle - save_cache: paths: - ./vendor/bundle key: v1-dependencies-{{ checksum "Gemfile.lock" }} - run: name: Wait for DB command: dockerize -wait tcp://127.0.0.1:3306 -timeout 120s # Database setup - run: bundle exec rake db:create - run: bundle exec rake db:schema:load # run tests! - 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 \ --format RspecJunitFormatter \ --out /tmp/test-results/rspec.xml \ --format progress \ $TEST_FILES # collect reports - store_test_results: path: /tmp/test-results - store_artifacts: path: /tmp/test-results destination: test-results # run rubocop - run: name: run rubocop command: bundle exec rubocop

試したこと

環境変数をいじったり、ソケットやホストの見直しを行ったが上記のエラーが消えなかった

具体的に何でエラーが発生しているのか解らない状況なので質問させてください

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問