質問編集履歴
8
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -454,6 +454,8 @@
|
|
454
454
|
|
455
455
|
```
|
456
456
|
|
457
|
+
% mysql_config --socket
|
458
|
+
|
457
459
|
/tmp/mysql.sock
|
458
460
|
|
459
461
|
```
|
@@ -462,6 +464,8 @@
|
|
462
464
|
|
463
465
|
```
|
464
466
|
|
467
|
+
% mysql_config --socket
|
468
|
+
|
465
469
|
/var/lib/mysql/mysql.sock
|
466
470
|
|
467
471
|
```
|
7
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -446,7 +446,25 @@
|
|
446
446
|
|
447
447
|
```
|
448
448
|
|
449
|
-
が、ローカルとEC2ターミナルでは違いました。
|
449
|
+
の結果が、ローカルとEC2ターミナルでは違いました。
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
ローカル
|
454
|
+
|
455
|
+
```
|
456
|
+
|
457
|
+
/tmp/mysql.sock
|
458
|
+
|
459
|
+
```
|
460
|
+
|
461
|
+
EC2
|
462
|
+
|
463
|
+
```
|
464
|
+
|
465
|
+
/var/lib/mysql/mysql.sock
|
466
|
+
|
467
|
+
```
|
450
468
|
|
451
469
|
そこで、database.ymlをこの様に変更しましたが、エラーは変わりませんでした。
|
452
470
|
|
@@ -567,3 +585,25 @@
|
|
567
585
|
socket: /var/lib/mysql/mysql.sock
|
568
586
|
|
569
587
|
```
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
```
|
592
|
+
|
593
|
+
ps ax | grep mysqld
|
594
|
+
|
595
|
+
```
|
596
|
+
|
597
|
+
の結果です。
|
598
|
+
|
599
|
+
```
|
600
|
+
|
601
|
+
9762 ? Ssl 0:01 mysqld
|
602
|
+
|
603
|
+
13734 pts/1 S+ 0:00 grep --color=auto mysqld
|
604
|
+
|
605
|
+
21504 ? S 0:00 /bin/sh /usr/libexec/mysql56/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
|
606
|
+
|
607
|
+
21718 ? Sl 0:14 /usr/libexec/mysql56/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql56/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
|
608
|
+
|
609
|
+
```
|
6
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -431,3 +431,139 @@
|
|
431
431
|
bundle exec cap production deploy unicorn:restart
|
432
432
|
|
433
433
|
```
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
追記です。
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
```
|
444
|
+
|
445
|
+
mysql_config --socket
|
446
|
+
|
447
|
+
```
|
448
|
+
|
449
|
+
が、ローカルとEC2ターミナルでは違いました。
|
450
|
+
|
451
|
+
そこで、database.ymlをこの様に変更しましたが、エラーは変わりませんでした。
|
452
|
+
|
453
|
+
```
|
454
|
+
|
455
|
+
# MySQL. Versions 5.1.10 and up are supported.
|
456
|
+
|
457
|
+
#
|
458
|
+
|
459
|
+
# Install the MySQL driver
|
460
|
+
|
461
|
+
# gem install mysql2
|
462
|
+
|
463
|
+
#
|
464
|
+
|
465
|
+
# Ensure the MySQL gem is defined in your Gemfile
|
466
|
+
|
467
|
+
# gem 'mysql2'
|
468
|
+
|
469
|
+
#
|
470
|
+
|
471
|
+
# And be sure to use new-style password hashing:
|
472
|
+
|
473
|
+
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
|
474
|
+
|
475
|
+
#
|
476
|
+
|
477
|
+
default: &default
|
478
|
+
|
479
|
+
adapter: mysql2
|
480
|
+
|
481
|
+
encoding: utf8
|
482
|
+
|
483
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
484
|
+
|
485
|
+
username: root
|
486
|
+
|
487
|
+
password: password
|
488
|
+
|
489
|
+
host: db
|
490
|
+
|
491
|
+
socket: /tmp/mysql.sock
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
development:
|
496
|
+
|
497
|
+
<<: *default
|
498
|
+
|
499
|
+
database: LuggageMGT_development
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
# Warning: The database defined as "test" will be erased and
|
504
|
+
|
505
|
+
# re-generated from your development database when you run "rake".
|
506
|
+
|
507
|
+
# Do not set this db to the same as development or production.
|
508
|
+
|
509
|
+
test:
|
510
|
+
|
511
|
+
<<: *default
|
512
|
+
|
513
|
+
database: LuggageMGT_test
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
# As with config/secrets.yml, you never want to store sensitive information,
|
518
|
+
|
519
|
+
# like your database password, in your source code. If your source code is
|
520
|
+
|
521
|
+
# ever seen by anyone, they now have access to your database.
|
522
|
+
|
523
|
+
#
|
524
|
+
|
525
|
+
# Instead, provide the password as a unix environment variable when you boot
|
526
|
+
|
527
|
+
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
528
|
+
|
529
|
+
# for a full rundown on how to provide these environment variables in a
|
530
|
+
|
531
|
+
# production deployment.
|
532
|
+
|
533
|
+
#
|
534
|
+
|
535
|
+
# On Heroku and other platform providers, you may have a full connection URL
|
536
|
+
|
537
|
+
# available as an environment variable. For example:
|
538
|
+
|
539
|
+
#
|
540
|
+
|
541
|
+
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
|
542
|
+
|
543
|
+
#
|
544
|
+
|
545
|
+
# You can use this database configuration with:
|
546
|
+
|
547
|
+
#
|
548
|
+
|
549
|
+
# production:
|
550
|
+
|
551
|
+
# url: <%= ENV['DATABASE_URL'] %>
|
552
|
+
|
553
|
+
#
|
554
|
+
|
555
|
+
production:
|
556
|
+
|
557
|
+
<<: *default
|
558
|
+
|
559
|
+
host: <%= ENV['DB_HOST'] %>
|
560
|
+
|
561
|
+
database: <%= ENV['DB_DATABASE'] %>
|
562
|
+
|
563
|
+
username: <%= ENV['DB_USERNAME'] %>
|
564
|
+
|
565
|
+
password: <%= ENV['DB_PASSWORD'] %>
|
566
|
+
|
567
|
+
socket: /var/lib/mysql/mysql.sock
|
568
|
+
|
569
|
+
```
|
5
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -98,6 +98,22 @@
|
|
98
98
|
|
99
99
|
|
100
100
|
|
101
|
+
host部分をdbにしたり、
|
102
|
+
|
103
|
+
compose.ymlのdbに
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
volumes:
|
108
|
+
|
109
|
+
- ./tmp/db:/var/lib/mysql/data
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
を追記してもエラーでした。
|
114
|
+
|
115
|
+
|
116
|
+
|
101
117
|
現状のエラーですが、
|
102
118
|
|
103
119
|
```
|
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -144,7 +144,7 @@
|
|
144
144
|
|
145
145
|
password: password
|
146
146
|
|
147
|
-
host:
|
147
|
+
host: localhost
|
148
148
|
|
149
149
|
socket: /tmp/mysql.sock
|
150
150
|
|
@@ -162,7 +162,7 @@
|
|
162
162
|
|
163
163
|
<<: *default
|
164
164
|
|
165
|
-
host:
|
165
|
+
host: localhost
|
166
166
|
|
167
167
|
database: LuggageMGT_test
|
168
168
|
|
@@ -180,6 +180,8 @@
|
|
180
180
|
|
181
181
|
password: <%= ENV['DATABASE_PASSWORD'] %>
|
182
182
|
|
183
|
+
socket: /var/lib/mysql/mysql.sock
|
184
|
+
|
183
185
|
```
|
184
186
|
|
185
187
|
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,17 +16,33 @@
|
|
16
16
|
|
17
17
|
```
|
18
18
|
|
19
|
-
Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/
|
19
|
+
Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")
|
20
|
-
|
20
|
+
|
21
|
-
```
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
|
22
|
-
|
25
|
+
#行ったこと
|
26
|
+
|
27
|
+
|
28
|
+
|
23
|
-
|
29
|
+
mysqlが起動していないと仮説を立て、
|
30
|
+
|
24
|
-
|
31
|
+
```
|
32
|
+
|
25
|
-
|
33
|
+
sudo service mysqld start
|
34
|
+
|
26
|
-
|
35
|
+
Starting mysqld: [ OK ]
|
36
|
+
|
27
|
-
|
37
|
+
```
|
38
|
+
|
28
|
-
|
39
|
+
となったが、エラーは変わりませんでした。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
29
|
-
|
45
|
+
mysql.sockの場所が曖昧でしたので、
|
30
46
|
|
31
47
|
```
|
32
48
|
|
@@ -42,7 +58,47 @@
|
|
42
58
|
|
43
59
|
```
|
44
60
|
|
45
|
-
と返ってきたのであわせてdatabaseを変更しましたが、エラーは変わらなかったです。
|
61
|
+
と返ってきたのであわせて下記の様にdatabaseを変更しましたが、エラーは変わらなかったです。
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
default: &default
|
66
|
+
|
67
|
+
adapter: mysql2
|
68
|
+
|
69
|
+
encoding: utf8
|
70
|
+
|
71
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
72
|
+
|
73
|
+
username: root
|
74
|
+
|
75
|
+
password: password
|
76
|
+
|
77
|
+
host: db
|
78
|
+
|
79
|
+
socket: /tmp/mysql.sock
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
次に、エラーログを確認したところ、
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
Unknown MySQL server host 'db' (25) (Mysql2::Error::ConnectionError)
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
という風になっており、dbに接続できていないことを確認できました。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
現状のエラーですが、
|
46
102
|
|
47
103
|
```
|
48
104
|
|
@@ -52,12 +108,18 @@
|
|
52
108
|
|
53
109
|
は通過するのですが、
|
54
110
|
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
55
|
-
``
|
115
|
+
```
|
56
116
|
|
57
117
|
docker-compose run web rails db:migrate RAILS_ENV=production
|
58
118
|
|
59
119
|
```
|
60
120
|
|
121
|
+
|
122
|
+
|
61
123
|
だけ通りません。
|
62
124
|
|
63
125
|
|
@@ -148,34 +210,28 @@
|
|
148
210
|
|
149
211
|
command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
|
150
212
|
|
213
|
+
volumes:
|
214
|
+
|
215
|
+
- .:/app_name
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
db:
|
220
|
+
|
221
|
+
image: mysql:5.6
|
222
|
+
|
151
223
|
environment:
|
152
224
|
|
225
|
+
MYSQL_ROOT_PASSWORD: password
|
226
|
+
|
153
|
-
|
227
|
+
MYSQL_DATABASE: root
|
228
|
+
|
154
|
-
|
229
|
+
ports:
|
230
|
+
|
155
|
-
|
231
|
+
- "4306:3306"
|
156
232
|
|
157
233
|
volumes:
|
158
234
|
|
159
|
-
- .:/app_name
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
db:
|
164
|
-
|
165
|
-
image: mysql:5.6
|
166
|
-
|
167
|
-
environment:
|
168
|
-
|
169
|
-
MYSQL_ROOT_PASSWORD: password
|
170
|
-
|
171
|
-
MYSQL_DATABASE: root
|
172
|
-
|
173
|
-
ports:
|
174
|
-
|
175
|
-
- "4306:3306"
|
176
|
-
|
177
|
-
volumes:
|
178
|
-
|
179
235
|
- ./tmp/db:/var/lib/mysql/data
|
180
236
|
|
181
237
|
volumes:
|
@@ -185,3 +241,175 @@
|
|
185
241
|
mysql_data:
|
186
242
|
|
187
243
|
```
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
dockerfile
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
FROM ruby:2.5.3
|
252
|
+
|
253
|
+
RUN apt-get update -qq && \
|
254
|
+
|
255
|
+
apt-get install -y build-essential \
|
256
|
+
|
257
|
+
libpq-dev \
|
258
|
+
|
259
|
+
nodejs
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
RUN mkdir /app_name
|
264
|
+
|
265
|
+
ENV APP_ROOT /app_name
|
266
|
+
|
267
|
+
WORKDIR $APP_ROOT
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
ADD ./Gemfile $APP_ROOT/Gemfile
|
272
|
+
|
273
|
+
ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
RUN bundle install
|
278
|
+
|
279
|
+
ADD . $APP_ROOT
|
280
|
+
|
281
|
+
```
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
(関係ないかもですが、)
|
286
|
+
|
287
|
+
circleci/config.yml
|
288
|
+
|
289
|
+
```
|
290
|
+
|
291
|
+
version: 2
|
292
|
+
|
293
|
+
jobs:
|
294
|
+
|
295
|
+
build:
|
296
|
+
|
297
|
+
docker:
|
298
|
+
|
299
|
+
- image: circleci/ruby:2.5.3-node-browsers
|
300
|
+
|
301
|
+
environment:
|
302
|
+
|
303
|
+
RAILS_ENV: 'test'
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
- image: circleci/mysql:5.6
|
308
|
+
|
309
|
+
environment:
|
310
|
+
|
311
|
+
MYSQL_ROOT_PASSWORD: "password"
|
312
|
+
|
313
|
+
MYSQL_ROOT_HOST: "%"
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
working_directory: ~/app_name
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
steps:
|
322
|
+
|
323
|
+
- checkout
|
324
|
+
|
325
|
+
- restore_cache: # キャッシュを読み込む
|
326
|
+
|
327
|
+
keys:
|
328
|
+
|
329
|
+
- gem-cache-v1-{{ checksum "Gemfile.lock" }}
|
330
|
+
|
331
|
+
- gem-cache-v1-
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
- run:
|
336
|
+
|
337
|
+
name: Bundle Install
|
338
|
+
|
339
|
+
command: bundle check --path vendor/bundle || bundle install --deployment
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
- save_cache: # キャッシュを保存する
|
344
|
+
|
345
|
+
key: gem-cache-v1-{{ checksum "Gemfile.lock" }}
|
346
|
+
|
347
|
+
paths:
|
348
|
+
|
349
|
+
- vendor/bundle
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
- run:
|
354
|
+
|
355
|
+
name: Wait for DB
|
356
|
+
|
357
|
+
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 120s
|
358
|
+
|
359
|
+
- run: bundle exec rake db:create
|
360
|
+
|
361
|
+
- run: bundle exec rake db:schema:load
|
362
|
+
|
363
|
+
- run:
|
364
|
+
|
365
|
+
name: run tests
|
366
|
+
|
367
|
+
command: |
|
368
|
+
|
369
|
+
mkdir /tmp/test-results
|
370
|
+
|
371
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
372
|
+
|
373
|
+
bundle exec rspec --format progress \
|
374
|
+
|
375
|
+
--out /tmp/test-results/rspec.xml \
|
376
|
+
|
377
|
+
--format progress \
|
378
|
+
|
379
|
+
$TEST_FILES
|
380
|
+
|
381
|
+
- store_test_results:
|
382
|
+
|
383
|
+
path: /tmp/test-results
|
384
|
+
|
385
|
+
- store_artifacts:
|
386
|
+
|
387
|
+
path: /tmp/test-results
|
388
|
+
|
389
|
+
destination: test-results
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
- add_ssh_keys:
|
394
|
+
|
395
|
+
fingerprints:
|
396
|
+
|
397
|
+
- "1f:d5:4b:1c:ed:c1:92:6e:47:a1:e0:18:a0:ff:27:ca"
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
- deploy:
|
402
|
+
|
403
|
+
name: Capistrano deploy
|
404
|
+
|
405
|
+
command: |
|
406
|
+
|
407
|
+
if [ "${CIRCLE_BRANCH}" != "master" ]; then
|
408
|
+
|
409
|
+
exit 0
|
410
|
+
|
411
|
+
fi
|
412
|
+
|
413
|
+
bundle exec cap production deploy unicorn:restart
|
414
|
+
|
415
|
+
```
|
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,29 +4,23 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
```
|
8
|
+
|
9
|
+
docker-compose run web rails db:migrate RAILS_ENV=production
|
10
|
+
|
11
|
+
```
|
12
|
+
|
7
|
-
|
13
|
+
と入力したら、次の様なエラーが出てしまいました。
|
8
14
|
|
9
15
|
|
10
16
|
|
11
17
|
```
|
12
18
|
|
13
|
-
Can't connect to local MySQL server through socket '/
|
19
|
+
Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
|
14
|
-
|
15
|
-
Couldn't create 'LuggageMGT_development' database. Please check your configuration.
|
16
|
-
|
17
|
-
rails aborted!
|
18
20
|
|
19
21
|
```
|
20
22
|
|
21
23
|
|
22
|
-
|
23
|
-
本番環境では、下記のエラーです。
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
Mysql2::Error::ConnectionError: Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
|
28
|
-
|
29
|
-
```
|
30
24
|
|
31
25
|
|
32
26
|
|
@@ -50,11 +44,21 @@
|
|
50
44
|
|
51
45
|
と返ってきたのであわせてdatabaseを変更しましたが、エラーは変わらなかったです。
|
52
46
|
|
53
|
-
|
47
|
+
```
|
54
48
|
|
55
|
-
|
49
|
+
docker-compose run web rails db:create RAILS_ENV=production
|
56
50
|
|
51
|
+
```
|
57
52
|
|
53
|
+
は通過するのですが、
|
54
|
+
|
55
|
+
``
|
56
|
+
|
57
|
+
docker-compose run web rails db:migrate RAILS_ENV=production
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
だけ通りません。
|
58
62
|
|
59
63
|
|
60
64
|
|
@@ -78,11 +82,11 @@
|
|
78
82
|
|
79
83
|
password: password
|
80
84
|
|
81
|
-
host:
|
85
|
+
host: db
|
82
86
|
|
83
87
|
socket: /tmp/mysql.sock
|
84
88
|
|
85
|
-
|
89
|
+
|
86
90
|
|
87
91
|
development:
|
88
92
|
|
@@ -96,7 +100,7 @@
|
|
96
100
|
|
97
101
|
<<: *default
|
98
102
|
|
99
|
-
host:
|
103
|
+
host: db
|
100
104
|
|
101
105
|
database: LuggageMGT_test
|
102
106
|
|
@@ -113,8 +117,6 @@
|
|
113
117
|
username: root
|
114
118
|
|
115
119
|
password: <%= ENV['DATABASE_PASSWORD'] %>
|
116
|
-
|
117
|
-
socket: /tmp/mysql.sock
|
118
120
|
|
119
121
|
```
|
120
122
|
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
初めはできていたのですが、色々といじっていたら、ローカル
|
7
|
+
初めはできていたのですが、色々といじっていたら、ローカルで次の様なエラーが出てしまいました。
|
8
8
|
|
9
9
|
|
10
10
|
|
@@ -17,6 +17,18 @@
|
|
17
17
|
rails aborted!
|
18
18
|
|
19
19
|
```
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
本番環境では、下記のエラーです。
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
Mysql2::Error::ConnectionError: Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
|
20
32
|
|
21
33
|
|
22
34
|
|
@@ -39,6 +51,10 @@
|
|
39
51
|
と返ってきたのであわせてdatabaseを変更しましたが、エラーは変わらなかったです。
|
40
52
|
|
41
53
|
初学者ですが、丸々2日環境構築で苦戦してしまっています。
|
54
|
+
|
55
|
+
サイトで該当することは色々と試してみたのですが、結局元に戻ってきてしまいました...。
|
56
|
+
|
57
|
+
|
42
58
|
|
43
59
|
|
44
60
|
|