Heroku assets precompile error, despite compiling assets locally - ruby-on-rails

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

Related

How to set up RefineryCMS with Heroku and Amazon AWS assets

I've spent most of the last three days struggling with installing RefineryCMS on Heroku.
There are a lot of questions on SO and on various blogs, as well as documentation from Refinery and Heroku (and Rails) but none of the walkthroughs have helped 100%... Every page seems to be missing some vital piece of information.
I've tried to document all the necessary steps having gone through them three or four times, refining the procedure each time (working out what is and isn't necessary).
References included where they were obvious.
Run the refinery initialisation script, with Heroku option
refinerycms myapp --heroku
From http://refinerycms.com/guides/heroku
The output should give you a new heroku app and its name listed in the output:
"Creating Heroku app.. run heroku create --stack cedar from "."
Creating ... done, stack is cedar
http://[your heroku app].herokuapp.com/ | git#heroku.com:[your heroku app].git
Git remote heroku added"
Create bucket on Amazon AWS…
Should be self-explanatory.
Set connection info for Amazon in the Heroku environment
We need both sets of credentials.
AWS_* and FOG_* is for Heroku (and the rails precompile, I believe).
S3_* stuff is for Refinery to be able to upload images etc.
heroku config:add AWS_ACCESS_KEY_ID="<your key>" AWS_SECRET_ACCESS_KEY="<your secret>" FOG_DIRECTORY="<your bucket name>" FOG_PROVIDER="AWS" FOG_REGION="<your aws region>"
heroku config:add S3_BUCKET="<your bucket name>" S3_KEY="<your key>" S3_REGION="<your aws region>" S3_SECRET="<your secret>"
Add required gems to your Gemfile
gem 'globalize3', '0.3.0'
From refinerycms not working when adding page
gem 'unf'
(fixes some warnings)
gem 'rails_12factor'
From Why is the rails_12factor gem necessary on Heroku?
gem 'asset_sync'
From https://github.com/rumblelabs/asset_sync.
This gem seems the only way to get the assets pushed up to the cloud... Although perhaps you can make do without it; perhaps someone else can confirm.
ruby '2.0.0'
[ place this at the end of the Gemfile. (Needed to clear Heroku warnings) ]
Add asset_sync asset host path in config/environments/production.rb
config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
From https://github.com/rumblelabs/asset_sync
Set the site name in config/initializers/refinery/core.rb
config.site_name = <your site name>
Set the s3_backend in the config/environments/production.rb
Refinery::Core.config.s3_backend = true
From https://github.com/refinery/refinerycms/issues/1879
Configure database details
Remove sqlite3 in config/database.yml and setting postgresql instead: this is optional but recommended by Heroku and others
For adapter:
sqlite3 => postgresql
For database name:
db/foo.sqlite3 => <sitename>_foo
Set user-env-precompile settings
heroku labs:enable user-env-compile -a myapp
From https://devcenter.heroku.com/articles/labs-user-env-compile
Run the Bundler
bundle install
Note: First of all, I had to run, as prompted:
1. rvm use 2.0.0 in order to match the version we're using in Gemfile
2. bundle update globalize3
From refinerycms not working when adding page
Create (local) production database
RAILS_ENV=production rake db:create
Set environment variables needed before asset precompile can work
(this is for *nix, do whatever you need to on your platform)
export FOG_DIRECTORY="<your bucket name>"
export FOG_PROVIDER="AWS"
export AWS_SECRET_ACCESS_KEY="<your secret>"
export AWS_ACCESS_KEY_ID="<your key>"
Precompile the assets (???)
NOTE: This MAY NOT be required... (I did do this step each time but cannot be sure whether it's required. The next steps suggest to me it's not necessary to manually precompile: we need to change the "initialize_on_precompile" to false, run a git push to heroku (i.e. without assets), then set the "initialize_on_precompile" back to true for future pushes. Not sure why we need to do this, and it may be an issue only with Rails 3.* (see: https://devcenter.heroku.com/articles/rails-asset-pipeline)
RAILS_ENV=production bundle exec rake assets:precompile
Set precompile false in config/application.rb
config.assets.initialize_on_precompile = false
From http://refinerycms.com/guides/heroku…
This setting is required the first time you git push to heroku, because otherwise the precompile step of git push heroku master always fails with:
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?
NOTE: The reference is not clear on this (although setting intially to false then true is mentioned elsewhere).
Check in files to git and commit changes
Note: add the Gemfile.lock along with all the other changes.
Push to heroku
git push heroku master
Set precompile option back to true in config/application.rb
config.assets.initialize_on_precompile = true
From http://refinerycms.com/guides/heroku…
Add config/application.rb to git and commit (!!)
... if you don't, the next push will fail
Push to heroku (Demonstrates that this time it succeeds)
git push heroku master
Migrate and seed on the Heroku database
heroku run rake db:migrate
heroku run rake db:seed
From http://refinerycms.com/guides/heroku
Ready to go!
Hopefully from here you have access to your RefineryCMS page, with all the Refinery CSS and images displaying correctly (both on the admin screens and when 'viewing website' but still logged in.
If you add an image using the Refinery menu you should subsequently be able to see that image added to your AWS bucket. I don't have thumbnails working yet.

Precompilation failing heroku even when using user-env-compile

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.

Heroku Deployment : Discourse Assets precompile

Hi I'm actually trying to deploy discourse on Heroku.
I'm following the step by step guide here Basic Heroku deployment
I'm facing a problem when I try to rake assets:precompile (I'm precompiling locally).
The rake command is aborted, saying to me that
No such file or directory: mydirectories/discourse/config/database.yml
When I rake assets:precompile I'm in production environment (RAILS_ENV=production).
So I checked if the database.yml was missing in the repo, and yes it was.
I currently have two database.yml but a bit different. There's database.yml.development-sample and
database.yml.production-sample.
I tried renaming database.yml.production-sample to a simple database.yml but it still doesn't work giving me this error:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
What am I doing wrong ?
Cordially,
Rob
PS : The config/redis.yml and public/assets are commented in the .gitignore
# http://shcatula.wordpress.com/2013/07/08/deploying-discourse-to-heroku/ you have a detailed description of deployment of Discourse to Heroku. It also links to a gist with a shell script that does the entire job of pre-compiling and preparing your deploy. The shell script pretty much explains all the steps needed. Hope it helps!

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