Find file
Fetching contributors…
Cannot retrieve contributors at this time
100 lines (73 sloc) 2.63 KB
# Deployment for private server
# This is only an example for other installations
import os
import time
from fabric.api import task, env, sudo, cd, prefix, run
from fabric.utils import puts
from fabric.colors import yellow, green
env.hosts = [""]
env.remote_workdir = '/home/%s/virtualenvs/kirchenreich' % env.user
env.virtualenv_dir = env.remote_workdir + '/kr_env'
def in_rwd(path):
"""Complete relative path to full path on remote system"""
return os.path.join(env.remote_workdir, path)
env.source_dir = in_rwd('kirchenreich/')
env.requirements_file = in_rwd('kirchenreich/requirements.d/prod.txt')
def django_manage(*args):
"""Use the remote django"""
with cd(env.source_dir):
with prefix('source %s' % os.path.join(env.virtualenv_dir, 'bin/activate')):
args_string = ' '.join(args + ('',))
run('python ' + args_string)
def git_pull():
"""Pull the lastest source from master branch"""
puts(yellow("Pull master from GitHub"))
with cd(env.source_dir):
run('git reset --hard HEAD')
run('git pull')
def build_virtualenv():
"""Install the dependencies from requirements file and link project
package into virtualenv"""
puts(yellow("Install dependencies from requirements.txt"))
with cd(env.source_dir):
with prefix('source %s' % in_rwd('bin/activate')):
sudo('pip install -r %s' % env.requirements_file,
sudo('python develop', user=env.app_user)
def collectstatic():
"""Collect the statics and link this into the static path"""
puts(yellow("Collect statics"))
django_manage('collectstatic', '-l', '--noinput')
def migrate():
"""Run the South migrations"""
puts(yellow("Run South migrations"))
def reload_gunicorn():
"""Reload the gunicorn graceful"""
puts(yellow("Reload gunicorn graceful"))
sudo('kill -HUP `cat %s`' % (env.gunicorn_pidpath), user=env.app_user)
def restart_celery():
"""Restart the celery worker"""
puts(yellow("Restart celery worker"))
with prefix('source %s' % in_rwd('bin/activate')):
sudo('supervisorctl restart celery-worker', user=env.app_user)
sudo('supervisorctl status', user=env.app_user)
def deploy():
"""Get source and update virtualenv, statics and run South migrations"""
# build_virtualenv()
# collectstatic()
# reload_gunicorn()
# restart_celery()
puts(green("Deployment done!"))