I decided to serve rails assets via S3; heroku has great tutorials on how to do this. The site is now serving assets from my amazon bucket but I'm unsure why I had to manually run heroku run rake assets:precompile
after a git push heroku master
which runs a rake assets:precompile
.
After running the git push heroku master
the assets where not in my bucket and the output for the precompile stuff was:
AssetSync: using default configuration from built-in initializer
AssetSync: using default configuration from built-in initializer
rake aborted!
Fog provider can't be blank, Fog directory can't be blank
/tmp/build_3vtwfg15g8ajx/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.5.0/lib/asset_sync/asset_sync.rb:29:in `sync'
/tmp/build_3vtwfg15g8ajx/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.5.0/lib/tasks/asset_sync.rake:3:in `block in <top (required)>'
Tasks: TOP => assets:precompile:nondigest
(See full trace by running task with --trace)
Precompiling assets failed, enabling runtime asset compilation
Injecting rails31_enable_runtime_asset_compilation
I did set the fog provider and directory with: heroku config:add FOG_DIRECTORY=XXX FOD_PROVIDER=AWS
and calling heroku config --app confirms this...so I don't get those errors.
The assets didn't show up in my bucket so I ran: heroku run rake assets:precompile
and everything worked with a warning:
AssetSync: using default configuration from built-in initializer
AssetSync: Syncing.
[WARNING] fog: the specified s3 bucket name(ss_assets) is not a valid dns name, which will negatively impact performance. For details see: http://docs.amazonwebservices.com/AmazonS3/latest/dev/Bucket
Restrictions.html
Will I always have to run the precompile task after and just be okay with the push failure? I'll check to see if the Warning of the directory name is causing the blank FOG errors on push
EDIT Again asset_sync doesn't appear to have ENV variables when called in the assets:precompile task of the heroku push. Running that task after push works but it 'annoying'.
Still not working for me, latest attempt was (per asset_sync github project):
lib/tasks/asset_sync.rake.
Rake::Task['assets:precompile'].enhance do
AssetSync.sync
end
Rake::Task["assets:precompile:nondigest"].enhance do
AssetSync.sync
end
I also attempted adding lines to my production.rb file such as:
config.asset_sync.aws_bucket = ENV['FOG_DIRECTORY']
config.asset_sync.fog_provider = ENV['FOG_PROVIDER']
Didn't work for me either.