-
Notifications
You must be signed in to change notification settings - Fork 2
/
fabfile.py
132 lines (84 loc) · 2.15 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
import time
from invoke import run, task
# HELPER FUNCTIONS ###
def _api_cmd(cmd):
return "docker exec -it api_service %s" % cmd
def local(command):
run(command, pty=True)
# FABRIC COMMANDS ###
def create_version_file():
local("./ci_cd/version.sh")
@task
def build(c):
create_version_file()
local("docker-compose build")
@task(aliases=["build-nocache"])
def buildnocache(c):
create_version_file()
local("docker-compose build --no-cache --pull")
@task
def up(c):
"""Note: api_db takes a minute or more to init."""
local("docker-compose up -d")
@task
def down(c):
local("docker-compose down")
@task
def downnocache(c):
local("docker-compose down -v")
@task
def runserver(c):
local(_api_cmd("python manage.py runserver 0.0.0.0:8080"))
@task
def runserverplus(c):
local(_api_cmd("gunicorn --reload -c runserverplus.conf app.wsgi:application"))
@task
def makemigrations(c):
local(_api_cmd("python manage.py makemigrations"))
@task
def migrate(c):
local(_api_cmd("python manage.py migrate"))
@task
def shell(c):
local("docker exec -it api_service /bin/bash")
@task
def dbshell(c):
local(_api_cmd("python manage.py dbshell"))
@task
def shellplus(c):
local(_api_cmd("python manage.py shell_plus"))
@task
def lint(c):
local(_api_cmd("pylint --load-plugins pylint_django api"))
@task
def test(c):
local(
"docker exec -it api_service pytest --nomigrations --cov-report=html --cov=api --verbose api/tests"
)
@task
def dbrestore(c, keyname="local"):
"""Restore the database from a named s3 key
ie - fab dbrestore --keyname dev
"""
local(_api_cmd("python manage.py dbrestore {}".format(keyname)))
@task
def dbbackup(c, keyname="local"):
"""Backup the database from a named s3 key
ie - fab dbbackup --keyname dev
"""
local(_api_cmd("python manage.py dbbackup {}".format(keyname)))
@task
def install(c, keyname="local"):
down(c)
buildnocache(c)
up(c)
time.sleep(20)
migrate(c)
@task
def freshinstall(c, keyname="local"):
downnocache(c)
buildnocache(c)
up(c)
time.sleep(20)
dbrestore(c, keyname)
migrate(c)