Skip to content

A lil' tool for testing, deploying, and maintaining Django apps with Fabric and Supervisor.

Notifications You must be signed in to change notification settings

baiyunping333/fabfiles

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fabfiles

Because deploying Django apps with Fabric is fun!

Installation

First off, you want the source, right? If you didn't already clone this repo, you can easily drop it off in your local dir like so:

curl -L 'https://github.com/mikedory/fabfiles/tarball/master' | tar zx && mv mikedory-fabfiles-* fabfiles

Because it's always a handy way to avoid conflicts, virtualenv is recommended for managing dependencies and Python versions:

pip install virtualenv

Then set up a virtualenv for the app, and activate it (you can turn it off later by running deactivate):

virtualenv venv --distribute && source ./venv/bin/activate 

Then to get the dependencies for this application, install the remaining requirements via Pip:

pip install -r requirements.txt

Make a local_settings.sample.py called local_settings.py, and edit the environment variables accordingly:

cp config/local_settings.sample.py config/local_settings.py

That it! You're all set to deploy things!

But... I'm not using Python?

That's okay too! Just run this one-liner after installing:

echo '#!/bin/bash \nfab -f fabfiles/fabfile.py "$@"' >> fab && chmod +x fab

You can now run all the commands from your app's root directory with ./fab and never need to worry about what's under the hood except for the local_settings options.

Use

Local

There's a bunch of stuff one might need to do locally, and thankfully, Fabric makes this easy. Most of this focuses on testing and getting ready for a deploy, but more can be easily added to your liking.

Testing your app

There's a ton of great testing options for Django apps, so stub in your framework of choice. You can run locally with like so:

fab test

Preparing for a deploy

As noted, this application assumes you're using Django, so we'll use its test framework to ensure everything is kosher first. Then, we'll commit everything, and push it up to Github. The all-in-one command is:

fab prepare

Remote

Putting stuff on remote servers and running processes from afar — the fun part! This is written assuming you're using Supervisor to control your processes (Gunicorn, Tornado, etc.), though that's easily swap-out-able.

Deploying code

To deploy a tag:

fab env deploy:tag=YYYY-MM-DD-tag-description

To deploy a branches:

fab prod deploy:branch=master

So to deploy a tag to production, you can run:

fab prod deploy:tag=YYYY-MM-DD-tag-description

And to deploy to a single server:

fab -u username -H domain.com -i /path/to/.ssh/id_rsa deploy:tag=YYYY-MM-DD-tag-description

If if you don't want to execute Supervisor restarts (or if Virtualenv isn't your particular cup of tea), you can override both methods in most cases. For example, to deploy without restarting Supervisor, run:

fab prod deploy:tag=YYYY-MM-DD-tag-description,supervisor_restart=False

Restarting processes

Restarting services remotely is made a bunch easier via Fabric, and included here is a remote supervisor-restart function:

fab env restart

Rolling back

Rolling back to a previously-deployed tag is something one must occasionally do if the impossible event of a bad deploy happens. No worries tho, it's easy!

fab env rollback:tag=YYYY-MM-DD-tag-description

About

This app was assembled by Mike Dory, based on Jeff Forcier's amazing Fabric library. Contributions/edits are always welcome, naturally.

About

A lil' tool for testing, deploying, and maintaining Django apps with Fabric and Supervisor.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%