Skip to content

Instantly share code, notes, and snippets.

@datacodesolutions
Created December 4, 2012 02:53
Show Gist options
  • Select an option

  • Save datacodesolutions/4200113 to your computer and use it in GitHub Desktop.

Select an option

Save datacodesolutions/4200113 to your computer and use it in GitHub Desktop.
Fab Deploy
# 1. Install fabric: sudo pip install fabric
# 2. Use this file with the name of fabfile.py and place it in project root.
# 3. Execute deploy: fab staging deploy
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
env.key_filename = ["/path/to/ssh/key"]
path = ''
def staging():
global env, path
env.hosts = ['deploydomain.com']
env.user = 'remoteuser'
path = '/remote/path/to/repo'
local("git push bitbucket staging")
def master():
global env, path
env.hosts = ['deploydomain.com']
env.user = 'remoteuser'
path = '/remote/path/to/repo'
local("git push bitbucket master")
def deploy():
global env, path
commit_hash = local("git rev-parse HEAD", capture=True)
with cd(path):
run("git fetch bitbucket")
run("git reset --hard " + str(commit_hash))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment