Skip to content

Instantly share code, notes, and snippets.

Created August 16, 2012 00:10
Show Gist options
  • Save brianr/3364913 to your computer and use it in GitHub Desktop.
Save brianr/3364913 to your computer and use it in GitHub Desktop.
Simple deploy script with Fabric
import sys
from fabric.api import run, local, cd, env, roles, execute
import requests
env.roledefs = {
'web': ['web1', 'web2']
def deploy():
# pre-roll checks
# do the roll.
# execute() will call the passed-in function, honoring host/role decorators.
# post-roll tasks
def update_and_restart():
code_dir = '/home/deploy/www/mox'
with cd(code_dir):
run("git pull")
run("pip install -r requirements.txt")
run("supervisorctl restart web1")
run("supervisorctl restart web2")
def check_user():
if local('whoami', capture=True) != 'deploy':
print "This command should be run as deploy. Run like: sudo -u deploy fab deploy"
def ratchet_record_deploy():
# read access_token from production.ini
access_token = local("grep 'ratchet.access_token' production.ini | sed 's/^.* = //g'", capture=True)
environment = 'production'
local_username = local('whoami', capture=True)
revision = local('git log -n 1 --pretty=format:"%H"', capture=True)
resp ='', {
'access_token': access_token,
'environment': environment,
'local_username': local_username,
'revision': revision
}, timeout=3)
if resp.status_code == 200:
print "Deploy recorded successfully. Deploy id:", resp.json['data']['deploy_id']
print "Error recording deploy:", resp.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment