I am a big fan of Sinatra and have been writing a few apps using this lightweight Ruby framework. Deploying them on Heroku is a breeze and painless but I always seem to forget a step so this is more of a note for future me.
I wrote a template that sets up a very basic Sinatra app that outputs JSON — perfect for when I need to set up a basic API for an iOS app. There's no database, so DataMapper is nowhere to be found and there's no tests either, just extreme simplicity.
Assumptions:
- you already have a Heroku account and have the Heroku Toolbelt installed
- you are on a Mac, though I'm sure its not too dissimilar for Windows folk
- You have the Bundler and Shotgun gems already installed
So with that out of the way,
- Download the template, and unzip it into your new apps' folder
- Navigate to the folder in Terminal and then run
bundle install
- Check that everything is working by running
shotgun
. Then fire up a browser and navigate tohttp://127.0.0.1:9393
- Next we need to create the local git repository:
git init
- Now we add all of the files:
git add .
- Then we commit them: `git commit -m 'first commit'
Now we're ready to create the app on Heroku. For this example lets call it "myapp".
- In the Terminal create the app (the default stack nowadays is Cedar which is what we want):
heroku apps:create myapp
- Because the git repository already exists, the Heroku toolbelt should have set up a remote for us, but lets double check:
git remote -v
- Double check that the remotes look like
heroku git@heroku.com:myapp.git
for both fetch and push - Deploy!
git push heroku master
Now if you navigate to http://myapp.herokuapp.com you should see some successful JSON output.
Now go build your app!