-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_container.sh
executable file
·49 lines (38 loc) · 1.07 KB
/
build_container.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
#! /usr/bin/env bash
# vim: filetype=sh
NAME="s5p"
DOCKER_OPTS="--restart=always --net=host --log-opt mode=non-blocking --log-opt max-buffer-size=4m"
if (( $# < 1 )); then
echo "usage: build_container.sh server | build_container.sh proxy server_address"
exit 1
fi
ROLE="$1"
if [[ $ROLE == "proxy" ]]; then
if (( $# < 2 )); then
echo "usage: build_container.sh proxy server_address"
exit 1
fi
SERVER="$2"
fi
if (docker container ls -a --format '{{.Names}}' | grep -q "$NAME")
then
echo "rm container ..."
docker container stop "$NAME"
docker container rm "$NAME"
fi
if (docker image ls --format '{{.Repository}}' | grep -q "$NAME")
then
echo "rm image ..."
docker image rm "$NAME"
fi
echo "build image ..."
docker image build -t $NAME .
echo "build $ROLE container ..."
if [[ "$ROLE" == "server" ]]; then
docker container create --name="$NAME" $DOCKER_OPTS $NAME s5pserver
elif [[ "$ROLE" == "proxy" ]]; then
docker container create --name="$NAME" $DOCKER_OPTS $NAME s5pproxy -S $SERVER
else
echo "only support server|proxy container"
exit 1
fi