redeploy.sh 1.85 KB
Newer Older
1
2
3
#!/bin/bash

# ----- CAUTION!!! -----
johandegn's avatar
johandegn committed
4
5
6
# This script stops and removes the running web and server
# containers, removes their images and the persist-net
# docker network.
7
#
johandegn's avatar
johandegn committed
8
9
# It then reconfigures the network, download
# the images and redeploys them again.
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

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!"