-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfabfile.py
48 lines (38 loc) · 1.26 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
from fabric.api import *
try:
import fabric_settings
except ImportError:
print("Please create a fabric_settings.py file in order to use fab.")
exit(1)
def run_within_virtual_env(command):
with cd(env.project_root):
if env.virtual_env_name != '':
command_prefix = 'workon %s && ' % env.virtual_env_name
else:
command_prefix = ''
run(command_prefix + command)
def run_manage(command):
run_within_virtual_env('python manage.py %s' % command)
def deploy_static_files():
run_manage('collectstatic -v0 --noinput')
def deploy_code():
with settings(warn_only=True):
if run('test -d %s' % env.project_root).failed:
run('git clone %s %s' % (env.repository_url, env.project_root))
with cd(env.project_root):
run('git checkout %s' % env.deploy_branch)
run('git pull origin %s' % env.deploy_branch)
def install_dependencies():
run_within_virtual_env('pip install -r requirements.txt')
def run_migrations():
run_manage('syncdb')
run_manage('migrate')
def restart_app_server():
with cd(env.project_root):
run('touch app.wsgi')
def deploy():
deploy_code()
install_dependencies()
deploy_static_files()
run_migrations()
restart_app_server()