Skip to content

Instantly share code, notes, and snippets.

@mrchilds
Last active December 23, 2015 03:29
Show Gist options
  • Save mrchilds/6573907 to your computer and use it in GitHub Desktop.
Save mrchilds/6573907 to your computer and use it in GitHub Desktop.
Simple Fabric Script
# Deploy branch to staging
from fabric.api import cd, env, parallel, run, task
from fabric.decorators import roles
# Define your servers
env.roledefs = {
'staging-web-servers': ['s-web-01.example.com',
's-web-03.example.com',
's-web-03.example.com'],
'staging-db-servers': ['s-db-01.example.com'],
}
# Update servers at the same time, e.g. in parallel.
@parallel
@task
@roles('staging-web-servers', 'staging-db-servers')
def pull_code_onto_servers(branch):
# Path to your code
with cd():
# Update your code and pull your branch
run('git fetch')
run('git checkout remotes/origin/%s' % branch)
# Restart any relevant services
run("sudo supervisorctl restart gunicorn")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment