我有一个 Rails 7.1.3.2 应用程序,我正在使用 Dokku 将其部署到服务器。
在部署过程中,我收到此错误:
remote: ------
remote: Dockerfile:37
remote: --------------------
remote: 35 |
remote: 36 | # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
remote: 37 | >>> RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
remote: 38 | #RUN if [[ "$RAILS_ENV" == "production" ]]; then \
remote: 39 | # mv config/credentials.yml.enc config/credentials.yml.enc.backup; \
我在github上发现了这个/类似的问题,添加了这个推荐之后,上面的错误消失了,但是又弹出了一个类似的问题:
=====> Start of redata-prod container output (web.1)
bin/rails aborted!
ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `bin/rails credentials:edit` (ArgumentError)
raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/rails/config/environment.rb:5:in `<main>'
Tasks: TOP => db:prepare => db:load_config => environment
(See full trace by running task with --trace)
我不确定如何处理生产的 Secret_key_base 密钥。我该如何解决这个错误?
如有任何建议,我们将不胜感激。
如果您正在部署基于 Dockerfile 的应用程序,Dokku 应用程序中的环境变量将通过构建参数自动公开(从 Dokku 0.31.0 开始)。这遵循 Docker 关于环境变量的最佳实践(请参阅 docker/docker#13490 了解基本原理) - 您只能指定构建参数,而不是环境变量,并且必须显式使用它们。
除了公开 --build-arg
docker 选项之外,您还需要在使用任何参数之前在 Dockerfile 中指定一个指令,以将该值公开为环境变量
。要公开构建参数,请运行以下命令:
dokku docker-options:add node-js-app build '--build-arg SECRET_KEY_BASE'
接下来,您的
Dockerfile
在使用环境变量之前
需要具有以下内容:
# set the argument default
ARG SECRET_KEY_BASE=some-dummy-value
# assign it to an environment variable
# we can wrap the variable in brackets
ENV SECRET_KEY_BASE ${SECRET_KEY_BASE}
请参阅 Dokku 文档了解更多信息。