我有一个 Rails 6 应用程序,其凭据在本地 Docker 上运行。
为了在 AWS ElasticBeanstalk 上启动并运行它,我想将 Assets 预编译为 Docker 构建的一部分。然而,正如 this issue in the rails repo 中所述,我在 rake assets:precompile
上收到以下错误:Missing encryption key to decrypt file with. Ask your team for your master key and write it to config/master.key or put it in the ENV['RAILS_MASTER_KEY'].
我添加了 RAILS_MASTER_KEY
作为 EB 环境中的环境变量(配置 > 软件 > 修改),但在 Docker 构建期间,它不会从那里读取 Env 变量。
允许 Docker 构建访问环境变量的最佳和最安全的方法是什么?我应该运行我的assets:precompile
在部署之前?
在本地,我可以通过将 key 作为构建参数传递来在生产模式下预编译 Assets (请参阅 Dockerfile 中我解析 RAILS_MASTER_KEY 参数并设置它的部分),但是,这似乎不是生产的正确选择?或者如果是,我应该怎么做?
我的 Dockerfile:
FROM ruby:2.6.3-slim
ARG RAILS_MASTER_KEY
bla bla install yarn etc
RUN gem install bundler
#Install gems
RUN mkdir /gems
WORKDIR /gems
COPY Gemfile .
COPY Gemfile.lock .
RUN bundle install
ARG INSTALL_PATH=/opt/my_app
ENV INSTALL_PATH $INSTALL_PATH
ENV RAILS_MASTER_KEY $RAILS_MASTER_KEY
WORKDIR $INSTALL_PATH
COPY . .
RUN RAILS_ENV=production rake assets:precompile
最佳答案
您添加的主 key 可能不正确。检查 config/master.key
中的主 key (在本地)。本地和 aws 中的主 key 必须相同。
此外,请确保在 AWS 中添加主 key 。进入控制台打印主 key ENV['RAILS_MASTER_KEY']
.
关于ruby-on-rails - Rails 6 rake Assets :precompile failing with Docker on AWS due to missing Master Key Env variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58202309/