puma - 为什么在部署后找不到我的数字海洋空间的 Rails 凭据?
问题描述
我在使用空间将我的 rails 6 应用程序部署到 Digital Ocean 时遇到问题。部署后,网络服务器失败。在 Puma 日志中,我发现:
Unable to load application: Aws::Sigv4::Errors::MissingCredentialsError: missing credentials, provide credentials with one of the following options:
Feb 05 03:33:25: - :access_key_id and :secret_access_key
Feb 05 03:33:25: - :credentials
Feb 05 03:33:25: - :credentials_provider
这是我的相关导轨设置:
宝石文件
gem 'aws-sdk-s3'
配置/存储.yml
digitalocean_spaces:
service: S3
access_key_id: <%= Rails.application.credentials.dig(:digitalocean_spaces, :access_key_id) %>
secret_access_key: <%= Rails.application.credentials.dig(:digitalocean_spaces, :secret_access_key) %>
region: nyc3
endpoint: 'https://nyc3.digitaloceanspaces.com'
bucket: foobar-bucket
环境/生产.rb
config.active_storage.service = :digitalocean_spaces
凭证.yml.enc
digitalocean_spaces:
access_key_id: foobar
secret_access_key: secretfoobar
解决方案
当您通过执行生成凭证文件时EDITOR="nano -w" rails credentials:edit --environment production
,在保存类似这样的内容后会打印到控制台:
Adding config/credentials/production.key to store the encryption key: c1463bd04a5521e81cbe2a496a91af52
Save this in a password manager your team can access.
If you lose the key, no one, including you, can access anything encrypted with it.
create config/credentials/production.key
Ignoring config/credentials/production.key so it won't end up in Git history:
append .gitignore
服务器必须知道密钥才能解密凭据。
我正在使用 DO 应用程序,必须转到我的应用程序 -> 设置 -> 应用程序级环境变量 -> 编辑并添加RAILS_MASTER_KEY
其中包含生成的密钥
推荐阅读
- telegram - Telegram 机器人可以运行多个问题的民意调查吗?
- node.js - Prisma:使用具有非唯一字段的“where”进行更新?
- python - 我可以将运算符 +,-,/,* 分配给 python 中的字符串吗?
- javascript - Bootstrap 4 Card Carousel 未显示多个项目
- flutter - 当 Future Builder 处于 ConnectionState.waiting 时,Flutter App 卡住了
- visual-studio-2019 - 安装新更新后,Visual Studio 2019 Git 在提交和推送时显示“commit --allow-empty-message --file=-”消息。不再提交和推送
- browser - 无法从域向 localhost 发送请求(net::ERR_BLOCKED_BY_CLIENT 错误)
- javascript - 鼠标悬停变成文字
- reactjs - 无法渲染我做错了什么?
- javascript - 如何用剩余的缺失月份填充一组对象(总共 12 个月)