-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.sh
executable file
·88 lines (76 loc) · 1.8 KB
/
manage.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
#!/bin/bash
COMMANDLINE_ARGS=("$@")
OPERATION=${COMMANDLINE_ARGS[0]}
function usage {
cat <<usagemessage
+++++++++++++++++++++++++++++
USAGE: ./manage.sh op
op:
* [kill] kills service's container
* [run]: runs service's container
* [restart]: kill service's container then run the container.
* [build]: build service's container image with latest working dir changes.
* [deploy]: build service's container image with latest working dir changes and
runs the service's container.
* [unittests] run the unittests containr and them purge it.
+++++++++++++++++++++++++++++
usagemessage
}
function run_unit_tests {
docker run --rm enid-sieve:latest pytest -v
}
function run_service_detached {
# run container in detached state and publish container's port 80 to host's port 8000.
docker run --name enidsieve -dp 8000:80 enid-sieve
}
function kill_service {
docker kill enidsieve; docker container rm enidsieve;
}
function restart_service {
kill_service
run_service_detached
}
function purge_dangling_images {
# after each build, there mightbe some residue from the intermediate containers,
# that was created by docker during the container image building process, so we purge them
# to save disk space.
local DANGLING_IMAGES=$(docker images -f "dangling=true" -q)
if [ "$DANGLING_IMAGES" ]; then
docker rmi $DANGLING_IMAGES
fi
}
function build {
kill_service
docker build --force-rm -t enid-sieve .
purge_dangling_images
}
function deploy {
build
run_service_detached
}
function main {
case $OPERATION in
kill)
kill_service
;;
run)
run_service_detached
;;
build)
build
;;
restart)
restart_service
;;
deploy)
deploy
;;
unittests)
run_unit_tests
;;
*)
usage
;;
esac
}
main