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?
To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.
rake assets:precompile. We use rake assets:precompile to precompile our assets before pushing code to production. This command precompiles assets and places them under the public/assets directory in our Rails application.
I had the same problem on one of our servers, until I found the documentation on the asset_sync github page that says you need to run
heroku labs:enable user-env-compile --app <appname>
in order for it to work.
Heroku also has AssetSync documentation
It's so nice to only be compiling assets once now
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With