Saturday, April 21, 2012

First steps with Heroku

After bashing together a little web-site using Sinatra a while back, it sat on my machine for several months sobbing gently to itself.  All that changed today when I set out to upload the site to Heroku.

I already had a Heroku account and knew my way around Ruby and Sinatra (in which the site was written).  Uploading involved using git though, and that's where most of my learning was to be done.  I followed a mash-up of the instructions here and here.  What follows is a reminder for myself of what I actually ended up doing; maybe I'll look back and laugh at my naivete later.

First up, I needed to get the files on my local machine ready for git.  I already had git installed so I did

cd /my/app/dir
git init
git add .
git status

Whoops, I'd added far too many intermediate files.  I created a .gitignore file in my app's root directory

touch .gitignore

Then I did some Googling to find out how to remove things I'd accidentally added to my git staging area. I hit gold on stackoverflow) and ran

git rm --cached -r "*mini*"

which worked a treat.  It took longer than I'd like (15 mins or so) to work out the proper syntax to match the filenames I wanted (they all had the word 'mini' in them and it wasn't obvious from the git man pages that git rm would accept a wildcarded filename).  So then I wrote

git commit -m "Initial app commit"

So good so far.  I pretty well understood what I'd been doing git-wise, even if it wasn't second nature and I knew I'd probably forget the precise commands.  With my push pending I needed somewhere to push it to.  Logging on to my account at heroku.com I selected an empty Heroku app I must have created a while ago.  This empty app had a git repo ready created and associated with it, so that was my target location.  Here's what I did

gem install heroku
heroku login
<provided authentication gubbins - username and password - I'd created a git key some time before>
git remote add my_app_name git@heroku.com:my_garbled_heroku_app_name.git
git push my_app_name master

Then I hit the URL listed in my Heroku account and bingo!, there was my app.  And there was much rejoicing!

All I need to do now is figure out the inevitably subtly different workflow I'll use to make and upload changes to my site. :)

No comments: