Skip to content

Instantly share code, notes, and snippets.

@dcuadraq
Last active August 29, 2015 14:16
Show Gist options
  • Save dcuadraq/dda7c113f476e31d240b to your computer and use it in GitHub Desktop.
Save dcuadraq/dda7c113f476e31d240b to your computer and use it in GitHub Desktop.
Add existing rails project to heroku
# 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
This file should be at app's root level with no extension
  web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

Steps to upload a rails 4 project to Heroku

1.- Create the Heroku app where it will be uploaded.
2.- Download and install Heroku toolbelt if it is not installed already.
3.- In the terminal, login in to Heroku
  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
6.- Run the migrations.
  heroku run rake db:migrate
7.- Set variables if any.
  heroku config:set API_KEY=secret
8.- Restart Heroku app.
  heroku restart
9.- View app in browser from the Heroku server.
  heroku open
# # 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