Search code examples
ruby-on-rails-3.1herokuasset-pipeline

rake assets:precompile failing during push to Heroku


I'm currently using asset_sync in my Rails app, and I have the environment variables set in my Heroku app. When I run heroku config I get:

AWS_ACCESS_KEY_ID:     XXXXXXXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY: XXXXXXXXXXXXXXXXXX
FOG_DIRECTORY:         MY-BUCKET-NAME
FOG_PROVIDER:          AWS
etc...

When I push my app to Heroku, it tries to run rake assets:precompile and I get the following message:

Preparing app for Rails asset pipeline
Running: rake assets:precompile
/usr/local/bin/ruby /tmp/build_2pa7aisux9av8/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
AssetSync: using /tmp/build_2pa7aisux9av8/config/initializers/asset_sync.rb
rake aborted!
Fog directory can't be blank, Aws access key can't be blank, Aws secret access key can't be blank

But then I run:

heroku run rake assets:precompile --app my-app-name

...and it processes everything and syncs to S3 just fine:

Running `rake assets:precompile` attached to terminal... up, run.1
/usr/local/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets
AssetSync: using /app/config/initializers/asset_sync.rb
/usr/local/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=staging RAILS_GROUPS=assets
AssetSync: using /app/config/initializers/asset_sync.rb
AssetSync: Syncing.
Using: Directory Search of /app/public/assets
Uploading: assets/application-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.css
Uploading: assets/application-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.css.gz
Uploading: assets/application-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.css.gz
Uploading: assets/application-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.css
AssetSync: Done.

Any ideas why it wouldn't work during the push but it would work fine when I heroku run rake assets:precompile?


Solution

  • I can see you're running the assets:precompile rake task with --app my-app-name option. Just to be sure, do you have multiple apps on Heroku? (eg. staging and production). If you do make sure make sure running heroku config --app my-app-name results in the output you had with heroku config.

    If you had the expected results with the above command, it's likely the ENV vars aren't available on git push as suggested here asset_sync_test github readme . You can go around that by using the following in your config/environments/*.rb file:

    config.asset_sync.aws_access_key = ENV['AWS_ACCESS_KEY_ID']
    config.asset_sync.aws_access_secret = ENV['AWS_SECRET_ACCESS_KEY']
    config.asset_sync.aws_bucket = ENV['FOG_DIRECTORY']
    config.asset_sync.fog_provider = ENV['FOG_PROVIDER']