Last active
June 23, 2016 09:22
-
-
Save mermoldy/d38e2a6bc181f9142205206906269b24 to your computer and use it in GitHub Desktop.
fabric deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import os | |
from fabric.api import run, env, cd, roles, task | |
env.roledefs['prod'] = ['myuser@host'] | |
env.roledefs['staging'] = ['myuser@host'] | |
def prod_env(): | |
env.key_filename = [os.path.join(os.environ['HOME'], '.ssh', 'id_rsa.pub')] | |
env.user = 'myuser' | |
env.project_root = '/home/myuser/myproject' | |
env.shell = '/bin/bash -c' | |
env.python = '/home/myuser/.virtualenvs/myproject/bin/python' | |
env.pip = '/home/myuser/.virtualenvs/myproject/bin/pip' | |
env.requirements = os.path.join(env.project_root, 'requirements.txt'); | |
def stagging_env(): | |
# ... | |
def deploy_prod(): | |
prod_env() | |
with cd(env.project_root): | |
run('git pull origin master') | |
run('{pip} install --upgrade -r {requirements}'.format(pip=env.pip, | |
requirements=env.requirements)) | |
run('{} manage.py migrate'.format(env.python)) | |
run("sudo supervisorctl restart myproject") | |
def deploy_stagging(): | |
# ... | |
@task | |
def deploy(): | |
if 'staging' in env.roles: | |
deploy_stagging() | |
elif 'prod' in env.roles: | |
deploy_prod() | |
else: | |
raise ValueError('No valid role specified!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment