我在heroku上构建了一个rails应用程序,并且想要将js,css和图像文件部署到Amazon上的存储桶中。我还没有找到这方面的许多资源,但我正在使用此(2012)教程进行指导; https://firmhouse.com/blog/complete-guide-to-serving-your-rails-assets-over-s3-with-asset_syncAsset_Sync没有推送到S3
该网站目前主要是css和js。这是我的代码到目前为止;
production.rb
Rails.application.configure do
config.action_controller.asset_host = "http://localize.s3.amazonaws.com"
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
end
初始化/ asset_sync.rb
if defined?(AssetSync)
AssetSync.configure do |config|
config.fog_provider = ENV['FOG_PROVIDER']
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
config.fog_directory = ENV['FOG_DIRECTORY']
config.fog_region = ENV['FOG_REGION']
# Don't delete files from the store
config.existing_remote_files = "delete"
# Automatically replace files with their equivalent gzip compressed version
config.gzip_compression = true
# Use the Rails generated 'manifest.yml' file to produce the list of files to
# upload instead of searching the assets directory.
config.manifest = true
config.custom_headers = { '.*' => { cache_control: 'max-age=31536000', expires: 1.year.from_now.httpdate } }
end
end
的Heroku瓦尔
AWS_ACCESS_KEY_ID: *****************
AWS_SECRET_ACCESS_KEY: *****************************
FOG_DIRECTORY: localize
FOG_PROVIDER: AWS
FOG_REGION: us-west-2
周的Gemfile
gem 'rails', '4.1.1'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'sdoc', '~> 0.4.0', group: :doc
#aws
gem "fog", "~>1.20"
gem 'asset_sync'
group :development do
gem 'thin'
end
group :production do
gem 'newrelic_rpm'
gem 'rails_12factor'
gem 'pg'
end
我也跑:
heroku config:add FOG_PROVIDER=AWS AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY=yyy
随着
heroku config:add FOG_DIRECTORY=localize
,然后当我运行
bundle exec rake assets:precompile
或者
RAILS_ENV=production bundle exec rake assets:precompile
我得到这个输出;
rake aborted!
AssetSync::Config::Invalid: Fog directory can't be blank, Aws access key can't be blank, Aws secret access key can't be blank
任何人谁拥有轨道,Heroku的经验,和S3谁可以指导我在正确的方向,将不胜感激。提前致谢。
shouldnt config.fog_directory = ENV ['localize']是config.fog_directory = ENV ['FOG_DIRECTORY']? – Richlewis 2014-10-02 08:44:52
并阅读heroku文档以获取可能需要做的heroku服务器上的VARS heroku config:set FOG_DIRECTORY =本地化例如..你检查了如果使用config:add实际上已经通过做heroku配置添加VARS到heroku服务器:得到FOG_DIRECTORY或者做heroku config查看你上传的所有VARS – Richlewis 2014-10-02 08:47:45
@Richlewis是的,我将代码改为config.fog_directory = ENV ['FOG_DIRECTORY']。我还运行了heroku config:add和heroku config:设置为FOG_DIRECTORY,FOG_PROVIDER,AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY。我现在得到的错误是'rake中止了! AssetSync :: Config ::无效:Aws访问密钥不能为空,Aws秘密访问密钥不能为空,所以它在FOG上工作,但不是AWS – user3749994 2014-10-03 04:33:59