forked from nlbdev/service-stem
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
49 lines (42 loc) · 948 Bytes
/
run.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
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
REPLICAS=$1
if [ "$REPLICAS" != "" ]; then
shift
fi
PORT=$1
if [ "$PORT" != "" ]; then
shift
fi
TEMPFILE="`tempfile`"
docker build . | tee $TEMPFILE
BUILD_ID="`cat $TEMPFILE | tail -n 1 | awk '{print $3}'`"
echo "BUILD_ID: $BUILD_ID"
RM="--rm"
IT="-it"
if [ "$PORT" == "" ]; then
REPLICAS=1
fi
if [ "$REPLICAS" != "" ] && [ $REPLICAS -gt 1 ]; then
IT="-d"
fi
# Example: ./run.sh 2 18000
set -x
while [ $REPLICAS -gt 0 ]; do
set +e
REPLICAS=`expr $REPLICAS - 1`
if [ "$?" != "0" ]; then REPLICAS=0 ; fi
set -e
docker run \
$RM $IT \
--network host \
--env-file config.env \
--env PORT=`expr $PORT + $REPLICAS` \
"$BUILD_ID" "$@"
done
if [ "$IT" = "-d" ]; then
read -p "Press a button to stop (kill) the containers..."
docker ps | grep $BUILD_ID | awk '{print $1}' | xargs docker kill
fi