質問するログイン新規登録

質問編集履歴

3

docker-compose logsの追記

2020/03/15 08:33

投稿

Pichan.
Pichan.

スコア4

title CHANGED
File without changes
body CHANGED
@@ -154,18 +154,50 @@
154
154
 
155
155
  ### 試したこと
156
156
 
157
- 例)[試した記事](https://qiita.com/t-izaki/items/c6ef3239176f9c6697f2)この記事などの
158
- config.ymlにあるcircleciのrubyとmysqlのimageでのやり方なども試しましたが同じエラーがおこります。
159
157
  ローカル環境ではdocker-compose dowon させてからbuildしてdb:create migrate問題なくできます。
160
- config.ymlでのsleep後にdocker-compose psコマンドを入れてコンテナの状態なども確認しましたが全てのコンテナ立ち上がっていました
158
+ config.ymlでのsleep後にdocker-compose logsコマンドを入れてコンテナの状態です
159
+ RAILS_MASTER_KEYを渡せずwebサーバーでundefined method `[]' for nil:NilClassが出ています。
160
+ devise.rbではomniauthの環境変数をcredentialsで渡している為です。
161
161
  ```
162
- docker-compose ps
163
- Name Command State Ports
164
- ---------------------------------------------------------------------------------------------
165
- project_chrome_1 /opt/bin/entry_point.sh Up 0.0.0.0:4444->4444/tcp
166
- project_db_1 docker-entrypoint.sh mysql ... Up 0.0.0.0:3306->3306/tcp, 33060/tcp
167
- project_nginx_1 /bin/sh -c /usr/sbin/nginx ... Up 0.0.0.0:80->80/tcp
168
- project_web_1 bundle exec puma -C /app/c ... Up 0.0.0.0:3000->3000/tcp
162
+ #!/bin/bash -eo pipefail
163
+ docker-compose logs
164
+ Attaching to project_nginx_1, project_web_1, project_chrome_1, project_db_1
165
+ web_1 | Puma starting in single mode...
166
+ web_1 | * Version 3.12.4 (ruby 2.5.1-p57), codename: Llamas in Pajamas
167
+ web_1 | * Min threads: 5, max threads: 5
168
+ web_1 | * Environment: development
169
+ web_1 | ! Unable to load application: NoMethodError: undefined method `[]' for nil:NilClass
170
+ web_1 | bundler: failed to load command: puma (/usr/local/bundle/bin/puma)
171
+
172
+ db_1 | 2020-03-15 08:15:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started.
173
+ web_1 | NoMethodError: undefined method `[]' for nil:NilClass
174
+
175
+ web_1 | /app/config/initializers/devise.rb:305:in `block in <top (required)>'
176
+
177
+ db_1 | 2020-03-15 08:15:59+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
178
+ db_1 | 2020-03-15 08:15:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started.
179
+ db_1 | 2020-03-15 08:15:59+00:00 [Note] [Entrypoint]: Initializing database files
180
+ db_1 | 2020-03-15T08:15:59.597544Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
181
+ web_1 | /usr/local/bundle/gems/devise-4.7.1/lib/devise.rb:311:in `setup'
182
+
183
+ db_1 | 2020-03-15T08:16:00.208657Z 0 [Warning] InnoDB: New log files created, LSN=45790
184
+ web_1 | /app/config/initializers/devise.rb:5:in `<top (required)>'
185
+
186
+ db_1 | 2020-03-15T08:16:00.277089Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
187
+ web_1 | /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
188
+
189
+ db_1 | 2020-03-15T08:16:00.339860Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3464bb45-6695-11ea-8dbb-0242ac120002.
190
+ web_1 | /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `block in load'
191
+
192
+ db_1 | 2020-03-15T08:16:00.343072Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
193
+ web_1 | /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
194
+
195
+ db_1 | 2020-03-15T08:16:03.233002Z 0 [Warning] CA certificate ca.pem is self signed.
196
+ web_1 | /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
197
+
198
+ db_1 | 2020-03-15T08:16:03.863511Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
199
+
200
+
169
201
  ```
170
202
 
171
203
  ### 補足情報(FW/ツールのバージョンなど)

2

docker-compose.ymlでのlink設定追記、dadabase.ci.ymlのhost名をdbに変更

2020/03/15 08:33

投稿

Pichan.
Pichan.

スコア4

title CHANGED
File without changes
body CHANGED
@@ -87,8 +87,8 @@
87
87
  - .:/app
88
88
  ports:
89
89
  - "3000:3000"
90
- # links:
90
+ links:
91
- # - db
91
+ - db
92
92
  depends_on:
93
93
  - db
94
94
  - chrome
@@ -115,7 +115,7 @@
115
115
  pool: 5
116
116
  username: 'root'
117
117
  port: 3306
118
- host: '127.0.0.1'
118
+ host: 'db'
119
119
  database: ci_test
120
120
  ```
121
121
  circleci/config.yml

1

現状のエラー内容、config.ymlでのRAILS_MASTER_KEYの環境変数追加、databese.ci.ymlの変更

2020/03/15 02:25

投稿

Pichan.
Pichan.

スコア4

title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,7 @@
1
1
  ### 前提・実現したいこと
2
2
  docker-compose環境にてrailsのアプリを作成しています。
3
3
  circleciでデーターベースのセットアップ事に
4
- rails aborted!b_1 ... done
5
- NoMethodError: undefined method `[]' for nil:NilClass
4
+ Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
6
5
  と、エラーになりデーターベースが作成できません。
7
6
  ネットにあるcircleciの記事のやり方や同じようなエラーの解決策をいろいろ試してみましたがどれを試してもdb:createのところで同じエラーが起こります。
8
7
 
@@ -11,39 +10,39 @@
11
10
 
12
11
  ### 発生している問題・エラーメッセージ
13
12
 
13
+ ```
14
- ```#!/bin/bash -eo pipefail
14
+ #!/bin/bash -eo pipefail
15
- docker-compose run web bin/rails db:create db:migrate RAILS_ENV=test
15
+ docker-compose run web bin/rails db:create db:migrate RAILS_ENV=test RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
16
+ Starting project_db_1 ...
17
+
16
18
  Starting project_chrome_1 ...
19
+
20
+ Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
17
- Starting project_db_1 ...
21
+ Couldn't create 'ci_test' database. Please check your configuration.
18
- rails aborted!b_1 ... done
22
+ rails aborted!
19
- NoMethodError: undefined method `[]' for nil:NilClass
20
- /app/config/initializers/devise.rb:305:in `block in <top (required)>'
23
+ Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
21
- /usr/local/bundle/gems/devise-4.7.1/lib/devise.rb:311:in `setup'
22
- /app/config/initializers/devise.rb:5:in `<top (required)>'
23
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
24
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `block in load'
25
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
26
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
27
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:663:in `block in load_config_initializer'
28
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:170:in `instrument'
29
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:662:in `load_config_initializer'
30
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
31
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:619:in `each'
24
+ /usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:89:in `connect'
32
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:619:in `block in <class:Engine>'
33
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:32:in `instance_exec'
34
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:32:in `run'
35
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:61:in `block in run_initializers'
36
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:50:in `each'
37
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:50:in `tsort_each_child'
38
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:60:in `run_initializers'
39
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:361:in `initialize!'
25
+ /usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:89:in `initialize'
26
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `new'
27
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `mysql2_connection'
28
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection'
29
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
30
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection'
31
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
32
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout'
33
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
34
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
40
- /app/config/environment.rb:5:in `<top (required)>'
35
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
41
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require'
36
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:90:in `connection'
42
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require'
37
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/mysql_database_tasks.rb:6:in `connection'
43
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
38
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/mysql_database_tasks.rb:14:in `create'
44
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require'
39
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:119:in `create'
40
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
41
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
42
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:313:in `each'
43
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
45
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:337:in `require_environment!'
44
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
46
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:520:in `block in run_tasks_blocks'
45
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <top (required)>'
47
46
  /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
48
47
  /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
49
48
  /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/command.rb:48:in `invoke'
@@ -60,11 +59,11 @@
60
59
  /app/bin/spring:15:in `<top (required)>'
61
60
  bin/rails:3:in `load'
62
61
  bin/rails:3:in `<main>'
63
- Tasks: TOP => db:create => db:load_config => environment
62
+ Tasks: TOP => db:create
64
63
  (See full trace by running task with --trace)
65
64
 
66
65
  Exited with code exit status 1
67
- CircleCI received exit code 1
66
+
68
67
  ```
69
68
 
70
69
  ### 該当のソースコード
@@ -113,11 +112,11 @@
113
112
  test:
114
113
  adapter: mysql2
115
114
  encoding: utf8mb4
116
- host: db
117
- username: root
118
- password:
119
115
  pool: 5
116
+ username: 'root'
117
+ port: 3306
118
+ host: '127.0.0.1'
120
- database: app_test
119
+ database: ci_test
121
120
  ```
122
121
  circleci/config.yml
123
122
  ```
@@ -144,7 +143,7 @@
144
143
  command: sleep 1
145
144
  - run:
146
145
  name: dbsetup
147
- command: docker-compose run web bin/rails db:create db:migrate RAILS_ENV=test
146
+ command: docker-compose run web bin/rails db:create db:migrate RAILS_ENV=test RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
148
147
  - run:
149
148
  name: RSpec test
150
149
  command: docker-compose run web bin/rspec
@@ -169,7 +168,6 @@
169
168
  project_web_1 bundle exec puma -C /app/c ... Up 0.0.0.0:3000->3000/tcp
170
169
  ```
171
170
 
172
-
173
171
  ### 補足情報(FW/ツールのバージョンなど)
174
172
 
175
173
  rails 5.2