web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
Last active
August 29, 2015 14:16
-
-
Save dcuadraq/dda7c113f476e31d240b to your computer and use it in GitHub Desktop.
Add existing rails project to heroku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby version has to be 1.9.3 or above, by default is 2.0 | |
... | |
ruby '2.2.0' | |
# Heroku uses only supports Postgresql | |
# Check database.yml to make sure production is using postgresql | |
gem 'pg' #, group: :production # in case of using another db for development | |
gem 'rails', '4.2.0' | |
gem 'unicorn' | |
gem 'rails_12factor', group: :production | |
... | |
# bundle install |
1.- Create the Heroku app where it will be uploaded.
2.- Download and install Heroku toolbelt if it is not installed already.
heroku login
4.- In the repository root folder, add the remote to the Heroku app previously created in step 1, replace the name fakeapp for your app.
heroku git:remote -a fakeapp
5.- Add the changes in Gemfile, Procfile and unicorn.rb and commit the changes and push them to Heroku.
git push heroku master
heroku run rake db:migrate
heroku config:set API_KEY=secret
heroku restart
heroku open
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # This file should be placed on the directory of 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment