Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From Nothing to Continuous Deployment in about 10 Minutes

These instructions walk you through using Raygun to generate a new app, pushing it to GitHub, deploying it to Heroku (two envs: production and acceptance), and setting up continuous integration and deployment using CircleCI. There's a preference for command-line operations when possible.

Prerequisties

  • Homebrew
  • Heroku toolbelt (brew install heroku-toolbelt)
  • Postgres installed (brew install postgres) and running
  • Postgres superuser called 'postgres' (createuser -s postgres)
  • PhantomJS installed (brew install phantomjs)
  • GitHub gem (gem install hub)

From Nothing to Continuous Deployment

Create project then push it to GitHub and Heroku (x2)

#-------------------------------
# Install Prequisites

brew install heroku-toolbelt postgres phantomjs  # be sure to init and start postgres
createuser -s postgres                           # generic db superuser
gem install raygun hub

#-------------------------------
# Generate the app and database setup

raygun bee-tracker  # you should use something different/unique
cd bee-tracker
./bin/setup

# Run the specs, they should all pass
RAILS_ENV=test rake

# Check out the running app locally
foreman s
open http://locahost:3000

#-------------------------------
# Push it to GitHub

hub create
git push

#-------------------------------
# Deploy "production" to Heroku

heroku apps:create bee-tracker
git remote rename heroku production
git config remote.production.push master:master
git push production
heroku run rake db:migrate db:seed

# Kick the tires...
open http://bee-tracker.herokuapp.com

#-------------------------------
# Deploy "acceptance" to Heroku

git co -b development
git push -u origin HEAD
heroku fork -a bee-tracker bee-tracker-acceptance
heroku config:set RACK_ENV=acceptance RAILS_ENV=acceptance -a bee-tracker-acceptance
git remote add acceptance https://git.heroku.com/bee-tracker-acceptance.git
git config remote.acceptance.push development:master
git push acceptance
heroku run rake db:migrate db:seed -a bee-tracker-acceptance

# Kick the tires...
open http://bee-tracker-acceptance.herokuapp.com

Setup continuous integration and deployment using CircleCI

Follow these steps using the CircleCI web UI:

  1. Visit http://circleci.com.
  2. Authenticate with GitHub.
  3. Follow the git repo.
  4. Open up the project settings, select Heroku, set Heroku API Key and the Heroku deploy user.
  5. Retry the build when/if it fails during deploy (Heroku settings were missing).

Changes to development are deployed to acceptance when they pass CI. Changes to master are deployed to production.

Viola! You have a shiny new Rails app on GitHub, Heroku (prodction and acceptance), and CircleCI. New commits are automatically tested and deployed. Win!

@mwean
Copy link

mwean commented Feb 6, 2015

I've really enjoyed using the parity gem for making heroku commands easier. One issue is that it requires production to be named <APPNAME>-production, and you have to write a small script to support the acceptance environment (rather than staging). The upside is that you can say production console rather than heroku run rails console --app my-app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment