-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfabfile.py
More file actions
88 lines (68 loc) · 2.27 KB
/
fabfile.py
File metadata and controls
88 lines (68 loc) · 2.27 KB
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 __future__ import unicode_literals
from fabric.api import local
from fabric.context_managers import shell_env
def ssh(service):
"""
ssh into running service container
:param service: ['backend', 'frontend', 'proxy', 'db']
"""
assert service in ['backend', 'frontend', 'proxy', 'db'], "%s is unrecognized service"
local('docker-compose exec %s bash' % service)
def managepy(command=''):
"""
Run specified manage.py command
"""
cmd = 'docker-compose exec backend python manage.py {}'.format(command)
local(cmd)
def fakedata(clean_before=True):
"""
Create mock data for the django backend.
"""
cmd = 'docker-compose exec backend python manage.py fakedata'
if clean_before:
cmd += ' --clean_before'
local(cmd)
def reset_db():
"""
Reset db, migrate and generate fixtures.
Useful when changing branch with different migrations.
"""
local('docker-compose exec backend python manage.py reset_db')
local('docker-compose exec backend python manage.py migrate')
local('docker-compose exec backend python manage.py loaddata --app common initial.json')
local('docker-compose exec backend python manage.py loaddata --app agency initial.json')
fakedata(clean_before=False)
def tests(test_path=''):
"""
Run unit tests.
"""
local('docker-compose exec backend python manage.py test {} --parallel --noinput'.format(test_path))
def remove_untagged_images():
"""
Delete all untagged (<none>) images
"""
local('docker rmi $(docker images | grep "^<none>" | awk "{print $3}")')
def lint():
"""
Run python code linter
"""
local('docker-compose exec backend flake8 ./ --count')
def clean_pyc():
"""
Cleanup pyc files
"""
local('docker-compose exec backend find . -name \'*.pyc\' -delete')
def compose():
with shell_env(DOCKER_CLIENT_TIMEOUT='300', COMPOSE_HTTP_TIMEOUT='300'):
local(
'docker-compose stop '
'&& '
'docker-compose up --build --abort-on-container-exit --remove-orphans'
)
def restart():
with shell_env(DOCKER_CLIENT_TIMEOUT='300', COMPOSE_HTTP_TIMEOUT='300'):
local(
'docker-compose stop '
'&& '
'docker-compose up'
)