forked from dssg/triage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial.sh
executable file
·129 lines (106 loc) · 2.54 KB
/
tutorial.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
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
#!/bin/bash
set -e -u
DIRTYDUCK_HOME="dirtyduck"
function help_menu () {
cat << EOF
Usage: ${0} {up|down|build|rebuild|run|logs|status|clean}
OPTIONS:
-h|help Show this message
up Starts Food DB
down Stops Food DB
build Builds images (food_db and bastion)
rebuild Builds images (food_db and bastion) ignoring if they already exists
-l|logs Shows container's logs
status Shows status of the containers
-d|clean Removes containers, images, volumes, networks
INFRASTRUCTURE:
Build the Dirtyduck's DB:
$ ./tutorial.sh up
Check the status of the containers:
$ ./tutorial.sh status
Stop the dirtyduck's infrastructure:
$ ./tutorial.sh down
Destroy all the resources related to the tutorial:
$ ./tutorial.sh clean
View dirtyduck's logs:
$ ./tutorial.sh -l
EOF
}
function start_infrastructure () {
docker-compose -f ${DIRTYDUCK_HOME}/docker-compose.yml up -d food_db
}
function stop_infrastructure () {
docker-compose -f ${DIRTYDUCK_HOME}/docker-compose.yml stop
}
function build_triage () {
docker build --target development -t dsapp/triage:development -f Dockerfile .
}
function build_images () {
docker-compose -f ${DIRTYDUCK_HOME}/docker-compose.yml build "${@}"
}
function destroy () {
docker-compose -f ${DIRTYDUCK_HOME}/docker-compose.yml down --rmi all --remove-orphans --volumes
}
function infrastructure_logs () {
docker-compose -f ${DIRTYDUCK_HOME}/docker-compose.yml logs -f -t
}
function status () {
docker-compose -f ${DIRTYDUCK_HOME}/docker-compose.yml ps
}
function bastion () {
docker-compose -f ${DIRTYDUCK_HOME}/docker-compose.yml run --service-ports --rm --name dirtyduck_bastion bastion
}
function all () {
build_images
start_infrastructure
status
}
if [[ $# -eq 0 ]] ; then
help_menu
exit 0
fi
case "$1" in
up)
start_infrastructure
shift
;;
down)
stop_infrastructure
shift
;;
build)
build_triage
build_images
shift
;;
rebuild)
build_images --no-cache
shift
;;
-d|clean)
destroy
shift
;;
-l|logs)
infrastructure_logs
shift
;;
status)
status
shift
;;
bastion)
bastion
shift
;;
-h|help)
help_menu
shift
;;
*)
echo "${1} is not a valid flag, try running: ${0} -h"
shift
;;
esac
shift
cd - > /dev/null