-
Notifications
You must be signed in to change notification settings - Fork 0
/
Secret_updater.sh
executable file
·70 lines (56 loc) · 1.76 KB
/
Secret_updater.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
#!/bin/bash
red () {
echo -e "\e[31m $1 \e[0m"
}
yellow () {
echo -e "\e[33m $1 \e[0m"
}
green () {
echo -e "\e[32m $1 \e[0m"
}
errors () {
red "$1"
exit 1
}
ENV_FILE=$1
SECRET=$2
SERVICE=$3
if [ -z $ENV_FILE ] || [ -z $SECRET ] || [ -z $SERVICE ];
then
red "- Please provide an env file and a service name -"
yellow "- Script usage:"
yellow "- ./Secret_updater.sh </example/file.env> <secret_name> <service_name>"
exit 1
else
yellow "- Updating secret $SECRET..."
docker secret create ${SECRET}_2 $ENV_FILE &> /dev/null && \
green "+ Created new second secret" || \
errors "- Failed when creating second secret"
yellow "- Updating $SERVICE with new second secret..."
docker service update \
--secret-rm $SECRET \
--secret-add source=${SECRET}_2,target=$SECRET \
--detach=false $SERVICE &> /dev/null && \
green "+ Service updated successfully" || \
errors "- Failed when updating service"
yellow "- Deleting old secret..."
docker secret rm $SECRET &> /dev/null && \
green "+ Old secret deleted successfully" || \
errors "- Failed when deleting old secret"
yellow "- Creating secret $SECRET updated..."
docker secret create $SECRET $ENV_FILE &> /dev/null && \
green "+ Secret created successfully" || \
errors "- Failed when creating secret"
yellow "- Updating service $SERVICE with new secret $SECRET..."
docker service update \
--secret-rm ${SECRET}_2 \
--secret-add source=$SECRET,target=$SECRET \
--detach=false $SERVICE &> /dev/null && \
green "+ Service updated successfully" || \
errors "- Failed when updating service"
yellow "- Deleting second secret"
docker secret rm ${SECRET}_2 &> /dev/null && \
green "+ Second secret deleted successfully" || \
errors "- Failed when deleting second secret"
green "+ Secret updated successfully"
fi