forked from cadmiumkitty/vocbench3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_tool.sh
executable file
·75 lines (64 loc) · 1.88 KB
/
docker_tool.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
#!/usr/bin/env bash
APP_NAME=vocbench3
REPO=berzemus
PORT=1979
while getopts ":h" opt; do
case ${opt} in
h )
echo "Usage:"
echo " docker-tool.sh -h Display this help message."
echo " docker-tool.sh build <VERSION> Builds image"
echo " docker-tool.sh test <VERSION> Tests image"
echo " docker-tool.sh publish <VERSION> Publishes image to Docker Hub"
echo " docker-tool.sh latest <VERSION> Tags images as latest on Docker Hub."
echo " docker-tool.sh run <VERSION> Run the image locally"
exit 0
;;
\? )
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
esac
done
test_docker_image() {
docker run -d --name "$1" -p ${PORT}:${PORT} -e HOST='0.0.0.0' $REPO/$APP_NAME:"$1"
sleep 2
url=http://localhost:${PORT}/
status=$(curl --get --location --connect-timeout 5 --write-out %{http_code} --silent --output /dev/null ${url})
if [[ $status == '200' ]]
then
echo "$(tput setaf 2)Image: ${REPO}/${APP_NAME}:${1} - Passed$(tput sgr0)"
docker kill "$1"
docker rm "$1"
else
echo "$(tput setaf 1)Image: ${REPO}/${APP_NAME}:${1} - Failed$(tput sgr0)"
docker kill "$1"
docker rm "$1"
exit 1
fi
}
shift $((OPTIND -1))
subcommand=$1; shift
version=$1; shift
case "$subcommand" in
build)
docker build -t ${REPO}/${APP_NAME}:${version} -f ./Dockerfile --no-cache .
;;
test)
# Test the images
test_docker_image ${version}
;;
publish)
# Push the build images
docker push ${REPO}/${APP_NAME}:${version}
;;
latest)
# Update the latest tags to point to supplied version
docker tag ${REPO}/${APP_NAME}:${version} ${REPO}/${APP_NAME}:latest
docker push ${REPO}/${APP_NAME}:latest
;;
run)
# Run the image
docker run -it --rm -p ${PORT}:${PORT} ${REPO}/${APP_NAME}:${version}
;;
esac