dmb*_*o11 15 crash ruby-on-rails heroku amazon-web-services rails-activestorage
我的应用程序部署到 Heroku,但每次都崩溃。我不知道为什么。我已经在 Heroku 上为生产中的应用程序设置了 Carrierwave、雾和 aws,然后就好了。尝试按照相同的步骤操作,但我收到了 h10 错误代码。在 rails 控制台中,它特别指出:
/app/vendor/bundle/ruby/2.3.0/gems/activestorage-5.2.1/lib/active_storage/engine.rb:76:in `block (2 levels) in ': 找不到 Active Storage 配置 / app/config/storage.yml(运行时错误)
storage.yml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
amazon:
service: S3
access_key_id: "S3_KEY"
secret_access_key: "S3_SECRET"
region: "us-east-1"
bucket: "books4reviews"
Run Code Online (Sandbox Code Playgroud)
生产.rb
config.active_storage.service = :amazon
Run Code Online (Sandbox Code Playgroud)
载波
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['S3_KEY'],
aws_secret_access_key: ENV['S3_SECRET'],
region: 'us-east-1'
}
config.fog_directory = 'books4reviews'
config.fog_public = false
config.storage = :fog
end
Run Code Online (Sandbox Code Playgroud)
美洲狮
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
plugin :tmp_restart
Run Code Online (Sandbox Code Playgroud)
配置文件
web: bundle exec puma -C config/puma.rb
Run Code Online (Sandbox Code Playgroud)
头像_上传者.rb
class AvatarUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# Choose what kind of storage to use for this uploader:
include CarrierWave::MiniMagick
storage :fog
process resize_to_fit: [500,500]
version :small do
process resize_to_fill: [200, 200]
end
version :medium do
# change the word 'fit' to 'fill'
process resize_to_fill: [400,600]
end
version :large do
process resize_to_fill: [1000,1000]
end
version :thumb do
process resize_to_fill: [50, 50]
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
Run Code Online (Sandbox Code Playgroud)
我已经在终端的 heroku 配置变量中为 aws 凭证设置了我的 env 变量。你能告诉我为什么我会收到这个活动存储错误吗?谢谢
Pro*_*ton 18
我在部署最近升级的 Rails 应用程序时遇到了同样的问题。应用程序从Rails 5升级到Rails 6。但是,当我尝试部署到Heroku 时,出现以下错误:
2021-02-12T17:32:33.404828+00:00 app[web.1]: ! Unable to load application: RuntimeError: Couldn't find Active Storage configuration in /app/config/storage.yml
2021-02-12T17:32:33.404874+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.7.0/bin/puma)
2021-02-12T17:32:33.404958+00:00 app[web.1]: RuntimeError: Couldn't find Active Storage configuration in /app/config/storage.yml
Run Code Online (Sandbox Code Playgroud)
这是我修复它的方法:
我检查了config我的应用程序的目录,发现它没有config/storage.yml文件。我所要做的就是创建文件,并将Rails 6应用程序附带的 vanilla 模板复制到文件中:
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
# region: us-east-1
# bucket: your_own_bucket
# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
# project: your_project
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# storage_account_name: your_account_name
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
# container: your_container_name
# mirror:
# service: Mirror
# primary: local
# mirrors: [ amazon, google, microsoft ]
Run Code Online (Sandbox Code Playgroud)
这次我部署一切正常。
注意:您可以根据您的存储配置修改文件内容
就这样。
我希望这有帮助
小智 2
这可能无法解决您的问题,但我有“.yaml”而不是“.yml”,因为我必须手动创建文件“/config/storage.yml”并犯了一个拼写错误。
希望这对某人有帮助,因为我找不到有关此错误的很多结果。
仅供参考,我认为生成器没有创建 storage.yml 文件,因为我最初使用的是 Rails 5.1,然后升级到 5.2
| 归档时间: |
|
| 查看次数: |
3169 次 |
| 最近记录: |