-
Notifications
You must be signed in to change notification settings - Fork 188
/
deploy.sh
executable file
·54 lines (41 loc) · 1.16 KB
/
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
#!/bin/bash
set -e
set -u
set -x
# Delete and Clone Latest
cd ..
rm -rf telescope
git clone https://github.com/Seneca-CDOT/telescope.git --depth=1
cd telescope
# Set NGINX FILE + ENV_FILE Params
if [ $1 = 'production' ]
then
ENV_FILE=config/env.production
elif [ $1 = 'staging' ]
then
ENV_FILE=config/env.staging
else
echo $1 is not a valid argument. Please use either production or staging.
exit 1
fi
if [[ $(docker-compose --env-file $ENV_FILE --project-name=blue ps -q) ]]; then
ENV="green"
OLD="blue"
else
ENV="blue"
OLD="green"
fi
echo "GIT_COMMIT=$2" >> $ENV_FILE
echo "Building $ENV Container"
docker-compose --env-file $ENV_FILE --project-name=$ENV build
# Delete associated project orphans (services) and volumes
echo "Stopping "$OLD" Environment"
docker-compose --env-file $ENV_FILE --project-name=$OLD down --remove-orphans
echo "Deleting $OLD Volumes"
docker volume prune -f
echo "Starting $ENV Environment"
docker-compose --env-file $ENV_FILE --project-name=$ENV up -d
echo "Removing dangling images"
docker rmi $(docker images -f "dangling=true" -q)
echo "Removing $OLD Environment"
docker rmi $(docker images $OLD\_* -aq ) -f 2> /dev/null