質問編集履歴
3
試したことを追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
circleciにでheroku_deploy時に環境変数が読まれない。
|
1
|
+
circleciにでheroku_deploy時に環境変数が読まれない。['RAILS_MASTER_KEY']
|
test
CHANGED
@@ -18,9 +18,21 @@
|
|
18
18
|
|
19
19
|
---
|
20
20
|
|
21
|
-
circleciを使用しherokuへデプロイをする際、「
|
21
|
+
circleciを使用しherokuへデプロイをする際、「復号するためのキーが見つからない」とエラー文が出てきます
|
22
|
-
|
22
|
+
|
23
|
-
![
|
23
|
+
![イメージ説明](b4f8db54d31d379ec4d21367d2e710fd.png)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
エラー文抜粋:
|
28
|
+
|
29
|
+
Running: rake assets:precompile
|
30
|
+
|
31
|
+
Missing encryption key to decrypt file with.
|
32
|
+
|
33
|
+
Ask your team for your master key and write it to //config/master.key or put it in the ENV['RAILS_MASTER_KEY'].
|
34
|
+
|
35
|
+
|
24
36
|
|
25
37
|
該当のソースコード
|
26
38
|
|
@@ -28,172 +40,66 @@
|
|
28
40
|
|
29
41
|
```ここに言語を入力
|
30
42
|
|
43
|
+
/.circleci
|
44
|
+
|
31
|
-
|
45
|
+
heroku_deploy:
|
32
|
-
|
33
|
-
jobs:
|
34
|
-
|
35
|
-
rspec:
|
36
46
|
|
37
47
|
working_directory: ~/bookreco
|
38
48
|
|
39
49
|
docker:
|
40
50
|
|
41
|
-
- image:
|
51
|
+
- image: sue445/heroku-cli
|
42
52
|
|
43
53
|
steps:
|
44
54
|
|
45
55
|
- checkout
|
46
56
|
|
47
|
-
-
|
48
|
-
|
49
|
-
-
|
50
|
-
|
51
|
-
|
57
|
+
- build-tools/install-ci-tools
|
58
|
+
|
59
|
+
- jq/install
|
60
|
+
|
61
|
+
- run:
|
62
|
+
|
63
|
+
name: Identify who I am
|
64
|
+
|
65
|
+
command: echo 'export MY_EMAIL=`heroku auth:whoami | tail -n 1`' >> $BASH_ENV
|
66
|
+
|
67
|
+
- run:
|
68
|
+
|
69
|
+
name: Identify Heroku app names to destroy
|
70
|
+
|
71
|
+
command: echo 'export APP_NAMES_TO_REMOVE=`heroku apps --json | jq -r "map(select(.owner.email == "\"$MY_EMAIL\"" and (.name | contains(\"bookreco\")))) | sort_by(.updated_at) | reverse | .[5:] | .[].name"`' >> $BASH_ENV
|
72
|
+
|
73
|
+
- run:
|
74
|
+
|
75
|
+
name: Delete old apps if needed
|
76
|
+
|
77
|
+
command: for app_name in $APP_NAMES_TO_REMOVE; do heroku apps:destroy -a $app_name -c $app_name; done
|
78
|
+
|
79
|
+
- run:
|
80
|
+
|
81
|
+
name: Define Heroku app name to create
|
82
|
+
|
83
|
+
command: timestamp=`date +%Y%m%d%H%M%S` && echo "export HEROKU_APP_NAME=bookreco-$timestamp" >> $BASH_ENV
|
84
|
+
|
85
|
+
- run:
|
86
|
+
|
87
|
+
name: Create fresh Heroku app
|
88
|
+
|
89
|
+
command: heroku apps:create $HEROKU_APP_NAME --addons=jawsdb:kitefin
|
90
|
+
|
91
|
+
- run:
|
92
|
+
|
93
|
+
name: Deploy
|
94
|
+
|
95
|
+
command: git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git master
|
96
|
+
|
97
|
+
- run:
|
98
|
+
|
99
|
+
name: Run post-deploy tasks
|
52
100
|
|
53
101
|
command: |
|
54
102
|
|
55
|
-
echo "export COMPOSE_FILE=docker-compose.ci.yml" >> $BASH_ENV
|
56
|
-
|
57
|
-
- run:
|
58
|
-
|
59
|
-
name: Start containers and verify it is working
|
60
|
-
|
61
|
-
command: |
|
62
|
-
|
63
|
-
set -x
|
64
|
-
|
65
|
-
docker-compose up -d
|
66
|
-
|
67
|
-
docker exec bookreco curl -4 --retry 10 --retry-delay 3 --retry-connrefused http://localhost:3000
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
- run:
|
72
|
-
|
73
|
-
name: Setup database
|
74
|
-
|
75
|
-
command: |
|
76
|
-
|
77
|
-
docker-compose exec bookreco rails db:create
|
78
|
-
|
79
|
-
docker-compose exec bookreco rails db:migrate
|
80
|
-
|
81
|
-
docker-compose exec bookreco bundle exec rake db:migrate RAILS_ENV=test
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
- run:
|
86
|
-
|
87
|
-
name: Run rspec
|
88
|
-
|
89
|
-
command: docker-compose exec bookreco rspec
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
rubocop:
|
94
|
-
|
95
|
-
working_directory: ~/bookreco
|
96
|
-
|
97
|
-
docker:
|
98
|
-
|
99
|
-
- image: circleci/ruby:2.5.1
|
100
|
-
|
101
|
-
steps:
|
102
|
-
|
103
|
-
- checkout
|
104
|
-
|
105
|
-
- restore_cache:
|
106
|
-
|
107
|
-
keys:
|
108
|
-
|
109
|
-
- gemfiles-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
|
110
|
-
|
111
|
-
- gemfiles-{{ .Branch }}-
|
112
|
-
|
113
|
-
- gemfiles-master-
|
114
|
-
|
115
|
-
- run: bundle config --local path vendor/bundle
|
116
|
-
|
117
|
-
- run:
|
118
|
-
|
119
|
-
name: bundle install
|
120
|
-
|
121
|
-
command: bundle check || bundle install --jobs=8 --clean
|
122
|
-
|
123
|
-
- run:
|
124
|
-
|
125
|
-
name: Run rubocop
|
126
|
-
|
127
|
-
command: bundle exec rubocop --parallel
|
128
|
-
|
129
|
-
- save_cache:
|
130
|
-
|
131
|
-
key: gemfiles-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
|
132
|
-
|
133
|
-
paths:
|
134
|
-
|
135
|
-
- vendor/bundle
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
heroku_deploy:
|
140
|
-
|
141
|
-
working_directory: ~/bookreco
|
142
|
-
|
143
|
-
docker:
|
144
|
-
|
145
|
-
- image: sue445/heroku-cli
|
146
|
-
|
147
|
-
steps:
|
148
|
-
|
149
|
-
- checkout
|
150
|
-
|
151
|
-
- build-tools/install-ci-tools
|
152
|
-
|
153
|
-
- jq/install
|
154
|
-
|
155
|
-
- run:
|
156
|
-
|
157
|
-
name: Identify who I am
|
158
|
-
|
159
|
-
command: echo 'export MY_EMAIL=`heroku auth:whoami | tail -n 1`' >> $BASH_ENV
|
160
|
-
|
161
|
-
- run:
|
162
|
-
|
163
|
-
name: Identify Heroku app names to destroy
|
164
|
-
|
165
|
-
command: echo 'export APP_NAMES_TO_REMOVE=`heroku apps --json | jq -r "map(select(.owner.email == "\"$MY_EMAIL\"" and (.name | contains(\"bookreco\")))) | sort_by(.updated_at) | reverse | .[5:] | .[].name"`' >> $BASH_ENV
|
166
|
-
|
167
|
-
- run:
|
168
|
-
|
169
|
-
name: Delete old apps if needed
|
170
|
-
|
171
|
-
command: for app_name in $APP_NAMES_TO_REMOVE; do heroku apps:destroy -a $app_name -c $app_name; done
|
172
|
-
|
173
|
-
- run:
|
174
|
-
|
175
|
-
name: Define Heroku app name to create
|
176
|
-
|
177
|
-
command: timestamp=`date +%Y%m%d%H%M%S` && echo "export HEROKU_APP_NAME=bookreco-$timestamp" >> $BASH_ENV
|
178
|
-
|
179
|
-
- run:
|
180
|
-
|
181
|
-
name: Create fresh Heroku app
|
182
|
-
|
183
|
-
command: heroku apps:create $HEROKU_APP_NAME --addons=jawsdb:kitefin
|
184
|
-
|
185
|
-
- run:
|
186
|
-
|
187
|
-
name: Deploy
|
188
|
-
|
189
|
-
command: git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git master
|
190
|
-
|
191
|
-
- run:
|
192
|
-
|
193
|
-
name: Run post-deploy tasks
|
194
|
-
|
195
|
-
command: |
|
196
|
-
|
197
103
|
heroku config:set AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY AWS_REGION=$AWS_REGION AWS_HOST_NAME=$AWS_HOST_NAME AWS_BUCKET=$AWS_BUCKET
|
198
104
|
|
199
105
|
heroku run bin/rails db:migrate
|
@@ -250,53 +156,97 @@
|
|
250
156
|
|
251
157
|
```ここに言語を入力
|
252
158
|
|
159
|
+
/.env
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
AWS_ACCESS_KEY_ID = '********'
|
164
|
+
|
165
|
+
AWS_SECRET_ACCESS_KEY = '*******'
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
CircleCIの歯車アイコンからAdd Variablesを選択し、AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY、という名前でそれぞれ環境変数を追加済![イメージ説明](346e8a1fb5e184838b44b901f044a2c3.png)
|
170
|
+
|
171
|
+
試したこと
|
172
|
+
|
173
|
+
---
|
174
|
+
|
175
|
+
・credentials.yml.encのaccess_keyの値は初期値から任意の値へ変更済
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
・「rails c」コマンドを使い、中身の値を確認
|
180
|
+
|
181
|
+
pry(main)> ENV['AWS_ACCESS_KEY_ID']⇨
|
182
|
+
|
183
|
+
pry(main)>Rails.application.credentials.secret_key_base⇨
|
184
|
+
|
185
|
+
コマンドの結果、どちらもcredentials.yml.encの中身を確認することができた
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
・config/master.keyの中身に値は作成されている
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
・config/environments/production.rbの中に「config.require_master_key = true」と記載
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
・carrierwave.rb修正⇨下記のように修正するも解決せず
|
198
|
+
|
199
|
+
```ここに言語を入力
|
200
|
+
|
253
|
-
a
|
201
|
+
config/initializers/carrierwave.rb
|
254
|
-
|
255
|
-
|
256
|
-
|
202
|
+
|
203
|
+
|
204
|
+
|
257
|
-
|
205
|
+
require 'carrierwave/storage/abstract'
|
206
|
+
|
258
|
-
|
207
|
+
require 'carrierwave/storage/file'
|
208
|
+
|
209
|
+
require 'carrierwave/storage/fog'
|
210
|
+
|
211
|
+
CarrierWave.configure do |config|
|
212
|
+
|
213
|
+
if Rails.env.development? || Rails.env.test?
|
214
|
+
|
215
|
+
config.storage = :file
|
216
|
+
|
259
|
-
if Rails.env.production?
|
217
|
+
elsif Rails.env.production?
|
260
|
-
|
218
|
+
|
261
|
-
storage :fog
|
219
|
+
config.storage :fog
|
220
|
+
|
262
|
-
|
221
|
+
config.fog_provider = 'fog/aws'
|
222
|
+
|
263
|
-
e
|
223
|
+
config.fog_directory = 'bookreco'
|
264
|
-
|
224
|
+
|
265
|
-
|
225
|
+
config.fog_credentials = {
|
226
|
+
|
227
|
+
provider: 'AWS',
|
228
|
+
|
229
|
+
aws_access_key_id: Rails.application.credentials.aws[:access_key_id],
|
230
|
+
|
231
|
+
aws_secret_access_key: Rails.application.credentials.aws[:secret_access_key],
|
232
|
+
|
233
|
+
region: 'ap-northeast-1'
|
234
|
+
|
235
|
+
}
|
266
236
|
|
267
237
|
end
|
268
238
|
|
269
|
-
|
239
|
+
end
|
270
|
-
|
240
|
+
|
271
|
-
```
|
241
|
+
```
|
272
|
-
|
273
|
-
|
242
|
+
|
274
|
-
|
275
|
-
/.env
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
AWS_ACCESS_KEY_ID = '********'
|
280
|
-
|
281
|
-
AWS_SECRET_ACCESS_KEY = '*******'
|
282
|
-
|
283
|
-
|
243
|
+
本題
|
284
|
-
|
285
|
-
|
244
|
+
|
286
|
-
|
287
|
-
試したこと
|
288
|
-
|
289
|
-
---
|
245
|
+
---
|
290
|
-
|
291
|
-
|
246
|
+
|
292
|
-
|
293
|
-
pry(main)> ENV['AWS_ACCESS_KEY_ID']⇨結果.envの中身を確認することができた
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
・carrierwave.rb
|
247
|
+
・carrierwave.rbに値をそのまま入れるとcircleciのdeployはクリアします。
|
248
|
+
|
249
|
+
その為原因として環境変数の設定に問題があるのだと思うのですが、どんな些細な可能性でも差し支えありません、アドバイスいただけないでしょうか。手当たり次第試している為情報が撮り散らかり申し訳ありません。
|
300
250
|
|
301
251
|
```ここに言語を入力
|
302
252
|
|
@@ -304,70 +254,18 @@
|
|
304
254
|
|
305
255
|
|
306
256
|
|
307
|
-
require 'carrierwave/storage/abstract'
|
308
|
-
|
309
|
-
require 'carrierwave/storage/file'
|
310
|
-
|
311
|
-
require 'carrierwave/storage/fog'
|
312
|
-
|
313
|
-
CarrierWave.configure do |config|
|
314
|
-
|
315
|
-
if Rails.env.development? || Rails.env.test?
|
316
|
-
|
317
|
-
config.storage = :file
|
318
|
-
|
319
257
|
elsif Rails.env.production?
|
320
258
|
|
321
|
-
config.storage :fog
|
322
|
-
|
323
|
-
config.fog_provider = 'fog/aws'
|
324
|
-
|
325
|
-
config.fog_directory = 'bookreco'
|
326
|
-
|
327
259
|
config.fog_credentials = {
|
328
260
|
|
329
261
|
provider: 'AWS',
|
330
262
|
|
331
|
-
aws_access_key_id:
|
263
|
+
aws_access_key_id: '******',
|
332
|
-
|
264
|
+
|
333
|
-
aws_secret_access_key:
|
265
|
+
aws_secret_access_key: '******',
|
334
266
|
|
335
267
|
region: 'ap-northeast-1'
|
336
268
|
|
337
269
|
}
|
338
270
|
|
339
|
-
end
|
340
|
-
|
341
|
-
end
|
342
|
-
|
343
|
-
```
|
271
|
+
```
|
344
|
-
|
345
|
-
本題
|
346
|
-
|
347
|
-
---
|
348
|
-
|
349
|
-
・carrierwave.rbに値をそのまま入れるとcircleciのdeployはクリアします。
|
350
|
-
|
351
|
-
その為原因として環境変数の設定に問題があるのだと思うのですが、どんな些細な可能性でも差し支えありません。アドバイスいただけないでしょうか。
|
352
|
-
|
353
|
-
```ここに言語を入力
|
354
|
-
|
355
|
-
config/initializers/carrierwave.rb
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
elsif Rails.env.production?
|
360
|
-
|
361
|
-
config.fog_credentials = {
|
362
|
-
|
363
|
-
provider: 'AWS',
|
364
|
-
|
365
|
-
aws_access_key_id: '******',
|
366
|
-
|
367
|
-
aws_secret_access_key: '******',
|
368
|
-
|
369
|
-
region: 'ap-northeast-1'
|
370
|
-
|
371
|
-
}
|
372
|
-
|
373
|
-
```
|
2
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -342,4 +342,32 @@
|
|
342
342
|
|
343
343
|
```
|
344
344
|
|
345
|
+
本題
|
346
|
+
|
347
|
+
---
|
348
|
+
|
349
|
+
・carrierwave.rbに値をそのまま入れるとcircleciのdeployはクリアします。
|
350
|
+
|
345
|
-
どんな些細な可能性でも差し支えありません。アドバイスいただけないでしょうか。
|
351
|
+
その為原因として環境変数の設定に問題があるのだと思うのですが、どんな些細な可能性でも差し支えありません。アドバイスいただけないでしょうか。
|
352
|
+
|
353
|
+
```ここに言語を入力
|
354
|
+
|
355
|
+
config/initializers/carrierwave.rb
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
elsif Rails.env.production?
|
360
|
+
|
361
|
+
config.fog_credentials = {
|
362
|
+
|
363
|
+
provider: 'AWS',
|
364
|
+
|
365
|
+
aws_access_key_id: '******',
|
366
|
+
|
367
|
+
aws_secret_access_key: '******',
|
368
|
+
|
369
|
+
region: 'ap-northeast-1'
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
```
|
1
試したことを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -283,3 +283,63 @@
|
|
283
283
|
```
|
284
284
|
|
285
285
|
CircleCIの歯車アイコンからAdd Variablesを選択し、AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY、という名前でそれぞれ環境変数を追加済![イメージ説明](346e8a1fb5e184838b44b901f044a2c3.png)
|
286
|
+
|
287
|
+
試したこと
|
288
|
+
|
289
|
+
---
|
290
|
+
|
291
|
+
・「rails c」コマンドを使い、中身の値を確認
|
292
|
+
|
293
|
+
pry(main)> ENV['AWS_ACCESS_KEY_ID']⇨結果.envの中身を確認することができた
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
・carrierwave.rb修正⇨下記のように修正するも解決せず
|
300
|
+
|
301
|
+
```ここに言語を入力
|
302
|
+
|
303
|
+
config/initializers/carrierwave.rb
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
require 'carrierwave/storage/abstract'
|
308
|
+
|
309
|
+
require 'carrierwave/storage/file'
|
310
|
+
|
311
|
+
require 'carrierwave/storage/fog'
|
312
|
+
|
313
|
+
CarrierWave.configure do |config|
|
314
|
+
|
315
|
+
if Rails.env.development? || Rails.env.test?
|
316
|
+
|
317
|
+
config.storage = :file
|
318
|
+
|
319
|
+
elsif Rails.env.production?
|
320
|
+
|
321
|
+
config.storage :fog
|
322
|
+
|
323
|
+
config.fog_provider = 'fog/aws'
|
324
|
+
|
325
|
+
config.fog_directory = 'bookreco'
|
326
|
+
|
327
|
+
config.fog_credentials = {
|
328
|
+
|
329
|
+
provider: 'AWS',
|
330
|
+
|
331
|
+
aws_access_key_id: Rails.application.credentials.aws[:access_key_id],
|
332
|
+
|
333
|
+
aws_secret_access_key: Rails.application.credentials.aws[:secret_access_key],
|
334
|
+
|
335
|
+
region: 'ap-northeast-1'
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
```
|
344
|
+
|
345
|
+
どんな些細な可能性でも差し支えありません。アドバイスいただけないでしょうか。
|