Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eugeny/10022524 to your computer and use it in GitHub Desktop.
Save Eugeny/10022524 to your computer and use it in GitHub Desktop.
Fabfile for Ajenti-V/Jenkins tutorial
import os
from fabric.api import *
from fabric.colors import cyan, yellow, green
from fabric.contrib.files import upload_template
py_deps = ' gcc libmysqlclient-dev libxml2-dev libpango1.0-dev libglib2.0-dev libcairo2-dev '
def localcfg():
env.hosts = ['localhost']
env.project = 'bucket'
env.ws_name = 'Bucket'
env.remote_path = '/srv/' + env.project
env.workspace = '/var/lib/jenkins/workspace/bucket'
env.python = env.workspace + '/env/bin/python'
env.env = 'prod'
env.user = 'root'
def make():
require('hosts', provided_by=[localcfg])
run('apt-get install -q -y ' + py_deps)
local('virtualenv env')
local('virtualenv --relocatable env')
with prefix('. env/bin/activate'):
local('pip install -r REQUIREMENTS')
print cyan('--- Generating assets')
local('./ collectstatic --noinput -v1 --settings=config.environments.%s' % env.env)
local('virtualenv --relocatable env')
print green('Build done')
def deploy():
require('hosts', provided_by=[localcfg])
put_dir(env.workspace, env.remote_path)
with cd(env.remote_path):
run('chown www-data: -R %s' % env.remote_path)
with prefix('. env/bin/activate'):
run('./ migrate --all --settings=config.environments.%s' % env.env)
print green('Deployment done')
def put_dir(local_dir, remote_dir):
local_tgz = "/tmp/fabtemp.tgz"
remote_tgz = os.path.basename(local_dir) + ".tgz"
local('tar -C "{0}" -czf "{1}" . --exclude-vcs'.format(local_dir, local_tgz))
put(local_tgz, remote_tgz)
local('rm -f "{0}"'.format(local_tgz))
run('rm -Rf "{0}"; mkdir "{0}"; tar -C "{0}" -xzf "{1}" && rm -f "{1}"'.format(remote_dir, remote_tgz))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment