Skip to content
ejucovy edited this page Aug 8, 2011 · 7 revisions

Background

The deployment system uses Fabric to coordinate deployments. At a high level, the process is:

  1. The Nginx configuration is adjusted to show a maintenance page.
  2. Rerun pip install ... to update the requirements
  3. The latest code is pulled from GitHub.
  4. JavaScript files are merged and minified with the help of require.js and Closure Compiler
  5. CSS files are minified.
  6. All static files are uploaded to an S3 bucket.
  7. manage.py syncdb is run
  8. You are prompted to migrate the database (manage.py migrate)
  9. uWSGI is restarted
  10. The maintenance page is taken down

If you're deploying to a cloud of servers, each application server will be updated with the latest requirements and code

About Fabric

The Fabric files are contained in the fabfile directory at the root of the project. Any of the functions defined in any of the files inside the fabfile directory can be called by using the fab command followed by the name of a function (fab should have been installed and put on your path after installing the requirements with pip).

Multiple functions can by called by space separating their names in the form fab some_function some_other_function. Functions are called in the order they're specified, however it is generally easier to define a new function that itself calls what you need in the proper sequence.

Arguments can be be passed to a fab function by appending a colon to the function name and comma separating the arguments. For example:

fab some_function:arg1,arg2,kwarg=foo,kwarg2=bar

SSH access

Before you can deploy to the development server, you need to be able to ssh to the server.

ssh ubuntu@ec2-107-20-218-152.compute-1.amazonaws.com -i /full/path/to/.ssh/lpkey

Public key authentication is the only option. Make sure the private key from the ec2 keypair is in you .ssh directory with permissions set to 400. To force Fabric to use the right key, set LP_KEY_FILENAME in your environment. Best to just add this to your .bashrc or .bash_profile:

export LP_AWS_ACCESS_KEY="..."
export LP_AWS_SECRET_KEY="..."
export LP_AWS_OWNER_ID="..."
export LP_KEY_FILENAME="/full/path/to/.ssh/lpkey"

Deploying to the development server

Once you are able to ssh to the dev server, cd to the project root, push your git changes, and type:

fab staging deploy

fab is the Fabric command. staging is the name of a function that changes the target of the deployment to the staging server (the term staging is baked into the fabfile, but should probably be changed to 'dev'). deploy is the function the kicks off the actual deploy sequence. So if you wanted to deploy to the production environment (assuming its application and load balancers were specified in the fabfile init.py file), you could use fab deploy.

The deploy function takes three optional parameters which can be used in any combination:

  • fab deploy:code_only=True will only pull the latest code from GitHub and restart uWSGI.
  • fab deploy:revision=<some hash> will deploy a specific revision
  • fab deploy:sync_media=False will skip uploading all the static files to S3.

Clone this wiki locally