forked from torchbox/vagrant-django-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
88 lines (71 loc) · 2.78 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from fabric.api import cd, env, run, sudo, task, execute
from fabtools.vagrant import vagrant
from fabtools import require
import fabtools
import fabric
from fabric.contrib.files import exists, append, comment, contains
from fabric.contrib.console import confirm
from fabric.colors import blue, cyan, green, red, blue
from datetime import datetime
import os
PROJECT_NAME = "{{ project_name }}"
@task
def default():
'''
Sets up the default env variables
'''
env.base_path = '/var/www/{{ project_name }}/{{ project_name }}'
env.virtualenv_path = '/var/www/{{ project_name }}'
env.db_name = '{{ project_name }}'
default()
@task
def staging():
'''
Sets up the staging env variables
'''
#env.hosts = [staging_host,]
#env.deploy_user = 'deploy_user'
pass
@task
def live():
'''
Sets up live env variables
'''
#env.hosts = [web1, web2]
pass
@task
def devserver(settings_file="{{ project_name }}.settings"):
'''
Start the development server
'''
with fabtools.python.virtualenv(env.virtualenv_path), cd(env.base_path):
run('python manage.py runserver 0.0.0.0:8000 --settings=%(settings_file)s' % locals())
@task
def circus():
with fabtools.python.virtualenv(env.virtualenv_path), cd(env.base_path):
run('circusd circus.ini')
@task
def deploy(commit_hash=None):
commit_hash = commit_hash or get_current_commit()
with cd(env.base_path), fabtools.python.virtualenv(env.virtualenv_path):
sudo('git fetch', user=env.deploy_user)
sudo('git reset --hard %(commit_hash)s' % locals(), user=env.deploy_user)
venv_path = env.virtualenv_path
proj_path = env.base_path
suffix = env.settings_suffix or "dev"
settings_file = "{{ project_name }}.settings.%(suffix)s" % locals()
sudo('%(venv_path)s/bin/pip install -r %(proj_path)s/requirements.txt' % locals(), user=env.deploy_user)
sudo('%(venv_path)s/bin/python %(proj_path)s/manage.py migrate --settings=%(settings_file)s' % locals(), user=env.deploy_user)
sudo('%(venv_path)s/bin/python %(proj_path)s/manage.py collectstatic --noinput --settings=%(settings_file)s' % locals(), user=env.deploy_user)
with settings(warn_only=True):
sudo('%(venv_path)s/bin/python %(proj_path)s/manage.py compress --settings=%(settings_file)s' % locals(), user=env.deploy_user)
if env.reset_command:
sudo(env.reset_command, user=env.deploy_user)
with settings(warn_only=True):
sudo('%(venv_path)s/bin/python %(proj_path)s/manage.py register_deploy %(commit_hash)s --settings=%(settings_file)s' % locals(), user=env.deploy_user)
@task
def switch():
pass
## ----- utilities ----- ##
def get_current_commit():
return local("git log -n 1 --format=%H", capture=True)