Heroku Deploy Bash Script

Quick and short one. The Heroku hosted app I’m working on has a staging env. I need to quickly deploy from local to the staging Heroku remote repo a lot. Doing git push staging whateverbranch:master is fine, but just tedious to type every time. And since the app is at early development stage, I need to constantly deploy to staging from a local feature branch to just do the show-n-tell, a simple bash/zsh alias will not do the job (well, I don’t know, maybe it can …).

So… since I’m using RVM and a project .rvmrc anyway, I throw the following function into my project .rvmrc. With that, I can just do deploy staging, job done!

deploy() {
  local ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  local current_branch=${ref#refs/heads/}

  echo "Deploying to Heroku: "
  echo "   - git push $1 $current_branch:master"
  git push $1 $current_branch:master

  echo "Running database migration: "
  echo "   - heroku run rake db:migrate"
  heroku run rake db:migrate
}

It’s quick and dirty, and once the app gets released I’m sure I’ll come back to modify it or move the deployment into a Rake task. Working just fine for now!

Published: 2012-07-14
blog comments powered by Disqus