英文:
`fly deploy` fails to deploy Rails 7 app with "Missing encryption key to decrypt file with." when rails master key is present on Fly.io
问题
I'm here to help with the translation. Here's the content you provided in Chinese:
我正在尝试评估 Fly.io 并部署一个已存在的 Rails 7 应用程序。按照他们的指南 existing rails apps,fly launch
正常工作,但是 fly deploy
在 assets:precompile
步骤中失败了。
控制台输出:
=> [build 5/6] RUN bundle exec bootsnap precompile app/ lib/ 1.1s
=> ERROR [build 6/6] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile 2.1s
------
> [build 6/6] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
#16 2.043 Missing encryption key to decrypt file with. Ask your team for your master key and write it to /rails/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile]: exit code: 1
显然,这是一个常见的问题,Fly 的 入门指南 中提到了这个问题。
我的 Rails 主密钥位于正确的配置文件 (config/master.key) 中,错误输出甚至链接到了该文件。
Fly launch 成功创建了 RAILS_MASTER_KEY
环境变量,我已确认密钥是正确的。
我的 secret_key_base
在 Rails 凭据文件中。
我尝试将 Dockerfile 设置为以下两种方式之一:
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
结果都导致相同的错误。
还有 这个 GitHub 问题,但似乎解决方案是虚拟的 secret key base。
有什么建议可以尝试以解决这个问题吗?
英文:
I'm trying to evaluate Fly.io and deploy an existing Rails 7 app. Following their guide for existing rails apps, fly launch
works fine, however fly deploy
fails on the assets:precompile
step.
Console Ouput:
=> [build 5/6] RUN bundle exec bootsnap precompile app/ lib/ 1.1s
=> ERROR [build 6/6] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile 2.1s
------
> [build 6/6] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
#16 2.043 Missing encryption key to decrypt file with. Ask your team for your master key and write it to /rails/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile]: exit code: 1
Obviously, this is a common enough problem that it’s mentioned in Fly's Getting Started Guide
I have my Rails master key in the correct config file (config/master.key), and the error output even links to the file.
Fly launch successfully created the RAILS_MASTER_KEY
env variable and I’ve confirmed that the key is correct.
My secret_key_base
is in the rails credentials file.
I've tried setting the Dockerfile to both of these:
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
Both result in the same error
There's also this issue on github, but the solution to that seems to be the dummy secret key base.
Any suggestions for what to try in order to resolve this?
答案1
得分: 3
以下是您要求的中文翻译:
我现在已经成功使其工作,尽管这不是一个理想的解决方案。
我已经更新了Dockerfile,手动添加了一个ARG和ENV变量用于RAILS_MASTER_KEY,并将密钥值作为构建参数传递。
Dockerfile
ARG RAILS_MASTER_KEY
# 设置生产环境
ENV RAILS_ENV="production" \
BUNDLE_WITHOUT="development:test" \
BUNDLE_DEPLOYMENT="1" \
RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
如果您在本地安装了Docker,可以进行本地测试:
sudo docker compose build --build-arg RAILS_MASTER_KEY=$(cat config/master.key)
部署到Fly.io:
fly deploy --build-arg RAILS_MASTER_KEY=$(cat config/master.key)
英文:
I have now managed to get this to work although it's not an ideal solution.
I've updating the Dockerfile to manually add an ARG and ENV var for the RAILS_MASTER_KEY and then passing the key value as a build arg.
Dockerfile
ARG RAILS_MASTER_KEY
# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_WITHOUT="development:test" \
BUNDLE_DEPLOYMENT="1" \
RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
Testing locally if you have docker installed:
sudo docker compose build --build-arg RAILS_MASTER_KEY=$(cat config/master.key)
Deploying to Fly.io:
fly deploy --build-arg RAILS_MASTER_KEY=$(cat config/master.key)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论