forked from td-org-uit-no/tdctl-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev_utils.sh
executable file
·59 lines (50 loc) · 1.44 KB
/
dev_utils.sh
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
#!/usr/bin/env bash
docker_command=""
path=".docker/docker-compose.development.yml"
check_compose_version() {
compose_command="docker compose"
if ! command -v ${compose_command} &> /dev/null; then
# can't find docker compose, tries older version
compose_command="docker-compose"
if ! command -v $compose_command &> /dev/null; then
# couldn't find docker-compose i.e no version of docker compose is installed
return
fi
fi
docker_command="$compose_command -f"
}
usage() {
echo "Utils script for docker commands in development:
Required:
compose:
passes the command line arguments to '${docker_command} ${path} {provided arguments}'.
exec:
exec interactive shell for development container (frontend_dev)
"
}
run_command() {
$docker_command ${path} $@
}
interactive_shell() {
# can use static name as frontend_dev is defined in compose file
docker exec -it frontend_dev bash
}
parse_arguments() {
if [ $# = 0 ];then
usage
exit 1
fi
# couldn't find docker compose or docker-compose
if [ -z "$docker_command" ];then
echo "Could not find any versions of (docker compose or docker-compose)"
exit 1
fi
case $1 in
compose) shift; run_command $@;;
exec) shift; interactive_shell;;
-h | --help) shift; usage;;
* ) usage;;
esac
}
check_compose_version
parse_arguments $@