|
|
@@ -0,0 +1,97 @@ |
|
|
from __future__ import with_statement |
|
|
from fabric.api import * |
|
|
from fabric.operations import get |
|
|
from fabric.contrib.files import exists |
|
|
from contextlib import contextmanager |
|
|
import os |
|
|
|
|
|
|
|
|
env.roledefs = { |
|
|
'web': ['server1.example.com', 'server2.example.com'], |
|
|
'db': ['server1.example.com'], |
|
|
} |
|
|
|
|
|
|
|
|
env.project_name = 'project_name' |
|
|
env.supervisor_app_name = 'project_name' |
|
|
env.git_url = '[email protected]:example/project_name.git' |
|
|
env.user = 'ubuntu' |
|
|
env.apps_path = '/home/ubuntu/' |
|
|
env.directory = '/home/ubuntu/project_name' |
|
|
env.activate = 'source /home/ubuntu/.virtualenvs/project_name/bin/activate' |
|
|
env.do_collectstatic = False |
|
|
env.django_settings_module = 'project_name.settings.prod' |
|
|
|
|
|
|
|
|
@contextmanager |
|
|
@roles('web') |
|
|
def virtualenv(): |
|
|
with settings(sudo_user=env.user): |
|
|
with cd(env.directory): |
|
|
with prefix(env.activate): |
|
|
puts('Activated virtualenv') |
|
|
yield |
|
|
|
|
|
@roles('web') |
|
|
def with_static(): |
|
|
env.do_collectstatic = True |
|
|
|
|
|
@roles('web') |
|
|
def uptime(): |
|
|
with virtualenv(): |
|
|
run('uptime') |
|
|
|
|
|
@roles('web') |
|
|
def git_pull(): |
|
|
with virtualenv(): |
|
|
run('git pull') |
|
|
|
|
|
@roles('web') |
|
|
def pip_install(): |
|
|
with virtualenv(): |
|
|
run('pip install -r requirements.txt') |
|
|
|
|
|
@roles('db') |
|
|
def syncdb(): |
|
|
with virtualenv(): |
|
|
run('python manage.py migrate') |
|
|
|
|
|
@roles('web') |
|
|
def collectstatic(): |
|
|
with virtualenv(): |
|
|
run('pwd') |
|
|
run('python manage.py collectstatic --noinput') |
|
|
|
|
|
@roles('web') |
|
|
def restart_app(): |
|
|
sudo('supervisorctl restart %s' % env.supervisor_app_name) |
|
|
|
|
|
@roles('web') |
|
|
def nginx_reload(): |
|
|
sudo('service nginx reload') |
|
|
|
|
|
|
|
|
@roles('db') |
|
|
def manage(arguments): |
|
|
with virtualenv(): |
|
|
run('python manage.py %s' % arguments) |
|
|
|
|
|
|
|
|
@roles('web') |
|
|
def deploy(): |
|
|
git_pull() |
|
|
pip_install() |
|
|
syncdb() |
|
|
if env.do_collectstatic: |
|
|
collectstatic() |
|
|
restart_app() |
|
|
|
|
|
@roles('db') |
|
|
def dump(arguments='latest.dump'): |
|
|
# this uses a management command called 'dbdump' |
|
|
# something similar to this package https://github.com/vitaliyf/django-dbdump |
|
|
# many more exist |
|
|
with virtualenv(): |
|
|
run('python manage.py dbdump %s' % arguments) |
|
|
get('latest.dump', arguments) |
|
|
|