前提・実現したいこと
CircleCIを使ってDocker上のRails(5.2.3)アプリをデプロイしたい。
CircleCIのjobのdeployのビルド最中に以下のエラーが発生するので解決したいです。よろしくお願いいたします。
発生している問題・エラーメッセージ
Step 16/18 : RUN RAILS_ENV=production bundle exec rake assets:precompile ---> Running in 48a40c520c0e rake aborted! ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:183:in `_decrypt' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:79:in `decrypt' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:42:in `read' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:21:in `read' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:33:in `config' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:38:in `options' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing' /usr/local/bundle/gems/devise-4.6.2/lib/devise/secret_key_finder.rb:24:in `key_exists?' /usr/local/bundle/gems/devise-4.6.2/lib/devise/secret_key_finder.rb:10:in `find' /usr/local/bundle/gems/devise-4.6.2/lib/devise/rails.rb:37:in `block in <class:Engine>' /usr/local/bundle/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec' /usr/local/bundle/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run' /usr/local/bundle/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers' /usr/local/bundle/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers' /usr/local/bundle/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!' /myapp/config/environment.rb:5:in `<top (required)>' /usr/local/bundle/gems/rake-12.3.2/exe/rake:27:in `<top (required)>' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:74:in `load' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:74:in `kernel_load' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:28:in `run' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/cli.rb:465:in `exec' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/cli.rb:27:in `dispatch' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/cli.rb:18:in `start' /usr/local/bundle/gems/bundler-2.0.2/exe/bundle:30:in `block in <top (required)>' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors' /usr/local/bundle/gems/bundler-2.0.2/exe/bundle:22:in `<top (required)>' /usr/local/bundle/bin/bundle:23:in `load' /usr/local/bundle/bin/bundle:23:in `<main>' Caused by: ArgumentError: key must be 16 bytes /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:193:in `key=' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:193:in `_decrypt' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:79:in `decrypt' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_file.rb:42:in `read' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:21:in `read' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:33:in `config' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb:38:in `options' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing' /usr/local/bundle/gems/devise-4.6.2/lib/devise/secret_key_finder.rb:24:in `key_exists?' /usr/local/bundle/gems/devise-4.6.2/lib/devise/secret_key_finder.rb:10:in `find' /usr/local/bundle/gems/devise-4.6.2/lib/devise/rails.rb:37:in `block in <class:Engine>' /usr/local/bundle/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `instance_exec' /usr/local/bundle/gems/railties-5.2.3/lib/rails/initializable.rb:32:in `run' /usr/local/bundle/gems/railties-5.2.3/lib/rails/initializable.rb:61:in `block in run_initializers' /usr/local/bundle/gems/railties-5.2.3/lib/rails/initializable.rb:60:in `run_initializers' /usr/local/bundle/gems/railties-5.2.3/lib/rails/application.rb:361:in `initialize!' /myapp/config/environment.rb:5:in `<top (required)>' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency' /usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require' /usr/local/bundle/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!' /usr/local/bundle/gems/railties-5.2.3/lib/rails/application.rb:520:in `block in run_tasks_blocks' /usr/local/bundle/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/cli.rb:27:in `dispatch' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/cli.rb:18:in `start' /usr/local/bundle/gems/bundler-2.0.2/exe/bundle:30:in `block in <top (required)>' /usr/local/bundle/gems/bundler-2.0.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors' /usr/local/bundle/gems/bundler-2.0.2/exe/bundle:22:in `<top (required)>' /usr/local/bundle/bin/bundle:23:in `load' /usr/local/bundle/bin/bundle:23:in `<main>' Tasks: TOP => environment (See full trace by running task with --trace) The command '/bin/sh -c RAILS_ENV=production bundle exec rake assets:precompile' returned a non-zero code: 1 Error: Exited with code 1 Step failed Error: runner failed (exited with 101) Task failed Error: task failed
該当のソースコード
Dockerfile
1FROM ruby:2.5.5-stretch 2ENV LANG C.UTF-8 3 4RUN apt-get update -qq && apt-get install -y \ 5 build-essential \ 6 nodejs \ 7 vim \ 8 mysql-client \ 9 && rm -rf /var/lib/apt/lists/* 10 11RUN gem install bundler 12 13WORKDIR /tmp 14ADD Gemfile Gemfile 15ADD Gemfile.lock Gemfile.lock 16RUN bundle install 17 18ENV APP_HOME /myapp 19RUN mkdir -p $APP_HOME 20WORKDIR $APP_HOME 21ADD . $APP_HOME 22 23EXPOSE 3000 24 25ENV RAILS_ENV production 26 27 28ARG RAILS_MASTER_KEY 29ENV RAILS_MASTER_KEY $RAILS_MASTER_KEY 30 31 32RUN RAILS_ENV=production bundle exec rake assets:precompile 33RUN rm -f tmp/pids/server.pid 34CMD ["bundle", "exec", "rails", "s", "puma", "-b", "0.0.0.0", "-p", "3000", "-e", "production"] 35
circleci
1version: 2 2jobs: 3 4 ~中略~ 5 deploy: 6 docker: 7 - image: circleci/python:3.7.4-stretch-node-browsers-legacy 8 steps: 9 - checkout 10 - setup_remote_docker 11 - run: 12 name: install aws 13 command: | 14 sudo pip install awscli 15 aws --version 16 - run: 17 name: Install ecs-deploy 18 command: | 19 curl https://raw.githubusercontent.com/silinternational/ecs-deploy/master/ecs-deploy | sudo tee -a /usr/bin/ecs-deploy 20 sudo chmod +x /usr/bin/ecs-deploy 21 - run: 22 name: Install jq 23 command: sudo apt-get install -y jq 24 - run: 25 name: Log in AWS ECR 26 command: eval $(aws ecr get-login --no-include-email --region ap-northeast-1) 27 - run: 28 name: Build & Push Docker Image 29 command: | 30 sudo docker build -f ./Dockerfile_pro -t myapp . 31 sudo docker tag myapp:latest $AWS_ACCOUNT_ID.dkr.ecr.ap-northeast-1.amazonaws.com/myapp:latest 32 sudo docker push $AWS_ACCOUNT_ID.dkr.ecr.ap-northeast-1.amazonaws.com/myapp:latest 33 - run: 34 name: "DB Migrate" 35 command: | 36 aws ecs run-task \ 37 --region ap-northeast-1 \ 38 --cluster myapp \ 39 --task-definition myapp \ 40 --overrides file://ecs/run_task_db_migrate.json 41 - run: 42 name: "Sevice deploy" 43 # environment: 44 command: | 45 ecs-deploy -c myapp-cluster -n myapp_app_service \ 46 -r ap-northeast-1 -t 240 \ 47 -i $AWS_ACCOUNT_ID.dkr.ecr.ap-northeast-1.amazonaws.com/myapp:$CIRCLE_SHA1 48 ~中略~ 49
試したこと
config/master.keyが参照されていないのと考えた。
よってローカルの〜/.bash_profileとCircleCIのマイページにて環境変数RAILS_MASTER_KEYを設置したが結果は変わらず。
production.rbは以下の設定
config.require_master_key = true config.assets.compile = true
補足情報(FW/ツールのバージョンなど)
circleciの検証はローカル環境で行なっております。
Docker : 18.09.2
CircleCI : 2
Rails : 5.2.3
Ruby : 2.5.5p157
MySQL : 8.0.16
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/23 09:38
2019/07/23 12:08
2019/07/23 12:13