如何解决缺少用于解密文件的加密密钥向您的团队询问您的主人......它在 ENV['RAILS_MASTER_KEY'] 中 Platform.sh 部署中止,
错误信息: W:缺少用于解密文件的加密密钥。向您的团队询问您的主密钥并将其写入 /app/config/master.key 或将其放入 ENV['RAILS_MASTER_KEY']。
在platform.sh上部署我的项目时,由于缺少解密密钥,操作失败。从我的谷歌搜索中,我找到了解密密钥。
我的 Ubuntu .bashrc
export RAILS_MASTER_KEY='ad5e30979672cdcc2dd4f4381704292a'
platform.sh 的 rails 项目配置
.platform.app.yaml
# The name of this app. Must be unique within a project.
name: app
type: 'ruby:2.7'
# The size of the persistent disk of the application (in MB).
disk: 5120
mounts:
'web/uploads':
source: local
source_path: uploads
relationships:
postgresdatabase: 'dbpostgres:postgresql'
hooks:
build: |
gem install bundler:2.2.5
bundle install
RAILS_ENV=production bundle exec rake assets:precompile
deploy: |
RACK_ENV=production bundle exec rake db:migrate
web:
upstream:
socket_family: "unix"
commands:
start: "\"unicorn -l $SOCKET -E production config.ru\""
locations:
'/':
root: "\"public\""
passthru: true
expires: "24h"
allow: true
routes.yaml
# Each route describes how an incoming URL is going to be processed by platform.sh.
"https://www.{default}/":
type: upstream
upstream: "app:http"
"https://{default}/":
type: redirect
to: "https://www.{default}/"
services.yaml
# The name given to the Postgresql service (lowercase alphanumeric only).
dbpostgres:
type: postgresql:13
# The disk attribute is the size of the persistent disk (in MB) allocated to the service.
disk: 5120
db:
type: postgresql:13
disk: 5120
configuration:
extensions:
- pgcrypto
- plpgsql
- uuid-ossp
environments/production.rb
config.require_master_key = true
我怀疑在部署过程中无法访问master.key,我不明白如何解决问题。
解决方法
据我了解,您的导出位于本地计算机上的 .bashrc
中,因此在 Platform.sh 上部署时将无法访问它。 (您在构建和部署时在终端中看到的日志是流式传输的,这不会发生在您的机器上。)
您需要使 RAILS_MASTER_KEY
在 Platform.sh 上可访问。为此,需要在您的项目中声明此变量。
鉴于变量的性质,我建议使用 Platform CLI 来创建此变量。 如果该变量在您的所有环境中都可以访问,您可以将其设为 project level variable。
$ platform variable:create --level project --sensitive true env:RAILS_MASTER_KEY <your_key>
如果它只能在特定环境中访问,那么您需要一个 environment level variable:
$ platform variable:create --level environment --environment '<your_envrionment>' --inheritable false --sensitive true env:RAILS_MASTER_KEY '<your_key>'
变量名称中的 env:
前缀告诉 Platform.sh 将变量与其余的环境变量一起公开。 variables prefix section 的 environment variables documentation page 中有关此的更多信息。
如果您不想使用命令行,也可以通过 management console 执行相同的操作。
环境变量也可以直接在您的 .platform.app.yaml
文件中配置,如 here 所述。请记住,此文件已进行版本控制,您不应将此方法用于敏感信息,例如加密密钥、API 密钥和其他类型的机密。
现在应该可以在 Platform.sh 部署期间访问 RAILS_MASTER_KEY
环境变量。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。