【发布时间】:2020-06-12 07:41:48
【问题描述】:
我碰壁了。我正在通过 Elastic Beanstalk 将 Rails 6 应用程序部署到 AWS。部署是通过eb cli完成的,我是用git来做的。
无论我尝试什么,我遇到的错误是:
ArgumentError: key must be 16 bytes
每当我尝试访问加密凭据时都会发生这种情况,例如Rails.application.credentials.sendgrid[:api_key],这些凭据是使用带有EDITOR="mvim -f" rails credentials:edit --environment production 的环境密钥设置的
我所看到的一切都在使用 Rails 5.2,而且一切似乎都使用 master.key 而不是特定于环境的 yml 文件来存储。
我尝试过的:
- 在 EB Web 控制台的环境属性中设置
RAILS_MASTER_KEY - 我可以做到
eb printenv,我确实看到了这个密钥 - 在
config/production.rb我已经设置了config.require_master_key = true - 我尝试将
RAILS_PRODUCTION_KEY设置为与主密钥相同的值,但还是不行 - 我添加了
RAILS_ENV和production作为环境属性的值 - 我添加了自己的容器 ebextensions 来运行迁移和预编译内容,但每当我尝试检索凭据时,它们仍然会以相同的方式出错。
总的来说,它似乎无法正确获取主密钥,并且抱怨密钥不是正确的 16 字节。
当我在本地运行 RAILS_ENV=production bundle exec rails c 时,它工作得很好,我可以获得所有凭据。
这是我的 .ebextensions/config 文件:
# Beanstalk ain't ready for Rails 6. This fix is courtesy of https://austingwalters.com/rails-6-on-elastic-beanstalk/
# Additional node 6 cleanup courtesy of https://github.com/nodesource/distributions/issues/486
commands:
00_remove_node_6_if_present:
command: "/bin/rm -rf /var/cache/yum && /usr/bin/yum remove -y nodejs && /bin/rm /etc/yum.repos.d/nodesource* && /usr/bin/yum clean all"
ignoreErrors: true
01_download_nodejs:
command: "curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -"
02_install_nodejs:
command: "yum -y install nodejs"
03_install_yarn:
command: "sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo && sudo yum install yarn -y"
04_mkdir_webapp_dir:
command: "mkdir /home/webapp"
ignoreErrors: true
05_chown_webapp_dir:
command: "chown webapp:webapp /home/webapp"
ignoreErrors: true
06_chmod_webapp_dir:
command: "chmod 0744 /home/webapp"
ignoreErrors: true
07_chmod_logs:
command: "chown webapp:webapp -R /var/app/current/log/"
ignoreErrors: true
08_create_log_file:
command: "touch /var/app/current/log/production.log"
ignoreErrors: true
09_chown_log_production:
command: "chown webapp:webapp /var/app/current/log/production.log"
ignoreErrors: true
10_chmod_log_dir:
command: "chmod 0664 -R /var/app/current/log/"
ignoreErrors: true
11_update_bundler:
command: "gem update bundler"
ignoreErrors: true
12_config_for_update_nokogiri:
command: "bundle config build.nokogiri --use-system-libraries"
13_chown_current:
command: "chown webapp:webapp -R /var/app/current/"
ignoreErrors: true
14_chmod_current:
command: "chmod 0755 -R /var/app/current/"
ignoreErrors: true
15_chown_current:
command: "chown webapp:webapp -R /var/app/ondeck/"
ignoreErrors: true
16_chown_current:
command: "chmod 0644 -R /var/app/ondeck/"
ignoreErrors: true
container_commands:
17_install_webpack:
command: "npm install --save-dev webpack"
18_config_for_update_nokogiri:
command: "bundle config build.nokogiri --use-system-libraries"
19_precompile:
command: "RAILS_ENV=production bundle exec rake assets:precompile"
20_database_migration:
leader_only: true
command: "RAILS_ENV=production bundle exec rake db:migrate"
【问题讨论】:
标签: amazon-elastic-beanstalk ruby-on-rails-6