File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
set -euo pipefail
3
3
4
+ server_version () {
5
+ docker version -f " {{.Server.Version}}"
6
+ }
7
+
4
8
update_services () {
5
9
local blacklist=" $1 "
10
+ local supports_detach_option=$2
11
+ local detach_option=" "
12
+ [ $supports_detach_option = true ] && detach_option=" --detach=false"
6
13
7
14
for service in $( IFS=" \n" docker service ls --quiet) ; do
8
15
local name image_with_digest image
@@ -11,19 +18,26 @@ update_services() {
11
18
image_with_digest=" $( docker service inspect " $service " -f ' {{.Spec.TaskTemplate.ContainerSpec.Image}}' ) "
12
19
image=$( echo " $image_with_digest " | cut -d@ -f1)
13
20
echo " Updating service $name with image $image "
14
- docker service update " $service " --detach=false --image=" $image " > /dev/null
21
+ docker service update " $service " $detach_option --image=" $image " > /dev/null
15
22
fi
16
23
done
17
24
}
18
25
19
26
main () {
20
- local blacklist=" ${BLACKLIST_SERVICES:- } "
27
+ local blacklist supports_detach_option=false
28
+ blacklist=" ${BLACKLIST_SERVICES:- } "
29
+
30
+ if [[ " $( server_version) " > " 17.05" ]]; then
31
+ supports_detach_option=true
32
+ echo " Enabling synchronous service updates"
33
+ fi
34
+
21
35
[[ " $blacklist " != " " ]] && echo " Excluding services: $blacklist "
22
36
23
37
while true ; do
24
- update_services " ${ blacklist} "
25
- echo " Sleeping ${ SLEEP_TIME} before next update"
26
- sleep " ${ SLEEP_TIME} "
38
+ update_services " $blacklist " " $supports_detach_option "
39
+ echo " Sleeping $SLEEP_TIME before next update"
40
+ sleep " $SLEEP_TIME "
27
41
done
28
42
}
29
43
You can’t perform that action at this time.
0 commit comments