Find file
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (60 sloc) 2.56 KB
import os
import datetime
from fabric.api import put, task, local, run, cd, env
if 'CALEBCC_DEPLOY_HOST' in os.environ:
env.hosts = [os.environ['CALEBCC_DEPLOY_HOST']]
if 'CALEBBC_SSH_KEY_FILE' in os.environ:
env.key_filename = os.environ['CALEBBC_SSH_KEY_FILE']
remote_dir = '~/webapps/calebcc_bottle'
remote_static_dir = '~/webapps/calebcc_static'
repo_url = ''
def init_env():
with cd(remote_dir):
run('mkdir cache')
run('mkdir versions')
run('git clone %s cache/calebcc_site' % repo_url)
def update_cache():
with cd(os.path.join(remote_dir, 'cache/calebcc_site')):
run('git pull -u')
def prepare(version=None, version_timestamp=None):
if not version_timestamp:
version_timestamp ='%s')
# copy the source code
with cd(os.path.join(remote_dir, 'versions')):
run('git clone %s %s' % (os.path.join(remote_dir, 'cache/calebcc_site'), version_timestamp))
# create the version file
version_tmp_file = '/tmp/' % version_timestamp
fd = open(version_tmp_file, 'w+')
fd.write('DEPLOY_VERSION = "%s"\n' % version_timestamp)
put(version_tmp_file, os.path.join(remote_dir, 'versions', version_timestamp, 'calebcc', ''))
local('rm %s' % version_tmp_file)
with cd(os.path.join(remote_dir, 'versions', version_timestamp)):
run('virtualenv --python=python2.7 --distribute --no-site-packages env')
run('pip install -E env -r requirements.txt')
run('env/bin/python -m compileall -q .')
run('ln -sfn %s %s' % (os.path.join(remote_dir, 'versions', version_timestamp, 'calebcc', 'static'), os.path.join(remote_static_dir, version_timestamp)))
run('ln -sfn %s %s' % (os.path.join(remote_dir, 'site_data/media'), os.path.join(remote_static_dir, 'media')))
def apache_restart():
with cd(os.path.join(remote_dir)):
def clean_old_releases():
with cd(os.path.join(remote_dir, 'versions')):
run('ls -1td * | tail -n +6 | xargs rm -r')
with cd(os.path.join(remote_static_dir)):
run('ls -1td * | tail -n +6 | xargs rm -r')
def deploy(version=None):
version_timestamp ='%s')
# move the symlink
with cd(os.path.join(remote_dir)):
run('ln -sfn %s project' % os.path.join(remote_dir, 'versions', version_timestamp))