简体   繁体   中英

Ruby on rails. Heroku compile assets timeout when i add unicorn gem

-----> Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   !     Timed out compiling Ruby app (15 minutes)
   !     See https://devcenter.heroku.com/articles/slug-compiler#time-limit

When I delete unicorn gem from gemfile assets:precompile start works... How i can fix this?

Since this seems like a setup issue to me, I'll give you the guides I've been looking at.

The way I would solve this would be to google the error. When I typed in heroku unicorn setup I got this page: https://devcenter.heroku.com/articles/rails-unicorn

UPDATE: The error that I was struggling with was an asset compilation issue. That was brought to my attention through using inspect element on my webpage. So I went through a few guides again to make sure the assets pre-complied (can only give the names since I already have two links):

  1. Deploying Rails Applications with Unicorn
  2. Getting Started with Rails 4.x on Heroku
  3. SQLite on Heroku (I had to update my app from SQLite)
  4. Rails 4 Asset Pipeline on Heroku

Otherwise, here's the guide I've been following:

below are some instructions for getting your app onto heroku...

Heroku specific instructions:

NOTE: everything from below this point will be for getting your app ready for deployment onto Heroku.   

To enable features such as static asset serving and logging on Heroku add rails_12factor gem to the end of your Gemfile.

gem 'rails_12factor', group: :production

Specify specific Ruby. At the end of your gemfile add...

ruby "2.1.2"

Add Unicorn Webserver to your Gemfile:

Inside your gemfile

gem 'unicorn'

Then run

$ bundle install

Now you are ready to configure your app to use Unicorn.

Create a configuration file for Unicorn at config/unicorn.rb:

$ touch config/unicorn.rb

Add Unicorn specific configuration options In file config/unicorn.rb:

worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

This default configuration assumes a standard Rails app with Active Record. You should get acquainted with the different options in the official Unicorn documentation .

Finally you will need to tell Heroku how to run your Rails app by creating a Procfile in the root of your application directory.

Add a Procfile:

touch Procfile
(note: the case is important!)

in the Procfile write:

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

Set the RACK_ENV to development in your environment and a PORT to connect to. Before pushing to Heroku you'll want to test with the RACK_ENV set to production since this is the enviroment your Heroku app will run in.

$ echo "RACK_ENV=development" >> .env
$ echo "PORT=3000" >> .env

You'll also want to add .env to your .gitignore since this is for local enviroment setup.

$ echo ".env" >> .gitignore
$ git add .gitignore
$ git commit -m "add .env to .gitignore"

Test your Procfile locally using Foreman:

$ gem install foreman

You can now start your web server by running

$ foreman start
18:24:56 web.1  | I, [2013-03-13T18:24:56.885046 #18793]  INFO -- : listening on addr=0.0.0.0:5000 fd=7
18:24:56 web.1  | I, [2013-03-13T18:24:56.885140 #18793]  INFO -- : worker=0 spawning...
18:24:56 web.1  | I, [2013-03-13T18:24:56.885680 #18793]  INFO -- : master process ready
18:24:56 web.1  | I, [2013-03-13T18:24:56.886145 #18795]  INFO -- : worker=0 spawned pid=18795
18:24:56 web.1  | I, [2013-03-13T18:24:56.886272 #18795]  INFO -- : Refreshing Gem list
18:24:57 web.1  | I, [2013-03-13T18:24:57.647574 #18795]  INFO -- : worker=0 ready

Press Ctrl-C to exit and you can deploy your changes to Heroku:

$ git add .
$ git commit -m "use unicorn via procfile"
$ git push heroku master

Check ps, you'll see the web process uses your new command specifying Unicorn as the web server

$ heroku ps
=== web (1X): `bundle exec unicorn -p $PORT -c ./config/unicorn.rb`
web.1: starting 2014/04/17 12:55:33 (~ 1s ago)

At this point you can follow the normal procedure to get your app on heroku

git init git add -A git commit -m "initial commit"

get things set up on github....then

heroku create git push heroku master

Migrate the database on Heroku

heroku run rake db:migrate

make sure the app is set to run

heroku ps:scale web=1

open the app

heroku open

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM