-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
113 lines (75 loc) · 2.48 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from ConfigParser import RawConfigParser
from fabric.api import cd, env, run, shell_env
from fabric.colors import green
from fabric.contrib.files import exists
from fabric.utils import puts
config = RawConfigParser()
with open('deploy/config.ini') as f:
config.readfp(f)
env.host_string = config.get('fabric_env', 'host_string')
env.project_name = config.get('fabric_env', 'project_name')
env.project_db_name = env.project_name
env.project_home = config.get('fabric_env', 'project_home')
env.project_root_dirname = config.get('fabric_env', 'project_root_dirname')
env.project_root = '{0.project_home}/{0.project_root_dirname}'.format(env)
env.virtualenv_home = config.get('fabric_env', 'virtualenv_home')
env.virtualenv_root = '{0.virtualenv_home}/{0.project_name}'.format(env)
env.virtualenv_activate_command = 'source {.virtualenv_root}/bin/activate'.format(env)
env.site_down_file = '.down'
env.touch_reload_file = '.reload'
env.git_repository = config.get('fabric_env', 'git_repository')
def prun(command):
"""
Runs command from project root directoy.
"""
with cd(env.project_root), shell_env(WORKON_HOME=env.virtualenv_home):
run(command)
def make(target):
"""
Invokes Makefile target.
"""
prun('make {}'.format(target))
def supervisorctl(action, program='', options=''):
run('supervisorctl {0} {1} {2}'.format(action, options, program))
def site_down():
prun('touch {}'.format(env.site_down_file))
puts(green('Site is down for maintenance'))
def site_up():
prun('rm {}'.format(env.site_down_file))
puts(green('Site is up and running'))
def touch_reload():
"""
uWSGI touch reload
"""
prun('touch {}'.format(env.touch_reload_file))
def git_clone():
with cd(env.project_home):
if exists(env.project_root_dirname):
run('rm -rf {.project_root_dirname}'.format(env))
run('git clone -q {0.git_repository} {0.project_root_dirname}'.format(env))
def git_pull():
prun('git pull -q')
def bootstrap():
"""
Bootstraps project for the first time.
"""
git_clone()
make('bootstrap')
make('settings_production')
make('requirements')
make('db_production')
make('collectstatic')
def deploy():
"""
Deploys updated project.
"""
site_down()
git_pull()
make('requirements')
make('syncdb')
make('migrate')
make('seed_production')
make('collectstatic')
touch_reload()
supervisorctl('restart', 'celery')
site_up()