forked from docker-library/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·141 lines (119 loc) · 4.17 KB
/
update.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
set -eo pipefail
defaultAlpineVersion='3.12'
declare -A alpineVersion=(
#[17.09]='3.6'
)
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
source '.architectures-lib'
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
# see http://stackoverflow.com/a/2705678/433558
sed_escape_lhs() {
echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g'
}
sed_escape_rhs() {
echo "$@" | sed -e 's/[\/&]/\\&/g' | sed -e ':a;N;$!ba;s/\n/\\n/g'
}
# "tac|tac" for http://stackoverflow.com/a/28879552/433558
dindLatest="$(curl -fsSL 'https://github.com/docker/docker/commits/master/hack/dind.atom' | tac|tac | awk -F '[[:space:]]*[<>/]+' '$2 == "id" && $3 ~ /Commit/ { print $4; exit }')"
dockerVersions="$(
git ls-remote --tags https://github.com/docker/docker-ce.git \
| cut -d$'\t' -f2 \
| grep '^refs/tags/v[0-9].*$' \
| sed 's!^refs/tags/v!!; s!\^{}$!!' \
| sort -u \
| gawk '
{ data[lines++] = $0 }
# "beta" sorts lower than "tp" even though "beta" is a more preferred release, so we need to explicitly adjust the sorting order for RCs
# also, "18.09.0-ce-beta1" vs "18.09.0-beta3"
function docker_version_compare(i1, v1, i2, v2, l, r) {
l = v1; gsub(/-ce/, "", l); gsub(/-tp/, "-alpha", l)
r = v2; gsub(/-ce/, "", r); gsub(/-tp/, "-alpha", r)
patsplit(l, ltemp, /[^.-]+/)
patsplit(r, rtemp, /[^.-]+/)
for (i = 0; i < length(ltemp) && i < length(rtemp); ++i) {
if (ltemp[i] < rtemp[i]) {
return -1
}
if (ltemp[i] > rtemp[i]) {
return 1
}
}
return 0
}
END {
asort(data, result, "docker_version_compare")
for (i in result) {
print result[i]
}
}
'
)"
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
versionOptions="$(grep "^$rcVersion[.]" <<<"$dockerVersions")"
rcGrepV='-v'
if [ "$rcVersion" != "$version" ]; then
rcGrepV=
fi
fullVersion="$(grep $rcGrepV -E -- '-(rc|tp|beta)' <<<"$versionOptions" | tail -1)"
if [ -z "$fullVersion" ]; then
echo >&2 "warning: cannot find full version for $version"
continue
fi
channel="$(versionChannel "$version")"
echo "$version: $fullVersion ($channel)"
archCase='apkArch="$(apk --print-arch)"; '$'\\\n'
archCase+=$'\t''case "$apkArch" in '$'\\\n'
for apkArch in $(apkArches); do
dockerArch="$(apkToDockerArch "$apkArch")"
# check whether the given architecture is supported for this release
if wget --quiet --spider "https://download.docker.com/linux/static/$channel/$dockerArch/docker-$fullVersion.tgz" &> /dev/null; then
bashbrewArch="$(apkToBashbrewArch "$apkArch")"
archCase+="# $bashbrewArch"$'\n'
archCase+=$'\t\t'"$apkArch) dockerArch='$dockerArch' ;; "$'\\\n'
fi
done
archCase+=$'\t\t''*) echo >&2 "error: unsupported architecture ($apkArch)"; exit 1 ;;'$'\\\n'
archCase+=$'\t''esac'
alpine="${alpineVersion[$version]:-$defaultAlpineVersion}"
majorVersion="${fullVersion%%.*}"
minorVersion="${fullVersion#$majorVersion.}"
minorVersion="${minorVersion%%.*}"
minorVersion="${minorVersion#0}"
for variant in \
'' git dind dind-rootless \
windows/windowsservercore-{1709,ltsc2016} \
; do
dir="$version${variant:+/$variant}"
[ -d "$dir" ] || continue
df="$dir/Dockerfile"
slash='/'
case "$variant" in
windows/windowsservercore*) tag="${variant#*-}"; template='Dockerfile-windows-windowsservercore.template' ;;
*) tag="$alpine"; template="Dockerfile${variant:+-${variant//$slash/-}}.template" ;;
esac
sed -r \
-e 's!%%VERSION%%!'"$version"'!g' \
-e 's!%%DOCKER-CHANNEL%%!'"$channel"'!g' \
-e 's!%%DOCKER-VERSION%%!'"$fullVersion"'!g' \
-e 's!%%TAG%%!'"$tag"'!g' \
-e 's!%%DIND-COMMIT%%!'"$dindLatest"'!g' \
-e 's!%%ARCH-CASE%%!'"$(sed_escape_rhs "$archCase")"'!g' \
"$template" > "$df"
# DOCKER_TLS_CERTDIR is only enabled-by-default in 19.03+
if [ "$majorVersion" -lt 19 ]; then
sed -ri -e 's!^(ENV DOCKER_TLS_CERTDIR=).*$!\1!' "$df"
fi
# pigz (https://github.com/moby/moby/pull/35697) is only 18.02+
if [ "$majorVersion" -lt 18 ] || { [ "$majorVersion" -eq 18 ] && [ "$minorVersion" -lt 2 ]; }; then
sed -ri '/pigz/d' "$df"
fi
done
cp -a docker-entrypoint.sh modprobe.sh "$version/"
cp -a dockerd-entrypoint.sh "$version/dind/"
done