circleCIのjob(bundle exec rake db:create)で発生しているエラーを解消したいのですが、色々とやってみたものの、解決できませんでしたのでどなたかアドバイスをいただきたいです。
<参考にした記事>
・https://teratail.com/questions/227081
・https://qiita.com/t-izaki/items/c6ef3239176f9c6697f2 など
解決したい内容
circle CIのbundle exec rake db:createのjobで発生する以下のエラーを解消したい
Unknown MySQL server host 'db' (-2) Couldn't create 'app_name_development' database. Please check your configuration.
環境
mac os
rails 2.5.3
docker
mysql:5.7
エラー詳細
circle CIのjob
①bundle exec rake db:create
#!/bin/bash -eo pipefail bundle exec rake db:create Unknown MySQL server host 'db' (-2) Couldn't create 'app_name_development' 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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/lib/active_record/connection_handling.rb:118:in `retrieve_connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:90:in `connection' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.1/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.1/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.1/lib/active_record/tasks/database_tasks.rb:119:in `create' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.1/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.1/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.1/lib/active_record/tasks/database_tasks.rb:313:in `each' /home/circleci/repo/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.4.1/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.1/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.1/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:23:in `load' /usr/local/bin/bundle:23:in `<main>' Tasks: TOP => db:create (See full trace by running task with --trace) Exited with code exit status 1
※エラーにはなっていないがcircle CI上の以下のjobでcancelが出ている
②Container circleci/mysql:5.7
2020-01-12 12:18:58+00:00 [Note] [Entrypoint]: Database files initialized 2020-01-12 12:18:58+00:00 [Note] [Entrypoint]: Starting temporary server 2020-01-12 12:18:58+00:00 [Note] [Entrypoint]: Waiting for server startup 2020-01-12T12:18:58.310267Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-01-12T12:18:58.312135Z 0 [Note] mysqld (mysqld 5.7.28) starting as process 164 ... 2020-01-12T12:18:58.314826Z 0 [Note] InnoDB: PUNCH HOLE support available 2020-01-12T12:18:58.314846Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2020-01-12T12:18:58.314849Z 0 [Note] InnoDB: Uses event mutexes 2020-01-12T12:18:58.314852Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 〜省略〜 2020-01-12T12:19:01.303652Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2020-01-12T12:19:01.318138Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2020-01-12T12:19:01.318732Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2020-01-12T12:19:01.318741Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2020-01-12T12:19:01.318999Z 0 [Note] InnoDB: Waiting for purge to start 2020-01-12T12:19:01.369136Z 0 [Note] InnoDB: 5.7.28 started; log sequence number 12440100 2020-01-12T12:19:01.369387Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool 2020-01-12T12:19:01.369455Z 0 [Note] Plugin 'FEDERATED' is disabled. 2020-01-12T12:19:01.372573Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200112 12:19:01 2020-01-12T12:19:01.375488Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. 2020-01-12T12:19:01.375504Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory. 2020-01-12T12:19:01.376000Z 0 [Warning] CA certificate ca.pem is self signed. 2020-01-12T12:19:01.376022Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. 2020-01-12T12:19:01.376383Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 2020-01-12T12:19:01.376410Z 0 [Note] IPv6 is available. 2020-01-12T12:19:01.376421Z 0 [Note] - '::' resolves to '::'; 2020-01-12T12:19:01.376441Z 0 [Note] Server socket created on IP: '::'. 2020-01-12T12:19:01.376716Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. 2020-01-12T12:19:01.383112Z 0 [Note] Event Scheduler: Loaded 0 events 2020-01-12T12:19:01.383298Z 0 [Note] mysqld: ready for connections. Version: '5.7.28' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL) 2020-01-12T12:19:03.790146Z 2 [Note] Got an error reading communication packets Job was canceled
関連ファイルの内容
.circleci/config.yml
version: 2 jobs: build: docker: - image: circleci/ruby:2.5.3-node-browsers environment: BUNDLE_PATH: vendor/bundle BUNDLER_VERSION: 2.0.2 BUNDLE_JOBS: 4 BUNDLE_RETRY: 3 - image: circleci/mysql:5.7 environment: RAILS_ENV: test DB_HOST: 127.0.0.1 DB_USERNAME: 'root' DB_PASSWORD: 'root' working_directory: ~/repo steps: - checkout - restore_cache: keys: - v1-dependencies-{{ checksum "Gemfile.lock" }} - v1-dependencies- - run: name: setup bundler command: | sudo gem update --system sudo gem uninstall bundler sudo rm -rf /usr/local/bin/bundle sudo rm -rf /usr/local/bin/bundler sudo gem install bundler - run: name: install dependencies command: | bundle install --jobs=4 --retry=3 --path vendor/bundle - run: name: install dependencies command: yarn - 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 - run: bundle exec rake db:create - run: bundle exec rake db:schema:load - run: name: run tests command: | DISABLE_SPRING=true bundle exec rails test
database.yml
default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: root host: db development: <<: *default database: app_name_development test: <<: *default database: app_name_test
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/12 14:28