Created
November 6, 2012 02:19
-
-
Save crosbymichael/4022139 to your computer and use it in GitHub Desktop.
Fab deployment
This file contains 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
#!/usr/bin/env python | |
from fabric.api import * | |
from datetime import datetime as dt | |
""" | |
Deployment Fabric File for codeassistant-django | |
""" | |
env.hosts = ['192.168.1.21'] | |
env.user = 'backend' | |
def deploy(): | |
""" Deploy the site to the production servers """ | |
test() | |
backup() | |
fetch() | |
install_requirements() | |
upload_config() | |
migrate() | |
restart() | |
def test(): | |
""" Run the unit test suite locally """ | |
local('./manage.py test') | |
def runserver(): | |
local('./manage.py runserver 8000') | |
def restart(): | |
""" Restart Lighttpd on the server """ | |
run('sudo /etc/init.d/lighttpd restart') | |
def syncdb(): | |
with cd('~/www/'): | |
run('./prod_manage.py syncdb') | |
def migrate(): | |
with cd('~/www/'): | |
run('./prod_manage.py migrate') | |
def _backup_postgres(): | |
pass | |
def fetch(): | |
with cd('~/www/'): | |
run('git fetch --all') | |
run('git reset --hard origin/master') | |
run('chmod +x private-requirements.sh') | |
run('chmod +x prod_manage.py') | |
run('chmod +x index.fcgi') | |
def backup(): | |
""" Backup the web and virtual environment """ | |
d = dt.now().strftime('%m-%d-%Y') | |
print 'Backing up web directory...' | |
run('tar -zcvf backup-www-%s.tar.gz www/' % (d)) | |
print 'Backing up virtual environment...' | |
run('tar -zcvf backup-env-%s.tar.gz .env/cadjango/' % (d)) | |
def install_requirements(): | |
with cd('~/www/'): | |
run('~/.env/cadjango/bin/pip install -r ~/www/prod-requirements.txt') | |
run('./private-requirements.sh') | |
def upload_config(): | |
put('~/.cmtask.cfg', '~/.cmtask.cfg') | |
def clean(): | |
local('find . -name "*.pyc" -delete') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment