Asset_Sync没有推送到S3

时间:2014-10-02 01:03:36

标签: ruby-on-rails-4 heroku amazon-s3

我正在heroku上构建rails应用程序,并希望将js,css和image文件部署到Amazon上的存储桶中。我没有为此找到很多资源,但我正在使用这个(2012)教程进行指导; https://firmhouse.com/blog/complete-guide-to-serving-your-rails-assets-over-s3-with-asset_sync

该网站目前主要是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 Vars

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

任何有过rails,heroku和S3经验的人都会非常感激。提前致谢。

1 个答案:

答案 0 :(得分:0)

好的看看你的设置似乎有些不对劲,我添加了我通常使用的东西,希望它能帮到你

Production.rb

ExampleApp::Application.configure do

config.action_controller.asset_host = "http://exampleapp.s3.amazonaws.com"

config.cache_classes = true

config.consider_all_requests_local       = false
config.action_controller.perform_caching = true

config.serve_static_assets = true

config.assets.compress = true

config.assets.compile = true

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