This repository was archived by the owner on Jul 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdev
executable file
·409 lines (339 loc) · 8.13 KB
/
dev
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#!/usr/bin/env bash
function check_command {
local command=$1
command ${command} >/dev/null 2>&1
if [ "$?" != "0" ]; then
echo "⨯ ${command} not found"
echo "Please install ${command}!"
exit 1
fi
echo "✓ ${command} found"
}
function check_requirements {
check_command "docker"
check_command "mutagen"
}
function startup {
echo "Starting stack. This might take a while on the first run."
docker network create dealog_dev
mutagen project start || mutagen project resume
}
function attach_to_web {
echo "Attaching to the application container. Use Ctrl+p Ctrl+q to leave."
docker attach backoffice_web_1
}
function tail_logs {
docker-compose logs --follow
}
function shutdown {
echo "Shutting down..."
mutagen project pause
echo "done"
}
function run_start {
check_requirements
startup
attach_to_web
}
function run_stop {
shutdown
}
function run_rebuild {
mutagen project terminate
}
function run_clean {
mutagen project terminate
rm -fr _build deps assets/node_modules
docker-compose down --rmi=all --volumes
}
function run_update {
git fetch --prune
git merge --ff origin/main
}
function run_iex {
local command="iex -S mix $@"
run_command web ${command}
}
function run_mix {
local command="mix $@"
run_detached_command web ${command}
}
function run_update_translations {
run_command web "mix do gettext.extract, gettext.merge priv/translations/web --locale de, gettext.merge priv/translations/mail --locale de"
echo "Extracted and updated translation strings. Please translate."
}
function run_tests {
run_test_env_reset
local command="mix test $@"
run_detached_command web ${command}
}
function run_test_env_reset {
local command="MIX_ENV=test mix do event_store.reset, ecto.reset"
run_detached_command web ${command}
}
function run_tests_in_watch_mode {
run_test_env_reset
local command="mix test.watch $@"
run_detached_command web ${command}
}
function run_yarn {
local command="cd assets && yarn $@"
run_detached_command web ${command}
}
function run_build_production {
local command="cd assets && yarn deploy && cd .. && mix phx.digest"
run_command web ${command}
}
function run_command {
local container_name=${1}
local command="${@:2}"
docker-compose exec ${container_name} bash -c "${command}"
}
function run_detached_command {
local container_name=${1}
local command="${@:2}"
docker-compose run --rm ${container_name} bash -c "${command}"
}
function print_usage {
echo "Usage: ./dev [command] [args]"
}
function show_help {
cat << EOF
The following commands are supported:
./dev start # Start the development stack
./dev stop # Stop the development stack
./dev rebuild # Rebuild the images and restart the development stack
./dev reset # Reset the stack (including volumes and images)
./dev update # Update from main branch
./dev iex # Spawn IEx session
./dev mix # Run mix commands
./dev translations.update # Run the (Elixir) tests
./dev test # Run the (Elixir) tests
./dev test.watch # Run the (Elixir) tests in watch mode
./dev test.env.reset # Reset the (Elixir) test environment
./dev yarn # Run a Yarn command
./dev build.prod # Run production build for assets
./dev execute # Run arbitrary command in a container
To get information about a single command use ./dev [command] --help
EOF
}
function maybe_show_command_help {
if [ "${1}" == "--help" ]; then
return
fi
if [ "${2}" != "--help" ]; then
return
fi
case ${command} in
"start"|"s")
print_help_for_start
;;
"stop"|"st")
print_help_for_stop
;;
"rebuild"|"rb")
print_help_for_rebuild
;;
"reset"|"rs")
print_help_for_reset
;;
"update"|"u")
print_help_for_update
;;
"iex"|"i")
print_help_for_iex
;;
"mix"|"m")
print_help_for_mix
;;
"translations.update"|"tu")
print_help_for_update_translations
;;
"test"|"t")
print_help_for_test
;;
"test.env.reset"|"ter")
print_help_for_test_env_reset
;;
"test.watch"|"tw")
print_help_for_test_watch
;;
"yarn"|"y")
print_help_for_yarn
;;
"build.prod"|"bp")
print_help_for_build_production
;;
"execute"|"e")
print_help_for_execute
;;
*) echo "No help found for '${command}'"
esac
exit 0
}
function print_help_for_start {
cat << EOF
# start
shortcut: s
The 'start' command checks if the required tools (Docker, Mutagen) are available.
If so it will check and create or load the images needed for the application.
It starts the application stack with all containers and opens the logs.
Stop the command with ctrl-c. This will stop the stack.
EOF
}
function print_help_for_stop {
cat << EOF
# stop
shortcut: st
The 'stop' command will stop the stack. All data and containers will be preserved.
EOF
}
function print_help_for_rebuild {
cat << EOF
# rebuild
shortcut: rb
The 'rebuild' command will tear down and rebuild the containers.
The volumes and images will be preserved.
EOF
}
function print_help_for_reset {
cat << EOF
# reset
shortcut: rs
The 'reset' command tears down the application and removes all built images and
volumes.
This is useful to start over.
EOF
}
function print_help_for_update {
cat << EOF
# update
shortcut: u
The 'update' command fetches the latest upstream state and fast-forward merges
the main branch.
EOF
}
function print_help_for_iex {
cat << EOF
# iex
shortcut: i
The 'iex' command spawns a new IEx session for the project.
EOF
}
function print_help_for_mix {
cat << EOF
# mix
shortcut: m
The 'mix' command can be used to run mix commands, e.g.
./dev mix run priv/repo.seeds.exs
EOF
}
function print_help_for_update_translations {
cat << EOF
# translations.update
shortcut: tu
The 'update_translations' command extracts and updates the application translations.
EOF
}
function print_help_for_test {
cat << EOF
# test [test_file_path]
shortcut: t
The 'test' command runs the test suite.
To run single tests the path can be passed as an argument.
EOF
}
function print_help_for_test_env_reset {
cat << EOF
# test.env.reset
shortcut: ter
The 'test.env.reset' command resets the test databases.
This includes the event store database as well as the repo
database.
EOF
}
function print_help_for_test_watch {
cat << EOF
# test.watch [test_file_path]
shortcut: tw
The 'test.watch' command runs the test suite in watch mode.
To run single tests the path can be passed as an argument.
EOF
}
function print_help_for_yarn {
cat << EOF
# yarn [args]
shortcut: y
The 'yarn' command runs Yarn commands within the web container.
EOF
}
function print_help_for_build_production {
cat << EOF
# build.prod
shortcut: bp
The 'build.prod' command runs building the assets in prod mode. This is useful
for debugging things like CSS purging.
EOF
}
function print_help_for_execute {
cat << EOF
# execute [container_name] [args]
shortcut: e
The 'execute' command runs arbitrary commands in the given container.
F.e. you can run './dev execute web "cd assets && yarn add my_dep -D"' to add a javascript library.
EOF
}
function main {
local command=${1}
local args="${@:2}"
maybe_show_command_help ${command} ${args}
case ${command} in
"--help")
show_help
;;
"start"|"s")
run_start
;;
"stop"|"st")
run_stop
;;
"rebuild"|"rb")
run_rebuild
;;
"reset"|"rs")
run_clean
;;
"update"|"u")
run_update
;;
"iex"|"i")
run_iex ${args}
;;
"mix"|"m")
run_mix ${args}
;;
"translations.update"|"tu")
run_update_translations
;;
"test"|"t")
run_tests ${args}
;;
"test.env.reset"|"ter")
run_test_env_reset
;;
"test.watch"|"tw")
run_tests_in_watch_mode ${args}
;;
"yarn"|"y")
run_yarn ${args}
;;
"build.prod"|"bp")
run_build_production
;;
"execute"|"e")
run_command ${args}
;;
*) print_usage; echo; show_help
esac
}
main $@