-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
61 lines (50 loc) · 1.22 KB
/
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
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#
## This script is only used for localhost building.
#
run_mode=''
service_tag=''
export RUN_NPM_INSTALL="$RUN_NPM_INSTALL"
#
## Reset in case getopts has been used previously in the shell.
#
OPTIND=1
while getopts "npw:" opt; do
case "$opt" in
n )
export RUN_NPM_INSTALL=$(uuidgen)
;;
p )
run_mode='PROD'
;;
w )
service_tag="${pb_service_name}-localhost-$OPTARG"
service_tag_suffix="localhost-$OPTARG"
;;
esac
done
if [[ -n "$service_tag" ]]; then
# Remove the old container if there is
docker ps -a -q --filter=ancestor="$service_tag" | xargs -I {} docker rm -f {}
#
## Build image.
#
docker build \
--build-arg PORTS_END=53547 \
--build-arg "RUN_NPM_INSTALL=$RUN_NPM_INSTALL" \
--tag "$service_tag" \
.
#
## Run the container.
#
## Since this is only for localhost testing purpose, so expose one port only, no matter how many cores your cpu has.
#
docker run -d -P \
--env "RUN_MODE=$run_mode" \
--env "SERVICE_NAME=$service_tag" \
--env "MS_SERVICE_TAG=$service_tag" \
--env "SERVICE_TAG_SUFFIX=$service_tag_suffix" \
"$service_tag"
else
echo "Error: please specify the env owner with '-w' option."
fi