-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.staging.sh
executable file
·131 lines (111 loc) · 3.01 KB
/
deploy.staging.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# Deployment script for sdt-validation-server-api
# Purpose: copies the correct docker-compose, requirements.txt, and .env file to
# the correct locations and then runs the docker commands and initialization
# scripts.
# Command: ./deploy.sh [environment]] -[destroy] -[restart] > deployment.log
# Options: environment = development, staging, or production
# -destroy = delete all containers and images before Building
# -restart = restart docker-machine before building Containers
# > deployment.log = write starttup messages to a file 'deployment.log'
#
echo "-----------------------------------------------------"
echo "Starting build: $(date)"
echo "-----------------------------------------------------"
SECONDS=0
while getopts "e:m:r:d:i:c:o:" option; do
case $option in
e ) env=$OPTARG
;;
d ) destroy=$OPTARG
;;
i ) import=$OPTARG
;;
c ) check=$OPTARG
;;
o ) options=$OPTARG
;;
esac
done
if [[ "$destroy" == "destroy" ]]
then
destroy=1
else
destroy=0
fi
if [[ "$restart" == "restart" ]]
then
restart=1
else
restart=0
fi
if [[ "$import" == "import" ]]
then
import=1
else
import=0
fi
if [[ "$check" == "check" ]]
then
check=1
else
check=0
fi
if [[ "$options" == "interactive" ]]
then
interactive=1
else
interactive=0
fi
if [[ "$env" == "prod" ]]
then
environment="production"
elif [[ "$env" == "stg" ]]
then
environment="staging"
elif [[ "$env" == "dev" ]]
then
environment="development"
else
environment=$env
fi
echo "-----------------------------------------------------"
echo "Inputs from command"
echo "-----------------------------------------------------"
echo "env: $env"
echo "environment: $environment"
echo "destroy: $destroy"
echo "import: $import"
echo "check: $check"
#else
# echo "-----------------------------------------------------"
# echo "Docker not installed - no restart is possible"
# echo "-----------------------------------------------------"
#fi
#Open Docker, only if is not running
if (! docker stats --no-stream ); then
sudo service docker start;
#Wait until Docker daemon is running and has completed initialisation
while (! docker stats --no-stream ); do
# Docker takes a few seconds to initialize
echo "Waiting for Docker to launch..."
sleep 1
done
fi
# Check if the container exists
if docker ps -a --format '{{.Names}}' | grep -q '^webapp$'; then
# If the container exists, stop and remove it
docker stop webapp && docker rm webapp
fi
# Build and run the container using docker-compose
docker-compose -f docker-compose.staging.yml up --build -d
echo "-----------------------------------------------------"
echo "Pause to allow things to come up"
echo "-----------------------------------------------------"
sleep 15
minutes=$((SECONDS/60))
seconds=$((SECONDS%60))
echo "-----------------------------------------------------"
echo "Ending build: $(date)"
echo "Build took $minutes minutes and $seconds seconds."
echo "-----------------------------------------------------"