Skip to content

Instantly share code, notes, and snippets.

@tarun-pacifica
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarun-pacifica/2bf1ba9650008fb974ba to your computer and use it in GitHub Desktop.
Save tarun-pacifica/2bf1ba9650008fb974ba to your computer and use it in GitHub Desktop.
Heroku Configuration

Deploying to Heroku using Sinatra

###Downloads

  • Begin by downloading and installing The Heroku Toolkit via MacOSX or Ubuntu. (The Toolkit includes Heroku Command Line utility, as well as git and Foreman.)

  • Install the Bundler gem for Ruby. ( Learn about Bundler )

$ gem install bundler

###Adding Files

  • Create a new folder and ensure your folder is not git-enabled...
$ mkdir newfolder
$ cd newfolder/
$ git status

...which should return:

fatal: Not a git repository (or any of the parent directories): .git
  • Create a gemfile document
$ touch Gemfile 

Create a Config.ru file to enable RackUp operations. Add this line

$ touch config.ru
$ cat > config.ru 
require './main.rb' run Sinatra::Application 
[CTRL-D]

Foreman uses a text file named ‘Procfile’ in the root directory of your app to declare what processes need to run. Create a Procfile

$ touch Procfile
  • Open Gemfile in your text editor. Specify the production gems that your application depends.
source 'https://rubygems.org'
gem 'sinatra'
gem 'pry'
gem 'sinatra-reloader'
  • Bundle your gems
$ bundle 

... which should return something like this:

Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
  • Edit Procfile to run your main ruby file:
web: bundle exec ruby main.rb -p $PORT

###Deployment

  • Now Login to Heroku and create a SSH Key
$ heroku login
Enter your Heroku credentials.
Email: adam@example.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /Users/adam/.ssh/id_rsa.pub
  • Create a new web application
$ heroku create
Creating murmuring-galaxy-997... done, stack is cedar
http://murmuring-galaxy-997.herokuapp.com/ | git@heroku.com:murmuring-galaxy-997.git
Git remote heroku added
  • Connect your local repository to the Heroku repository
$ heroku git:remote -a murmuring-galaxy-997
Git remote heroku added.
  • Test using Foreman, if it doesn't run properly, fix bugs and then test again.
$ foreman start
16:39:04 web.1 | started with pid 30728
18:49:43 web.1 | [2013-03-12 18:49:43] INFO WEBrick 1.3.1
18:49:43 web.1 | [2013-03-12 18:49:43] INFO ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
18:49:43 web.1 | [2013-03-12 18:49:43] INFO WEBrick::HTTPServer#start: pid=30728 port=5000
  • Push your code to Heroku
$ git add .
$ git commit -m "first deployment to heroku"
$ git push heroku master
  • Check your status with logs
$ heroku logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment