Create a gist now

Instantly share code, notes, and snippets.

@Eugeny /fabfile.py
Last active Aug 29, 2015

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('./manage.py 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('./manage.py 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