質問編集履歴

3

docker-compose logsの追記

2020/03/15 08:33

投稿

Pichan.
Pichan.

スコア4

test CHANGED
File without changes
test CHANGED
@@ -310,29 +310,93 @@
310
310
 
311
311
 
312
312
 
313
- 例)[試した記事](https://qiita.com/t-izaki/items/c6ef3239176f9c6697f2)この記事などの
314
-
315
- config.ymlにあるcircleciのrubyとmysqlのimageでのやり方なども試しましたが同じエラーがおこります。
316
-
317
313
  ローカル環境ではdocker-compose dowon させてからbuildしてdb:create migrate問題なくできます。
318
314
 
319
- config.ymlでのsleep後にdocker-compose psコマンドを入れてコンテナの状態なども確認しましたが全てのコンテナ立ち上がっていました
320
-
321
- ```
322
-
323
- docker-compose ps
324
-
325
- Name Command State Ports
326
-
327
- ---------------------------------------------------------------------------------------------
328
-
329
- project_chrome_1 /opt/bin/entry_point.sh Up 0.0.0.0:4444->4444/tcp
330
-
331
- project_db_1 docker-entrypoint.sh mysql ... Up 0.0.0.0:3306->3306/tcp, 33060/tcp
332
-
333
- project_nginx_1 /bin/sh -c /usr/sbin/nginx ... Up 0.0.0.0:80->80/tcp
334
-
335
- project_web_1 bundle exec puma -C /app/c ... Up 0.0.0.0:3000->3000/tcp
315
+ config.ymlでのsleep後にdocker-compose logsコマンドを入れてコンテナの状態です
316
+
317
+ RAILS_MASTER_KEYを渡せずwebサーバーでundefined method `[]' for nil:NilClassが出ています。
318
+
319
+ devise.rbではomniauthの環境変数をcredentialsで渡している為です。
320
+
321
+ ```
322
+
323
+ #!/bin/bash -eo pipefail
324
+
325
+ docker-compose logs
326
+
327
+ Attaching to project_nginx_1, project_web_1, project_chrome_1, project_db_1
328
+
329
+ web_1 | Puma starting in single mode...
330
+
331
+ web_1 | * Version 3.12.4 (ruby 2.5.1-p57), codename: Llamas in Pajamas
332
+
333
+ web_1 | * Min threads: 5, max threads: 5
334
+
335
+ web_1 | * Environment: development
336
+
337
+ web_1 | ! Unable to load application: NoMethodError: undefined method `[]' for nil:NilClass
338
+
339
+ web_1 | bundler: failed to load command: puma (/usr/local/bundle/bin/puma)
340
+
341
+
342
+
343
+ db_1 | 2020-03-15 08:15:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started.
344
+
345
+ web_1 | NoMethodError: undefined method `[]' for nil:NilClass
346
+
347
+
348
+
349
+ web_1 | /app/config/initializers/devise.rb:305:in `block in <top (required)>'
350
+
351
+
352
+
353
+ db_1 | 2020-03-15 08:15:59+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
354
+
355
+ db_1 | 2020-03-15 08:15:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.29-1debian10 started.
356
+
357
+ db_1 | 2020-03-15 08:15:59+00:00 [Note] [Entrypoint]: Initializing database files
358
+
359
+ 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).
360
+
361
+ web_1 | /usr/local/bundle/gems/devise-4.7.1/lib/devise.rb:311:in `setup'
362
+
363
+
364
+
365
+ db_1 | 2020-03-15T08:16:00.208657Z 0 [Warning] InnoDB: New log files created, LSN=45790
366
+
367
+ web_1 | /app/config/initializers/devise.rb:5:in `<top (required)>'
368
+
369
+
370
+
371
+ db_1 | 2020-03-15T08:16:00.277089Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
372
+
373
+ web_1 | /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
374
+
375
+
376
+
377
+ 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.
378
+
379
+ web_1 | /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `block in load'
380
+
381
+
382
+
383
+ 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.
384
+
385
+ web_1 | /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
386
+
387
+
388
+
389
+ db_1 | 2020-03-15T08:16:03.233002Z 0 [Warning] CA certificate ca.pem is self signed.
390
+
391
+ web_1 | /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
392
+
393
+
394
+
395
+ 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.
396
+
397
+
398
+
399
+
336
400
 
337
401
  ```
338
402
 

2

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

2020/03/15 08:33

投稿

Pichan.
Pichan.

スコア4

test CHANGED
File without changes
test CHANGED
@@ -176,9 +176,9 @@
176
176
 
177
177
  - "3000:3000"
178
178
 
179
- # links:
179
+ links:
180
-
180
+
181
- # - db
181
+ - db
182
182
 
183
183
  depends_on:
184
184
 
@@ -232,7 +232,7 @@
232
232
 
233
233
  port: 3306
234
234
 
235
- host: '127.0.0.1'
235
+ host: 'db'
236
236
 
237
237
  database: ci_test
238
238
 

1

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

2020/03/15 02:25

投稿

Pichan.
Pichan.

スコア4

test CHANGED
File without changes
test CHANGED
@@ -4,9 +4,7 @@
4
4
 
5
5
  circleciでデーターベースのセットアップ事に
6
6
 
7
- rails aborted!b_1 ... done
8
-
9
- NoMethodError: undefined method `[]' for nil:NilClass
7
+ Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
10
8
 
11
9
  と、エラーになりデーターベースが作成できません。
12
10
 
@@ -24,71 +22,71 @@
24
22
 
25
23
 
26
24
 
25
+ ```
26
+
27
- ```#!/bin/bash -eo pipefail
27
+ #!/bin/bash -eo pipefail
28
-
28
+
29
- docker-compose run web bin/rails db:create db:migrate RAILS_ENV=test
29
+ docker-compose run web bin/rails db:create db:migrate RAILS_ENV=test RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
30
+
31
+ Starting project_db_1 ...
32
+
33
+
30
34
 
31
35
  Starting project_chrome_1 ...
32
36
 
33
- Starting project_db_1 ...
34
-
35
- rails aborted!b_1 ... done
36
-
37
- NoMethodError: undefined method `[]' for nil:NilClass
38
-
39
- /app/config/initializers/devise.rb:305:in `block in <top (required)>'
40
-
41
- /usr/local/bundle/gems/devise-4.7.1/lib/devise.rb:311:in `setup'
42
-
43
- /app/config/initializers/devise.rb:5:in `<top (required)>'
44
-
45
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
46
-
47
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `block in load'
48
-
49
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
50
-
51
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
52
-
53
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:663:in `block in load_config_initializer'
54
-
55
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:170:in `instrument'
56
-
57
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:662:in `load_config_initializer'
58
-
59
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:620:in `block (2 levels) in <class:Engine>'
60
-
61
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:619:in `each'
62
-
63
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/engine.rb:619:in `block in <class:Engine>'
64
-
65
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:32:in `instance_exec'
66
-
67
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:32:in `run'
68
-
69
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:61:in `block in run_initializers'
70
-
71
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:50:in `each'
72
-
73
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:50:in `tsort_each_child'
74
-
75
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:60:in `run_initializers'
76
-
77
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:361:in `initialize!'
78
-
79
- /app/config/environment.rb:5:in `<top (required)>'
80
-
81
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require'
82
-
83
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require'
84
-
85
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
86
-
87
- /usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require'
88
-
89
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:337:in `require_environment!'
90
-
91
- /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:520:in `block in run_tasks_blocks'
37
+
38
+
39
+ Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
40
+
41
+ Couldn't create 'ci_test' database. Please check your configuration.
42
+
43
+ rails aborted!
44
+
45
+ Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
46
+
47
+ /usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:89:in `connect'
48
+
49
+ /usr/local/bundle/gems/mysql2-0.4.10/lib/mysql2/client.rb:89:in `initialize'
50
+
51
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `new'
52
+
53
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `mysql2_connection'
54
+
55
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection'
56
+
57
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
58
+
59
+ /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'
60
+
61
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
62
+
63
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout'
64
+
65
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
66
+
67
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
68
+
69
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
70
+
71
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:90:in `connection'
72
+
73
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/mysql_database_tasks.rb:6:in `connection'
74
+
75
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/mysql_database_tasks.rb:14:in `create'
76
+
77
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:119:in `create'
78
+
79
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
80
+
81
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
82
+
83
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:313:in `each'
84
+
85
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
86
+
87
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
88
+
89
+ /usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <top (required)>'
92
90
 
93
91
  /usr/local/bundle/gems/railties-5.2.4.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
94
92
 
@@ -122,7 +120,7 @@
122
120
 
123
121
  bin/rails:3:in `<main>'
124
122
 
125
- Tasks: TOP => db:create => db:load_config => environment
123
+ Tasks: TOP => db:create
126
124
 
127
125
  (See full trace by running task with --trace)
128
126
 
@@ -130,7 +128,7 @@
130
128
 
131
129
  Exited with code exit status 1
132
130
 
133
- CircleCI received exit code 1
131
+
134
132
 
135
133
  ```
136
134
 
@@ -228,15 +226,15 @@
228
226
 
229
227
  encoding: utf8mb4
230
228
 
231
- host: db
232
-
233
- username: root
234
-
235
- password:
236
-
237
229
  pool: 5
238
230
 
231
+ username: 'root'
232
+
233
+ port: 3306
234
+
235
+ host: '127.0.0.1'
236
+
239
- database: app_test
237
+ database: ci_test
240
238
 
241
239
  ```
242
240
 
@@ -290,7 +288,7 @@
290
288
 
291
289
  name: dbsetup
292
290
 
293
- command: docker-compose run web bin/rails db:create db:migrate RAILS_ENV=test
291
+ command: docker-compose run web bin/rails db:create db:migrate RAILS_ENV=test RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
294
292
 
295
293
  - run:
296
294
 
@@ -340,8 +338,6 @@
340
338
 
341
339
 
342
340
 
343
-
344
-
345
341
  ### 補足情報(FW/ツールのバージョンなど)
346
342
 
347
343