rake assets:precompile failing during push to Heroku - ruby-on-rails-3.1

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?

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']

Related

Heroku: where did my gems go?

I have been deploying a Rails 3.2 application to heroku for several weeks now. I have also been executing rake tasks on the Cedar stack where my application is located.
One day after a deploy I noticed that rake was no longer working. I get, for example, the following:
$:~/dev/my_project$ heroku run rake -T
Running `rake -T` attached to terminal... up, run.7566
bundler: command not found: rake
Install missing gem executables with `bundle install`
Trying to run commands with bundle exec yields the same results.
What I've tried:
heroku run bundle install. This works and informs me that gems were installed into ./vendor/bundle. However, heroku run ls ./vendor/bundle yields only the following:
$:~/dev/my_project$ heroku run ls ./vendor/bundle/
Runningls ./vendor/bundle/attached to terminal... up, run.3458
bin ruby
bundle package. Although the deployment works it does not help my problem.
fiddling around with the rubygems-bundler gem (although I think this is now part of core bundler). This does not seem to have any effect.
On Heroku, gems are installed within the vendor/bundle/ruby/<version>/gems directory. I just checked my Heroku instance and confirmed this.
You are going to want to use bundle exec rake task because the gems are not in the users PATH.

Why is assets:precompile so slow on Heroku?

My deployment set up is to have Heroku precompile assets. I want them precompiled so I can send them to a CDN (via asset_sync) and I want that done on Heroku so I don't have any compiled assets in my repo. I set that up using Heroku's guide and that had been working great. I added turbo-sprockets-rails3 for a speed boost. It had all been working fine and then stopped; I can't figure out why.
Now when I deploy (without public/assets) the assets:precompile Rake task times out on Heroku. To see how long it's really taking, I went into a shell (heroku run bash):
~ $ time bundle exec rake assets:precompile
AssetSync: YAML file found /app/config/asset_sync.yml settings will be merged into the configuration
AssetSync: Syncing.
Using: Directory Search of /app/public/assets
AssetSync: Done.
real 19m29.575s
user 17m43.690s
sys 0m28.480s
Twenty minutes! But when I run it locally (2011 iMac), it's only only a few minutes:
$ env RAILS_ENV=production time bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
~/.rbenv/versions/1.9.3-p327-perf/bin/ruby ~/.rbenv/versions/1.9.3-p327-perf/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Invoke assets:cache:clean (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
AssetSync: YAML file found ~/Code/Ruby/myproject-rails/config/asset_sync.yml settings will be merged into the configuration
** Execute assets:cache:clean
** Execute assets:precompile:all
AssetSync: Syncing.
Using: Directory Search of ~/Code/Ruby/myproject-rails/public/assets
Uploading: assets/application-3a6de939348195e9610f1321df27837a.js
Uploading: assets/application-3a6de939348195e9610f1321df27837a.js.gz
Uploading: assets/jquery.min-959a5819c76e1508f5a8655c289c0de8.map
Uploading: assets/jquery.min.map
Uploading: assets/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js
Uploading: assets/rails_admin/rails_admin-76cfbf31a605916a55eee29464ca3e6d.js.gz
AssetSync: Done.
179.92 real 19.29 user 3.98 sys
I wrote Heroku support over a week ago and after some days they said they'd escalate it to their Ruby buildback team, but I still haven't heard anything. Do any of the smart people on Stack Overflow have possible solutions?
The solution was to use tell Heroku to use Ruby 1.9.3, like my local machine. Apparently 1.9.3 is much faster at assets compilation than 1.9.2 which Heroku defaults to.
To fix it, make sure your Gemfile starts:
source "https://rubygems.org"
ruby "1.9.3"
# ...
More at Heroku docs on Ruby versions.

Heroku Error: No such file or directory after Bamboo - Cedar upgrade

I've upgraded my app from Bamboo to Cedar following the instructions here. My problem now is whenever I run any heroku command on the new heroku app I receive the following error
$ heroku run rake db:migrate --app my-app
Running `rake db:migrate` attached to terminal... up, run.1
Error: No such file or directory
The error does not tell me which file is causing this problem so most of the related posts haven't been applicable to this particular problem
The same error occurs for heroku run console, or even heroku run why_wont_this_work
I attempted heroku update, was yelled at for not having the Heroku Toolbelt, installed that, and still get yelled at for not having the Heroku Toolbelt.

Some heroku commands couldn't find my application

I can find my apps in heroku apps command, and also do some command to read information from app like heroku addons --app appname.
But I couldn't find my apps in some command like heroku addons:add addon_name, heroku pg:reset.
Work commands
heroku apps:
=== My Apps
my_app_1
my_app_2
(Also I can see my apps in heroku web dashboard.)
heroku addons --app my_app_1(not in my_app_1 folder):
=== my_app_1 Configured Add-ons
shared-database:5mb
heroku addons(in my_app_1 folder):
=== my_app_1 Configured Add-ons
shared-database:5mb
Doesn't work commands
heroku addons:add sendgrid(in my_app_1 folder):
! No app specified.
! Run this command from an app folder or specify which app to use with --app
heroku pg:reset DATABASE --confirm my_app_1(in my_app_1 folder):
Resetting SHARED_DATABASE (DATABASE_URL)... failed
! Resource not found
Here is my environment.
Max OS X Lion (10.7.4)
rvm 1.13.8 (stable)
ruby 1.9.3p194
heroku 2.26.5
Adding the heroku's remote configuration to git did the trick for me. Validate if you have it configured with git remote -v on the terminal and you should get something like:
heroku git#heroku.com:your-app.git (fetch)
heroku git#heroku.com:your-app.git (push)
if you don't, add it with
git remote add heroku git#heroku.com:your-app.git
It looks like the latest version fo the Heroku gem (2.26.5) is broken. A workaround is to downgrade to 2.26.3.
gem uninstall heroku -v 2.26.5
gem install heroku -v 2.26.3
It looks like you have a conflict between the Heroku gem, and the Heroku Toolbelt. I'm guessing you have installed the Heroku Toolbelt, but still have the Heroku gem in your gem file.
Remove the Heroku gem from your Gemfile and save.
Run the bundle command to update your Gemfile.lock
In Terminal, run gem uninstall heroku (NOTE: there may be multiple versions of the Heroku gem installed, and you'll need to uninstall all of them.)
In Terminal, run heroku addons
If you get heroku: command not found then you don't have the Heroku Toolbelt installed.
Install the Heroku Toolbelt and run the command again.
NOTE: If you're not in the app's directory, you'll need to add --app myapp1 to the Heroku commands.
Hope this helps.

Why my ruby application works locally and does not run on Heroku?

I have a Ruby 1.8.7 application that works correctly locally. To load it on Heroku, I changed the database from SQLite to PostgreSQL, install PostgreSQL 9.1.3, I changed the Gemfile replacing gem sqlite3 with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
And changing the part production of config/database.yml with:
production:
adapter: postgresql
database: project_production
pool: 5
timeout: 5000
Then I run bundle install --without production successfully. Next I created a git repository with:
git init
git add *
git commit -m "text"
Later I create a heroku application with heroku create --stack bamboo-ree-1.8.7 , git push heroku master and heroku rake db:migrate successfully.
But it didn't work!
What's missing? I've done something wrong or I have not made ​​any statement?
Is "git add *" working ? I think you'd better use :
$ git add .
As Larsenal asked, could you post your logs ?
$ heroku logs
The basic information about heroku deployment is here.
You don't need the "production" block in database.yml, this is automatically generated by heroku when deploying.
Kind regards,
Max

Resources