Precompilation failing heroku even when using user-env-compile - ruby-on-rails

I'm trying to push up to Heroku, but I'm getting this error:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
I'm using Ruby 2.0 and Rails 4.0. I've seen posts that say I should enable user-env-compile so that my environment variables are used in Heroku slug compilation, so I did this:
heroku labs:enable user-env-compile --app <my app's name>
I've also disabled it and re-enabled it. But, I'm still getting the same error. What could be the problem? What am I doing wrong?

It's less than ideal, but I was having a similar issue using Rails 4 on Heroku and resorted to pre-compiling locally using: RAILS_ENV=production bundle exec rake assets:precompile.
If you want to avoid having your compiled assets in master, you could create a deploy branch, pre-compile, commit, push to heroku and then destroy.

Related

How to rake db:migrate on a Heroku staging pipeline?

I've setup an app on Heroku, and I've now also set up a pipeline for staging. I did this by creating a fork of my production app on Heroku, then adding this to the app pipeline under the "staging" stage.
Before this (when I only had the app in production), I pushed updates to heroku from the CLI with git push heroku master. I could then update the database for new features with heroku run rake db:migrate.
However, I'm not sure how you would do this with a staging app in a pipeline? I tried using the --remote appendage but it doesn't recognise the app (I think because the --remote was pre pipelines?)
I have auto updates from git setup so that my app-staging always mirrors my git master, and I've just added a new feature which includes a table. The view on the staging site is now returning an error as I haven't run heroku run rake db:migrate on the staging site.
I obviously don't want to push these changes to production without know this new feature works. So how do you do it? Any ideas how to rake db:migrate the pipeline staging database? I can't find any guidance in the heroku manual either :/
Run
git remote -v
to see your remote name.
Assuming your staging remote name is staging, then:
heroku run rake db:migrate --remote staging
Read more

Getting Error while pushing into Heroku (Precompiling assets failed.)

Note: I am using Rails 3.2.13 and Ruby "1.9.3", and postgres-0.15.1
I tried to push my Ruby on Rails app in to heroku by following the procedure this website
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-deploying
, but I got error while try to push into heroku
Connecting to database specified by DATABASE_URL
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
! Precompiling assets failed.
! Push rejected, failed to compile Ruby app
To git#heroku.com:pure-hamlet-9148.git
! [remote rejected] master -> master (pre-receive hook declined)
So, I Googled myself and run the below command
heroku labs:disable user-env-compile
heroku labs:enable user-env-compile
Still getting the same error, please some help me to resolve this issue.
Along with Simone's answer,
Follow this website to precompile your assets locally before deploying. https://devcenter.heroku.com/articles/rails-asset-pipeline
RAILS_ENV=production bundle exec rake assets:precompile
git add public/assets -f
git commit -m "vendor compiled assets"
Check this article about Heroku and Rails asset:precompile error. You should set
config.assets.initialize_on_precompile = false
A way to resolve this error:
First of all set DATABASE_URL environment variable & then again tried to push code to Heroku again. And it worked as all rake compilation done at Heroku side so no more connection to local machine making rake compilation # .../tmp/bin..... directory.

Heroku assets precompile error, despite compiling assets locally

I am currently first time deploying my app to Heroku, and am encountering the precompile error. When I execute the command git push heroku master, I get:
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
After a bit of searching, I encountered both Heroku's own troubleshooting guide on precompile error, as well as this post on precompile errors and Rails 3.2, and following their directions, did the following:
Added config.assets.initialize_on_precompile = false to my application.rb file
Made a new heroku app using heroku create just to be safe
Per the Rails guide, ran bundle exec rake assets:precompile
I thought that since I am doing the compiling locally, when pushing to Heroku it would just skip the compilation part based on detecting a manifest.yml file. However, even when I do so, when running git push heroku master, it will still run rake assets:precompile and generate the same error as seen above.
Thanks in advance for you help!
Addendum
In my .gitignore, I have the following:
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
At first glance, I would assume that it should work.
Can you confirm that you have committed and merged all changes into master? i.e. git status

Rails 3.1 to 3.2.6 upgrade - asset_sync error

Making lots of progress in a rails 3.1 to 3.2.6 upgrade for a Heroku app.
I use asset_sync and precompile assets onto S3. I use the asset_sync.rb initialiser to config my S3 connection details.
Getting an error when I attempt to run
RAILS_ENV=production bundle exec rake assets:precompile
AssetSync: using /Users/bob/work/myapp/config/initializers/asset_sync.rb
rake aborted!
could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Tasks: TOP => environment
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/bob/.rvm/rubies/ruby-1.9.3-p...]
That's very strange. I checked that it is listening as per Postgres permission denied on MAC OS X that question and related comments.
this isn't an error with asset_sync, but the asset precompile process itself (specifically on heroku) try config.assets.initialize_on_precompile = false in your production or application.rb
What this will do is make sure your application code does not get initialized unnecessarily, which at precompile time, your heroku database my not be available.
Also it's not an issue with just Rails 3.2.6 but 3.2.x I believe.

Tutorial demo_app won't work on heroku

I'm trying to run the chapter two demo_app from the Ruby on Rails 3 Tutorial book on Heroku and it is not working. gws-demp-app.heroku.com gives the default Rails page, but gws-demo-app.heroku.com/users gives a web page that says "We're sorry, but something went wrong." On my desktop it works fine. I'm using the tools from RailsInstaller.org.
I had problems with heroku rake db:migrate at the end of the chapter not finding the activerecord-postgresql-adapter so I did install gem pg, bundle install, and updated the Gemfile and repositories. Everything is on github at https://github.com/gwshaw/demo_app.
What looks like the same problem appears at https://stackoverflow.com/questions/7619551/heroku-rake-dbmigrate-success-but-not-showing-in-app
I tried heroku restart recommended there, but that causes: Restarting processes... C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/net/http.rb:6
44:in `initialize': getaddrinfo: No such host is known. (SocketError)
I tried what is claimed to work, precompiling assets with bundle exec rake assets:precompile, but that generates an error: C:/RailsInstaller/Ruby1.9.2/bin/ruby.exe C:/RailsInstaller/Ruby1.9.2/bin/rake as
sets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
TypeError: Object doesn't support this property or method
(in C:/Sites/rails_projects/demo_app/app/assets/javascripts/application.js)
I'm new to ruby and rails so I'm at a loss. Any ideas?
Solved below.
Yes , this worked for me too after installing the pg gem, I ran the following:
bundle exec rake assets:precompile
git add .
git commit -am "add a note reflecting changes made"
git push
heroku create
git push heroku master
heroku rake db:migrate
heroku db:push
after invoking these commands, I was able to successfully open the demo_app on heroku.
Thanks for your post — I'm new to Rails, but reading your post helped me with a very similar issue.
Here's what worked for me:
Install pg gem to use postgreSQL on Heroku: (related article)
sudo gem install pg
Install taps gem to allow push of your local database to Heroku: (related article)
gem install taps
then the following sequence…
bundle exec rake assets:precompile
git add .
git commit -am "add a note reflecting changes made"
git push
heroku create
git push heroku master
heroku rake db:migrate
heroku db:push
If you're still having trouble, these articles are helpful too:
Stack Overflow - Heroku command: Heroku Rake db:migrate fails
Heroku - Getting Started with Rails 3.0 on Heroku/Cedar
The problem with bundle exec rake assets:precompile was the key and is solved here RoR Precompiling Assets fail while rake assets:precompile - on basically empty application.js
Oddly, Heroku wouldn't automatically precompile the assets on a git push heroku and thus would not find them. I don't think this little demo_app even uses assets, so that may be why it didn't precompile, but it still could not find applicaiton.css and failed. Once I set config.log_level = :debug in production.rb, I could see the problem in the logs. With the precompile working due to the above fix, everything worked.

Resources