-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·233 lines (212 loc) · 5.36 KB
/
manage.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/python3
import argparse
import os
import sys
from sys import exit as x
from py.colours import Colours
from py.dcompose import DCompose
from py.profile import Profile
from py.runner import Runner
from py.snapshots import Snapshots
from py.util import pprint
parser = argparse.ArgumentParser(
description=os.path.basename(__file__).title()
+ ": "
+ "dq-dev, daiquiri docker compose dev setup",
epilog="If used without arg, profile list is displayed\n",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"-b",
"--build",
type=str,
nargs="*",
default=None,
help="build a profile's containers, exit when done",
)
parser.add_argument(
"-bnc",
"--build_no_cache",
type=str,
nargs="*",
default=None,
help="build a profile's containers without using cache, exit when done",
)
parser.add_argument(
"-r",
"--run",
type=str,
nargs="*",
default=None,
help="run a profile's containers, build if necessary",
)
parser.add_argument(
"-p",
"--stop",
type=str,
nargs="*",
default=None,
help="stop profile's running containers",
)
parser.add_argument(
"-d",
"--down",
type=str,
nargs="*",
default=None,
help=(
"stop and remove profile's running containers, "
+ "remove docker's volumes, keep folders containing the "
+ "volume data, they can be reused on next run"
),
)
parser.add_argument(
"-rmi",
"--remove_images",
action="store_true",
default=False,
help='remove images when running "down", use in combination "-d -rmi"\n\n',
)
parser.add_argument(
"-rmn",
"--remove_network",
action="store_true",
default=False,
help="remove daiquiri containers' network",
)
parser.add_argument(
"-g",
"--tail_logs",
type=str,
nargs="*",
default=None,
help="tail docker compose logs\n\n",
)
parser.add_argument(
"-c",
"--create_profile",
type=str,
default=None,
help="create a new profile with the default settings",
)
parser.add_argument(
"-s",
"--set_profile",
type=str,
default=None,
help="set profile to active"
)
parser.add_argument(
"-e",
"--render",
type=str,
nargs="*",
default=None,
help="only render docker-compose.yaml for profile",
)
parser.add_argument(
"-a",
"--display_profile",
type=str,
nargs="*",
default=None,
help="display currently active profile",
)
parser.add_argument(
"--list_snapshots",
action="store_true",
default=False,
help="list currently saved snapshots",
)
parser.add_argument(
"--save_snapshot",
type=str,
nargs="*",
default=None,
help="save current db and config to snapshot",
)
parser.add_argument(
"--restore_snapshot",
type=str,
nargs="*",
default=None,
help="restore saved snapshot",
)
parser.add_argument(
"-n",
"--dry_run",
action="store_true",
default=False,
help=(
"do not run any docker-compose commands nor "
+ "save rendered docker-compose.yaml, just print them"
),
)
args = parser.parse_args()
if __name__ == "__main__":
col = Colours()
prof = Profile(args)
conf = prof.conf
dco = DCompose(conf, prof)
snap = Snapshots(conf)
if args.create_profile is not None:
prof.create(args.create_profile)
x()
if args.set_profile is not None:
prof.set(args.set_profile)
x()
if not prof.exists:
print(
col.red("There is no active profile!\n\n") +
col.gre("Please activate a profile with \n") +
col.gre(" python manage.py -s <profile_name>\n") +
col.gre("or, first, create a new profile with\n") +
col.gre(" python manage.py -c <profile_name>\n") +
col.gre("and then activate it.")
)
if len(sys.argv) <=1 or not prof.is_active():
prof.list()
x()
if args.display_profile is not None:
c = prof.read_profile_config(conf["args"]["display_profile"])
print("Currently set profile", col.yel(c["name"]))
pprint(c)
if args.render is not None:
dco.render_dc_yaml(conf["args"]["render"])
dco.render_dockerfile_templates()
if args.build is not None:
dco.render_dc_yaml(conf["args"]["run"])
dco.render_dockerfile_templates()
run = Runner(conf)
run.build()
if args.build_no_cache is not None:
dco.render_dc_yaml(conf["args"]["run"])
dco.render_dockerfile_templates()
run = Runner(conf)
run.build_no_cache()
if args.run is not None:
dco.render_dc_yaml(conf["args"]["run"])
dco.render_dockerfile_templates()
run = Runner(conf)
run.start()
if args.stop is not None:
run = Runner(conf)
run.stop()
if args.down is not None:
run = Runner(conf)
run.down()
if conf["args"]["tail_logs"] is True:
run = Runner(conf)
run.tail_logs()
if args.remove_images is True:
run = Runner(conf)
run.remove_images()
if args.remove_network is True:
run = Runner(conf)
run.remove_network()
if args.list_snapshots is True:
snap.list_snapshots()
if conf["args"]["save_snapshot"] is not None:
snap.save_snapshot()
if conf["args"]["restore_snapshot"] is not None:
snap.restore_snapshot()