Sunday, August 12, 2012

Deploy Sinatra To Heroku

I tried to follow the examples given in this tutorial, but somehow they did not work for me. Using google, I had to make some changes.

Here's documentation of what I did to make it work.

First, I log in to the heroku server...
$heroku login
Enter your Heroku credentials.
Email: adam@example.com
Password: 
On my computer, I cd into my working directory (/home/j/aaa/), then created a ruby file, web.rb...
require "sinatra"
require "bundler/setup"

get '/' do
  "Hello, world"
end
I then created my Gemfile, as this was required by heroku, with the following content...
source 'http://rubygems.org'
gem 'sinatra', '1.1.0'
gem 'thin'
One more file that was needed to deploy my Sinatra app with heroku was a Procfile.

A Procfile is a script for a mechanism for declaring what commands are run by your application’s dynos on the Heroku platform. It follows the process model on the large scale of the Heroku dyno manifold. You can use Procfile to declare any other process types, such as a multiple types of workers, or a singleton process like a clock or a consumer of the Twitter streaming API (source - heroku)

"I don't exactly know what that means atm. All I know is that I wouldn't be able to deploy without that script." On my terminal, I type in gvim Procfile, then input the following into that file...
web: bundle exec ruby web.rb -p $PORT

After I have these setup in my working directory (~/j/aaa), on my terminal, I then do...
git init
git add .
git commit -m "init"

If you need to review what these git commands mean, look here--Git Reference

Back to heroku, on my terminal, I type in...
heroku create jims08122012   # => my app name

Creating jims08122012... done, stack is cedar
http://jims08122012.herokuapp.com/ | git@heroku.com:jims08122012.git
Git remote heroku added

And finally...
git push heroku master

Warning: Permanently added the RSA host key for IP address '50.19.85.156' to the list of known hosts.
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 688 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby app detected
-----> Installing dependencies using Bundler version 1.2.0.rc
       Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
       Fetching gem metadata from http://rubygems.org/.....
       Installing daemons (1.1.9)
       Installing eventmachine (0.12.10) with native extensions
       Installing rack (1.4.1)
       Installing tilt (1.3.3)
       Installing sinatra (1.1.0)
       Installing thin (1.4.1) with native extensions
       Using bundler (1.2.0.rc)
       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
-----> Discovering process types
       Procfile declares types -> web
       Default types for Ruby  -> console, rake
-----> Compiled slug size is 1.9MB
-----> Launching... done, v3
       http://jims08122012.herokuapp.com deployed to Heroku

No comments:

Post a Comment