`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

huangapple go评论66阅读模式
英文:

`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 appsfly launch 正常工作,但是 fly deployassets: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) 

huangapple
  • 本文由 发表于 2023年4月17日 16:09:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032962.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定