Capistrano Deployment Guide - YaleSTC/reservations GitHub Wiki

This guide will walk you through the process of deploying Reservations using Capistrano. The deployment scripts are intended to be as general as possible but have been written for use with Yale ITS and have not been extensively tested. Any feedback or help is always appreciated!


Overview

This script is designed to allow for stable deployment of Reservations onto a local server. In other words, it's meant to be called from the application server, not from the development machine. The script requires the following:

  • A Linux webserver
  • Ruby (using RVM) / Rails
  • A local user named hudson with SSH access to localhost
  • A valid configuration file

Syntax

Reservations can be called using the following command:

cap deploy production

It requires three environment variables to be set:

  • GIT_TAG: the Git reference to deploy; this can be either a tag or a branch name
  • DEPLOY_DIR: the directory to deploy Reservations into; the actual application code will be symbolically linked to DEPLOY_DIR/current
  • PARAM_FILE: the location of the configuration parameter file for the instance to deploy; it is copied to DEPLOY_DIR/current/.env

In other words, a complete deployment command could look like:

GIT_TAG=v1.2.3 DEPLOY_DIR=/foo/www PARAM_FILE=/bar/baz.txt cap deploy production

Procedure

In brief, the deployment script does the following:

  1. SSH's into localhost with user hudson
  2. Downloads the application code at the specified Git reference
  3. Runs database migrations
  4. Precompiles assets
  5. Copies the configuration parameter file into the .env file of the new release
  6. Copies the production database.yml template into config/database.yml
  7. Renames config/secrets.yml.example to config/secrets.yml (used to pass-through configuration parameters)
  8. If a GitHub authorization token is specified, renames config/initializers/party_foul.rb.example to config/initializers/party_foul.rb
  9. Updates the crontab using the whenever gem *production environment only*
  10. Touches the file tmp/restart.txt to tell Passenger / Apache to restart

Testing

Currently, this script has been tested in two scenarios:

  1. A DigitalOcean droplet running CentOS 6.7 + Apache + Passenger
  2. Yale ITS VM running RHEL 5.5 + Apache + Passenger

The success of this script in deployment architectures similar or dissimilar to these is not guaranteed; use at your own risk!