-
Notifications
You must be signed in to change notification settings - Fork 11
/
fabfile.py
154 lines (113 loc) · 4.14 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
from fabric.api import local
def ssh(service):
"""
ssh into running service container
:param service: ['prp_backend', 'polymer', 'proxy', 'db', 'id-management-frontend']
"""
assert service in ['prp_backend', 'polymer', 'proxy', 'db', 'id-management-frontend'], "%s is unrecognized service"
if service == 'polymer':
local('docker-compose exec polymer ash')
else:
local('docker-compose exec %s bash' % service)
def up_recreate():
"""
Recreate containers even if their configuration and image haven't changed.
"""
local('docker-compose stop && docker-compose up')
def up(rebuild=False):
"""
Create and start containers.
"""
if rebuild:
command = 'docker-compose up --force-recreate --build'
else:
command = 'docker-compose up'
local(command)
def up_with_bundle(rebuild=True):
"""
Create and start containers with polymer bundle served.
"""
local('docker-compose -f docker-compose.polymer-bundle.yml up %s' % '' if rebuild else '--build')
def restart(service):
"""
restart a service container
:param service: ['prp_backend', 'polymer', 'proxy', 'db', 'id-management-frontend']
"""
assert service in ['prp_backend', 'polymer', 'proxy', 'db', 'beater-prp', 'worker-prp', 'id-management-frontend'], "%s is unrecognized service"
local('docker-compose restart %s' % service)
def down():
"""
Destroy all containers with volumes.
"""
local('docker-compose down')
def rebuild(service):
"""
Re-build docker images for containers.
"""
if service:
assert service in ['prp_backend', 'polymer', 'proxy', 'db', 'id-management-frontend'], "%s is unrecognized service"
local('docker-compose build %s' % service if service else '')
def ps():
"""
Display all containers.
"""
local('docker-compose ps')
def kill():
"""
Kill all containers.
"""
local('docker-compose kill')
def stop(service):
"""
Stop service(s).
"""
if service == 'all':
local('docker-compose stop')
elif service:
assert service in ['prp_backend', 'polymer', 'proxy', 'db', 'id-management-frontend'], "%s is unrecognized service"
local('docker-compose stop %s' % service)
def fixtures():
"""
Load fixture data for Site and ReportingEntities.
"""
local('docker-compose exec prp_backend python manage.py loaddata sites')
local('docker-compose exec prp_backend python manage.py loaddata reporting_entities')
local('docker-compose exec prp_backend python manage.py loaddata periodic_tasks')
def fake_data(quantity=1):
"""
Load example data from generate_fake_data management command.
"""
local('docker-compose exec prp_backend python manage.py generate_fake_data --quantity %d --clean_before' % (int(quantity)))
def real_data(area=False):
"""
Destroy current DB data and uses real sync with PMP API to get all data.
"""
local('docker-compose exec prp_backend python manage.py generate_real_data --clean_before %s' % ("--area %s --fast" % area if area else ""))
def generate_reports():
"""
Generate reports based on current data
"""
local('docker-compose exec prp_backend python manage.py generate_reports')
def sync_ocha_partners(area=False):
"""
Generate reports based on current data
"""
local('docker-compose exec prp_backend python manage.py sync_ocha_partners %s' % ("--country %s" % area if area else ""))
def tests(test_path=''):
"""
Run backend tests.
"""
local('docker-compose exec prp_backend python manage.py test {} --settings=etools_prp.config.settings.test --parallel --noinput'.format(test_path))
def update_real_fixtures(area=False):
"""
Uses real sync with PMP API to update data.
"""
local('docker-compose exec prp_backend python manage.py generate_real_data %s --update' % ("--area %s --fast" % area if area else ""))
def backend_lint():
"""
Run python code linter
"""
local('docker-compose exec prp_backend flake8 ./ --count')
def preview_uwsgi_log():
cmd = 'docker-compose exec prp_backend tail -f /var/log/uwsgi_global.log'
local(cmd)