-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate
More file actions
executable file
·71 lines (60 loc) · 2.23 KB
/
update
File metadata and controls
executable file
·71 lines (60 loc) · 2.23 KB
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
#!/bin/bash
####################################################################################
# Vars
####################################################################################
dockerUsername=""
dockerPassword=""
dockerComposeFile=/etc/spida/docker-compose.yml
####################################################################################
# Parses Args
####################################################################################
function parseCommandLineArguments() {
while [ $# -gt 0 ]
do
case "$1" in
--username) dockerUsername="$2"; shift;;
--password) dockerPassword="$2"; shift;;
--composefile) dockerComposeFile="$2"; shift;;
*)
echo >&2 \
"usage: $0 [option value]
Options:
--username dockerhub username (will prompt for username if argument is not passed)
--password dockerhub password (will prompt for password if argument is not passed)
--composefile the location of the docker compose file (defaults to $dockerComposeFile)
"
exit 1;;
*) break;; # terminate while loop
esac
shift
done
}
####################################################################################
# Logs in to Docker
####################################################################################
function dockerLogin() {
if [[ "$dockerUsername" = "" ]]; then
read -p "Docker username: " dockerUsername
fi
if [[ "$dockerPassword" = "" ]]; then
read -s -p "Docker password: " dockerPassword
fi
sudo docker login -u $dockerUsername -p $dockerPassword
if [ $? -ne 0 ]; then
echo "login failed, exiting."
exit 1
fi
}
parseCommandLineArguments $@
dockerLogin
echo "stopping docker containers..."
sudo docker-compose -f $dockerComposeFile stop
echo "removing old docker containers..."
sudo docker-compose -f $dockerComposeFile rm --force
echo "updating docker containers..."
sudo docker-compose -f $dockerComposeFile pull
echo "starting new docker containers..."
sudo docker-compose -f $dockerComposeFile up -d
echo "removing old docker images"
sudo docker system prune --all --force
sudo docker logout