forked from bcgov/esm-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_deploy.sh
executable file
·79 lines (66 loc) · 2.8 KB
/
docker_deploy.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
#!/bin/bash
environment_name=""
image_name=""
environment_variables=""
if [ "$#" -lt 2 ]; then
echo "Please specify an environment name as the first argument and an image to deploy as the second command-line argument."
exit -1
else
environment_name=$1
image_name=$2
app_variant=$(echo $environment_name | cut -f1 -d-)
promotion_level=$(echo $environment_name| cut -f2 -d-)
app_subvariant=$(echo $environment_name | cut -f3 -d-)
echo "Starting deployment for environment $environment_name with image $image_name ..."
echo "Variant is '$app_variant' and promotion level is '$promotion_level' ..."
if [ ${app_variant} = "mem" ]; then
environment_variables="-e MEM=true -e SEED_MEM=true"
fi
if [ -z ${app_subvariant} ]; then
echo "no subvariant"
else
echo "Subvariant is '$app_subvariant' ..."
environment_variables="-e ESM_VARIANT=$app_subvariant"
# re-assign the environment name, removing the subvariant
environment_name="$app_variant-$promotion_level"
echo "Environment is now '$environment_name' ..."
fi
fi
proxy="false"
proxyParams=""
proxyPort=""
virtualHost=""
if [ "$#" -ge 3 ]; then
if [ $3 = "PROXY" ]; then
if [ "$#" -lt 5 ]; then
echo "PROXY must be followed by a port and a virtual host."
exit -1
else
proxy="true"
proxyPort="$4"
virtualHost="$5"
proxyParams="-e VIRTUAL_PORT=$proxyPort -e VIRTUAL_HOST=$virtualHost"
fi
fi
fi
# pull the referenced image from our private registry
docker pull $image_name
# find the id of the prior container, if it exists
priorContainer=`docker ps -a --filter name=app-$environment_name | awk '{if(NR>1)print $1;}'`
# stop the previously deployed instance of the app
if [ -n "$priorContainer" ] ; then
priorContainerRunning=`docker ps -a --filter name=app-$environment_name -f status=running | awk '{if(NR>1)print $1;}'`
if [ -n "$priorContainerRunning" ]; then
echo "Stopping previously deployed container..."
docker stop $priorContainer
fi
ts=`date +"%m-%d-%y_%s"`
docker rename $priorContainer "$priorContainer-backup-$ts"
fi;
if [ "$proxy" = "true" ]; then
echo "Running with proxy."
docker run -p $proxyPort:3000 -v /data/$environment_name/uploads:/uploads -d --restart=always --link webapp-proxy:webapp-proxy --link mongo-$environment_name:db_1 --name app-$environment_name $proxyParams $environment_variables -l appname=$environment_name $image_name
else
echo "Running without proxy."
docker run -p $proxyPort:3000 -v /data/$environment_name/esm-uploads:/uploads -d --restart=always --link mongo-$environment_name:db_1 --name app-$environment_name -l appname=$environment_name $environment_variables $image_name
fi