forked from unicef/etools-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
142 lines (104 loc) · 4.25 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
import platform
from fabric.api import local, settings
from fabric.context_managers import shell_env, lcd
APP_SUBMODULE_DIRECTORIES = (
'dashboard',
'pmp',
'travel',
'ap',
'apd',
'tpm',
)
def ssh(service):
# https://stackoverflow.com/a/25293275/8207
class NoBashException(Exception):
pass
with settings(abort_exception=NoBashException):
try:
local('docker exec -it etoolsinfra_%s /bin/bash' % service)
except NoBashException:
# fallback in case bash isn't installed
local('docker exec -it etoolsinfra_%s /bin/sh' % service)
def reallyclean():
local('docker-compose down --rmi all --volumes')
local('docker volume rm $(docker volume ls -qf dangling=true)')
def devup(quick=False, DB_PORT="51322"):
with shell_env(DB_PORT=DB_PORT):
local('docker-compose up --force-recreate %s' % ('--build' if not quick else ''))
def devup_built(quick=False, DB_PORT="51322"):
nginx_config = " -c '/nginx-built.conf'"
front_end_command = "node express.js"
with shell_env(NX_CONFIG=nginx_config, FE_COMMAND=front_end_command, DB_PORT=DB_PORT):
local('docker-compose up --force-recreate %s' % ('--build' if not quick else ''))
def devup_built_windows(quick=False):
local('docker-compose -f docker-compose.dev-built-win.yml up --force-recreate %s' % ('--build' if not quick else ''))
def backend_migrations():
local('docker exec etoolsinfra_backend python /code/manage.py migrate_schemas --noinput')
def debug(quick=False, DEBUG_PORT='51312', DB_PORT="51322"):
try:
import netifaces as ni
except ImportError:
print("You must have the 'netifaces' package installed")
return
ni.ifaddresses('en0')
ip = ni.ifaddresses('en0')[2][0]['addr']
with shell_env(BACKEND_DEBUG="_debug", DEBUG_IP=ip, DEBUG_PORT=DEBUG_PORT, DB_PORT=DB_PORT):
local('docker-compose up --force-recreate %s' % ('--build' if not quick else ''))
def remove_docker_containers():
local('docker stop $(docker ps -q)')
local('docker rm $(docker ps -q)')
def stop_docker_containers():
local('docker stop $(docker ps -q)')
def up(quick=False):
local('docker-compose -f docker-compose.yml up --force-recreate')
def _frontend_deps_init():
# TODO retry after timeouts
for frontend_app_dir in APP_SUBMODULE_DIRECTORIES:
with lcd(frontend_app_dir):
local('npm install')
local('bower install')
def _frontend_deps_update():
# TODO retry after timeouts
for frontend_app_dir in APP_SUBMODULE_DIRECTORIES:
with lcd(frontend_app_dir):
local('npm update')
local('bower update')
def _update_submodules():
# TODO retry after timeouts
# see https://stackoverflow.com/a/18799234/8207 for more information about submodule branch tracking
local('git submodule update --init --recursive --remote')
local(
'git submodule foreach -q --recursive \'branch="$(git config -f $toplevel/.gitmodules submodule.$name.branch)";'
'git checkout $branch; git merge origin/$branch\''
)
def update(quick=False):
local('git fetch --all')
# TODO should we use `develop` on unicef/etools-infra rather than `master`?
local('git checkout master')
local('git merge origin/master')
_update_submodules()
# delete .pyc files - something creates some of them as root, sigh...
local("sudo find . -name '*.pyc' -delete")
if not quick:
_frontend_deps_update()
def init():
local('git fetch --all')
_update_submodules()
_frontend_deps_init()
if platform.system() == 'Darwin':
# TODO complain if postgres and/or GDAL are not installed
pass
if platform.system() == 'Linux':
# TODO complain if postgres and/or GDAL are not installed
pass
if platform.system() == 'Windows':
# TODO complain if postgres and/or GDAL are not installed
pass
def test(app=None):
# TODO add flag so caller can indicate --keepdb vs --noinput
if app is not None:
local('docker exec etoolsinfra_backend python'
' /code/core/manage.py test %s.tests --keepdb' % app)
else:
local('docker exec etoolsinfra_backend python'
' /code/core/manage.py test --keepdb')