0
votes

I am attempting to deploy my Rails 4 app to Heroku, and when I enter:

git push heroku master

I get the following 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?

From the Rails Asset Pipeline on Heroku Cedar:

This means that your app is attempting to connect to the database as part of rake assets:precompile. Because the config vars are not present in the environment and this is the mechanism the Heroku uses to configure your database connection, the command is failing.

The page suggests that I run

env -i GEM_PATH=$GEM_PATH \
   PATH=$PATH \
   DATABASE_URL=postgres://user:[email protected]/dbname \
   /bin/sh -c 'bundle exec rake --trace  assets:precompile'

When I do, I get the following error:

rake aborted! couldn't find HOME environment -- expanding ~' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/guardfile/generator.rb:20:inexpand_path' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/guardfile/generator.rb:20:in <class:Generator>' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/guardfile/generator.rb:9:in' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/guardfile/generator.rb:2:in <module:Guard>' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/guardfile/generator.rb:1:in' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/guardfile.rb:2:in require' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/guardfile.rb:2:in' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/dsl.rb:1:in require' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard/dsl.rb:1:in' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard.rb:6:in require' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-2.2.4/lib/guard.rb:6:in' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-rspec-4.2.0/lib/guard/rspec.rb:1:in require' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/guard-rspec-4.2.0/lib/guard/rspec.rb:1:in' /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:81:in require' /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:81:inrescue in block in require' /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:66:in block in require' /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:ineach' /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in require' /usr/local/rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler.rb:132:inrequire' /Users/dmanaster1/flatiron_school/SourceQ-An/config/application.rb:5:in <top (required)>' /Users/dmanaster1/flatiron_school/SourceQ-An/Rakefile:5:inrequire' /Users/dmanaster1/flatiron_school/SourceQ-An/Rakefile:5:in <top (required)>' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/rake_module.rb:25:inload' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in load_rakefile' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:637:inraw_load_rakefile' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:94:in block in load_rakefile' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:instandard_exception_handling' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:93:in load_rakefile' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:77:inblock in run' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in standard_exception_handling' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:inrun' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/gems/rake-10.1.0/bin/rake:33:in <top (required)>' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/bin/rake:23:inload' /Users/dmanaster1/flatiron_school/SourceQ-An/vendor/cache/ruby/2.0.0/bin/rake:23:in `'

What is generating this error? How can I fix it?

1
Why are you connecting to the database as part of your precompile step?Vidya
Unless I misunderstand your question, I am not. If you are referring to the command line that begins with env, I am following the instructions at devcenter.heroku.com/articles/rails-asset-pipeline to reproduce the specific error by using a nonexistent DATABASE_URL.dmanaster
As you quoted in your post, the same resource indicates that the cause of the error is "that your app is attempting to connect to the database as part of rake assets:precompile." More generally, it seems to rely on the availability of the environment. The command you ran is supposed to help confirm this. As they say, "you must fix it by not relying on environment variables and the database to be present at precompile time."Vidya
Sorry if I missed the point to your comment - this is my first time deploying, and I am finding the process confusing. I had enabled Heroku Labs' user-env-compile option because I was having issues with loading Devise's secret_key, as suggested in the answer to this SO question.dmanaster

1 Answers

0
votes

I am unfamiliar with user-env-compile, but just set the Devise key as described here:

heroku config:set DEVISE_SECRET_KEY=whatever_the_key_is

Make sure your initializer then uses the key like this:

config.secret_key = ENV['DEVISE_SECRET_KEY']

Then disable user-env-compile like so:

heroku labs:disable user-env-compile -a myapp

And then try to deploy.