-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev_utils.sh
executable file
·104 lines (91 loc) · 2.43 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
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
#!/usr/bin/env bash
docker_command=""
path=".docker/docker-compose.development.yml"
utils_path=utils
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_usage)
seed:
seeds database using the seeding file
test:
runs the docker test file, and sends any additional arguments to the pytest command
- 'seed -s' will be the same as 'pytest -s'
"
}
exec_usage() {
echo " exec:
interactive shell for development containers (api or db)
Options:
api - interactive shell for api container (default)
db - interactive monogsh shell for db
"
}
run_compose() {
$docker_command $path $@
}
exec_api() {
docker exec -it tdctl_api bash
}
exec_db() {
container=mongodb_dev
host=td_mongodb
port=26900
docker exec -it $container mongosh --host $host --port $port
}
interactive_shell() {
if [ $# = 0 ];then
# tdctl api is default exec container
exec_api
exit 1
fi
case $1 in
api) shift; exec_api;;
db) shift; exec_db;;
-h | --help) shift; exec_usage;;
* ) exec_usage;;
esac
}
seed_db() {
# runs seeding as module (fixes imports)
docker exec tdctl_api python3 -m $utils_path.seeding
}
run_tests() {
test_file=pytest_docker.py
python3 $utils_path/$test_file $@
}
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_compose $@;;
exec) shift; interactive_shell $@;;
seed) shift; seed_db;;
test) shift; run_tests $@;;
-h | --help) shift; usage;;
* ) usage;;
esac
}
check_compose_version
parse_arguments $@