forked from skylines-project/skylines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
112 lines (80 loc) · 2.44 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
from fabric.api import env, task, local, cd, lcd, run, sudo, put
from tempfile import NamedTemporaryFile
env.use_ssh_config = True
env.hosts = ['skylines@skylines']
APP_DIR = '/home/skylines'
SRC_DIR = '%s/src' % APP_DIR
@task
def deploy(branch='master', force=False):
build_ember()
upload_ember()
push(branch, force)
restart()
@task
def build_ember():
with lcd('ember'):
local('node_modules/.bin/ember build -prod -o dist/')
@task
def upload_ember():
with cd(SRC_DIR):
run('mkdir -p skylines/frontend/static/ember')
put('ember/dist/*', 'skylines/frontend/static/ember')
@task
def push(branch='HEAD', force=False):
cmd = 'git push %s:%s %s:master' % (env.host_string, SRC_DIR, branch)
if force:
cmd += ' --force'
local(cmd)
@task
def restart():
with cd(SRC_DIR):
run('git reset --hard')
# compile i18n .mo files
manage('babel compile')
# generate JS/CSS assets
manage('assets build')
# do database migrations
manage('migrate upgrade')
# restart services
restart_service('skylines-api')
restart_service('skylines')
restart_service('mapserver')
restart_service('tracking')
restart_service('celery')
restart_service('mapproxy')
@task
def restart_service(service):
# Using the sudo() command somehow always provokes a password prompt,
# even if NOPASSWD is specified in the sudoers file...
run('sudo supervisorctl restart %s' % service)
@task
def manage(cmd, user=None):
with cd(SRC_DIR):
if user:
sudo('./manage.py %s' % cmd, user=user)
else:
run('./manage.py %s' % cmd)
@task
def update_mapproxy():
with NamedTemporaryFile() as f:
content = open('mapserver/mapproxy/mapproxy.yaml').read()
content = content.replace(
'base_dir: \'/tmp/cache_data\'',
'base_dir: \'%s/cache/mapproxy\'' % APP_DIR,
)
content = content.replace(
'lock_dir: \'/tmp/cache_data/tile_locks\'',
'lock_dir: \'%s/cache/mapproxy/tile_locks\'' % APP_DIR,
)
f.write(content)
f.flush()
put(f.name, '%s/config/mapproxy.yaml' % APP_DIR)
@task
def pip_install():
with cd(SRC_DIR):
run('git reset --hard')
run('pip install -e .')
@task
def clean_mapproxy_cache():
with cd('/home/skylines/cache/mapproxy'):
run('rm -rv *')