Skip to content

Instantly share code, notes, and snippets.

@ohlol
Created January 10, 2012 21:16
Show Gist options
  • Save ohlol/1591251 to your computer and use it in GitHub Desktop.
Save ohlol/1591251 to your computer and use it in GitHub Desktop.
from fabric.api import *
import time
env.name = 'myapp'
env.python = 'python2.6'
env.time = int(time.time())
env.buildroot = '/tmp/%s/%d' % (env.name, env.time)
env.app = '%s/%s' % (env.buildroot, env.name)
env.deploy = '/usr/local/%s/releases' % env.name
env.hosts = ['foo.bar.com']
env.repo = 'git@github.com:foo/repo.git'
env.blob = '%s-%d.tgz' % (env.name, env.time)
def all():
mkvirtualenv()
prepare()
build()
deploy()
restart_daemon()
def deploy():
put('/tmp/%s' % env.blob, '/tmp')
with settings(hide('stdout')):
with cd(env.deploy):
run('mkdir %s' % env.time)
with cd('%s' % env.time):
run('tar xzf /tmp/%s' % env.blob)
run('rm -f current; ln -sf %s current' % env.time)
def build():
with settings(hide('stdout')):
with lcd(env.buildroot):
with prefix('. bin/activate'):
local('pip install -r %s/requirements.txt' % env.buildroot)
local('virtualenv --relocatable .')
local('perl -pi -e "s,%s,%s/current," bin/activate*' % (env.buildroot, env.deploy))
local('tar czf /tmp/%s .' % env.blob)
def mkvirtualenv():
with settings(hide('stdout')):
local('virtualenv --no-site-packages --setuptools --python %s %s' % (env.python, env.buildroot))
def prepare():
dirs = ['tmp', env.name]
with lcd(env.buildroot):
local('mkdir %s' % ' '.join(dirs))
with settings(hide('stdout')):
with lcd('tmp'):
with settings(hide('stderr')):
local('git clone %s %s' % (env.repo, env.name))
with lcd(env.name):
local('git archive master | tar -xC %s' % env.buildroot)
local('rm -rf %s' % env.name)
def restart_apache():
run('sv restart godzirra')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment