redeploy.sh 1.82 KB
Newer Older
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
#!/bin/bash

# ----- CAUTION!!! -----
# This script removes all running containers,
# all local docker images and all unused
# docker networks.
#
# It then reconfiguring the network downloading
# the images and redeploys them.

base_url="registry.gitlab.au.dk/exsys2021/da6/hold-afstand/"

# stops docker containers
echo -n "Stopping containers..."
docker stop server >/dev/null 2>&1
docker stop web >/dev/null 2>&1
echo " Done."

# removes docker containers
echo -n "Removing containers..."
docker rm server >/dev/null 2>&1
docker rm web >/dev/null 2>&1
echo " Done."

# removes docker images
echo -n "Removing images..."
docker rmi ${base_url}server:active >/dev/null 2>&1
docker rmi ${base_url}web:active >/dev/null 2>&1
echo " Done."

# removes unused docker networks
echo -n "Removing docker network..."
docker network rm persist-net >/dev/null 2>&1
echo " Done."

# pulling the images
echo -n "Pulling latest sever image..."
docker pull ${base_url}server:latest >/dev/null 2>&1
echo " Done."
echo -n "Pulling latest web image..."
docker pull ${base_url}web:latest >/dev/null 2>&1
echo " Done."

# changes tags from latest to active
echo -n "Tagging..."
docker tag ${base_url}server:latest ${base_url}server:active >/dev/null 2>&1
docker tag ${base_url}web:latest ${base_url}web:active >/dev/null 2>&1

docker rmi ${base_url}server:latest >/dev/null 2>&1
docker rmi ${base_url}web:latest >/dev/null 2>&1
echo " Done."

# crates network
echo -n "Creates docker network..."
docker network create -d bridge persist-net --attachable >/dev/null 2>&1
echo " Done."

# spins up containers
echo -n "Spinning up containers..."
docker run --network persist-net --network-alias server --name server -d ${base_url}server:active >/dev/null 2>&1
docker run --network persist-net -p 80:80 --name web -d ${base_url}web:active >/dev/null 2>&1
echo " Done."
echo "All done!"