4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Docker + CircleCI + Rails】Missing secret_key_base エラー

Last updated at Posted at 2021-01-24

環境

Ruby 2.7.1
Rails 6.0.3.4

CircleCIを使ってECSへデプロイ時に以下のようなエラーが発生

rake aborted!
ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `rails credentials:edit`

結論

Railsのmaster.keyをCircleCIの環境変数に設定しconfig.ymlとDockerfileに設定した環境変数を渡す事で解決しました。

Step1

CircleCI環境変数設定
nameをRAILS_MASTER_KEYとし、
valueにmaster.keyの値を入力

Step2

Dockerfileに追記

Dockerfile
# 追記
ARG RAILS_MASTER_KEY
ENV RAILS_MASTER_KEY ${RAILS_MASTER_KEY}

Step3

CircleCIの設定

.circleci/config.yml
      - aws-ecr/build-and-push-image:
          # 追記
          extra-build-args: '--build-arg RAILS_MASTER_KEY=${RAILS_MASTER_KEY}'

extra-build-argsで設定する事でCircleCI内で設定した環境変数をRails側でENVとして受け取る事が出来るとのことです。

参考にさせていただいた記事

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?