forked from docker-library/openjdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.sh
executable file
·360 lines (300 loc) · 9.62 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/bin/bash
set -eo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
declare -A suites=(
[6]='wheezy'
[7]='jessie'
[8]='jessie'
[9]='sid'
)
declare -A alpineVersions=(
[7]='3.4'
[8]='3.4'
[9]='3.5'
)
declare -A addSuites=(
[8]='jessie-backports'
[9]='experimental'
)
declare -A variants=(
[jre]='curl'
[jdk]='scm'
)
declare -A debCache=()
declare -A debVerCache=()
dpkgArch="$(dpkg --print-architecture)"
debian-latest-version() {
local package="$1"; shift
local suite="$1"; shift
local debVerCacheKey="$package-$suite"
if [ -n "${debVerCache[$debVerCacheKey]:-}" ]; then
echo "${debVerCache[$debVerCacheKey]}"
return
fi
local debMirror='https://deb.debian.org/debian'
local secMirror='http://security.debian.org'
local remotes=( "$debMirror/dists/$suite/main" )
case "$suite" in
sid) ;;
experimental)
remotes+=( "$debMirror/dists/sid/main" )
;;
*-backports)
suite="${suite%-backports}"
remotes+=( "$debMirror/dists/$suite/main" )
;&
*)
remotes+=(
"$debMirror/dists/$suite-updates/main"
"$secMirror/dists/$suite/updates/main"
)
;;
esac
local latestVersion= remote=
for remote in "${remotes[@]}"; do
if [ -z "${debCache[$remote]:-}" ]; then
local urlBase="$remote/binary-$dpkgArch/Packages" url= decomp=
for comp in xz bz2 gz ''; do
if wget --quiet --spider "$urlBase.$comp"; then
url="$urlBase.$comp"
case "$comp" in
xz) decomp='xz -d' ;;
bz2) decomp='bunzip2' ;;
gz) decomp='gunzip' ;;
'') decomp='cat' ;;
esac
break
fi
done
if [ -z "$url" ]; then
continue
fi
debCache[$remote]="$(wget -qO- "$url" | eval "$decomp")"
fi
IFS=$'\n'
local versions=( $(
echo "${debCache[$remote]}" \
| awk -F ': ' '
$1 == "Package" { pkg = $2 }
pkg == "'"$package"'" && $1 == "Version" { print $2 }
'
) )
unset IFS
local version=
for version in "${versions[@]}"; do
if [ -z "$latestVersion" ] || dpkg --compare-versions "$version" '>>' "$latestVersion"; then
latestVersion="$version"
fi
done
done
debVerCache[$debVerCacheKey]="$latestVersion"
echo "$latestVersion"
}
java-home-script() {
cat <<'EOD'
# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
RUN { \
echo '#!/bin/sh'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home
EOD
}
travisEnv=
for version in "${versions[@]}"; do
javaVersion="$version" # "6-jdk"
javaType="${javaVersion##*-}" # "jdk"
javaVersion="${javaVersion%-*}" # "6"
suite="${suites[$javaVersion]}"
addSuite="${addSuites[$javaVersion]}"
variant="${variants[$javaType]}"
javaHome="/usr/lib/jvm/java-$javaVersion-openjdk-$dpkgArch"
if [ "$javaType" = 'jre' -a "$javaVersion" -lt 9 ]; then
# woot, this hackery stopped in OpenJDK 9+!
javaHome+='/jre'
fi
needCaHack=
if [ "$javaVersion" -ge 8 -a "$suite" != 'sid' ]; then
# "20140324" is broken (jessie), but "20160321" is fixed (sid)
needCaHack=1
fi
debianPackage="openjdk-$javaVersion-$javaType"
if [ "$javaType" = 'jre' -o "$javaVersion" -ge 9 ]; then
# "openjdk-9" in Debian introduced an "openjdk-9-jdk-headless" package \o/
debianPackage+='-headless'
fi
debSuite="${addSuite:-$suite}"
debian-latest-version "$debianPackage" "$debSuite" > /dev/null # prime the cache
debianVersion="$(debian-latest-version "$debianPackage" "$debSuite")"
fullVersion="${debianVersion%%-*}"
fullVersion="${fullVersion#*:}"
echo "$version: $fullVersion (debian $debianVersion)"
cat > "$version/Dockerfile" <<-EOD
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
FROM buildpack-deps:$suite-$variant
# A few problems with compiling Java from source:
# 1. Oracle. Licensing prevents us from redistributing the official JDK.
# 2. Compiling OpenJDK also requires the JDK to be installed, and it gets
# really hairy.
EOD
cat >> "$version/Dockerfile" <<'EOD'
RUN apt-get update && apt-get install -y --no-install-recommends \
bzip2 \
unzip \
xz-utils \
&& rm -rf /var/lib/apt/lists/*
EOD
if [ "$addSuite" ]; then
cat >> "$version/Dockerfile" <<-EOD
RUN echo 'deb http://deb.debian.org/debian $addSuite main' > /etc/apt/sources.list.d/$addSuite.list
EOD
fi
cat >> "$version/Dockerfile" <<-EOD
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
EOD
java-home-script >> "$version/Dockerfile"
cat >> "$version/Dockerfile" <<-EOD
ENV JAVA_HOME $javaHome
ENV JAVA_VERSION $fullVersion
ENV JAVA_DEBIAN_VERSION $debianVersion
EOD
if [ "$needCaHack" ]; then
debian-latest-version 'ca-certificates-java' "$debSuite" > /dev/null # prime the cache
caCertHackVersion="$(debian-latest-version 'ca-certificates-java' "$debSuite")"
cat >> "$version/Dockerfile" <<-EOD
# see https://bugs.debian.org/775775
# and https://github.com/docker-library/java/issues/19#issuecomment-70546872
ENV CA_CERTIFICATES_JAVA_VERSION $caCertHackVersion
EOD
fi
cat >> "$version/Dockerfile" <<EOD
RUN set -x \\
&& apt-get update \\
&& apt-get install -y \\
$debianPackage="\$JAVA_DEBIAN_VERSION" \\
EOD
if [ "$needCaHack" ]; then
cat >> "$version/Dockerfile" <<EOD
ca-certificates-java="\$CA_CERTIFICATES_JAVA_VERSION" \\
EOD
fi
cat >> "$version/Dockerfile" <<EOD
&& rm -rf /var/lib/apt/lists/* \\
&& [ "\$JAVA_HOME" = "\$(docker-java-home)" ]
EOD
if [ "$needCaHack" ]; then
cat >> "$version/Dockerfile" <<-EOD
# see CA_CERTIFICATES_JAVA_VERSION notes above
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure
EOD
fi
cat >> "$version/Dockerfile" <<-EOD
# If you're reading this and have any feedback on how this image could be
# improved, please open an issue or a pull request so we can discuss it!
EOD
variant='alpine'
if [ -d "$version/$variant" ]; then
alpineVersion="${alpineVersions[$javaVersion]}"
alpinePackage="openjdk$javaVersion"
alpineJavaHome="/usr/lib/jvm/java-1.${javaVersion}-openjdk"
alpinePathAdd="$alpineJavaHome/jre/bin:$alpineJavaHome/bin"
case "$javaType" in
jdk)
;;
jre)
alpinePackage+="-$javaType"
alpineJavaHome+="/$javaType"
;;
esac
alpineMirror="http://dl-cdn.alpinelinux.org/alpine/v${alpineVersion}/community/x86_64"
alpinePackageVersion="$(
wget -qO- "$alpineMirror/APKINDEX.tar.gz" \
| tar --extract --gzip --to-stdout APKINDEX \
| awk -F: '$1 == "P" { pkg = $2 } pkg == "'"$alpinePackage"'" && $1 == "V" { print $2 }'
)"
alpineFullVersion="${alpinePackageVersion/./u}"
alpineFullVersion="${alpineFullVersion%%.*}"
echo "$version: $alpineFullVersion (alpine $alpinePackageVersion)"
cat > "$version/$variant/Dockerfile" <<-EOD
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
FROM alpine:$alpineVersion
# A few problems with compiling Java from source:
# 1. Oracle. Licensing prevents us from redistributing the official JDK.
# 2. Compiling OpenJDK also requires the JDK to be installed, and it gets
# really hairy.
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
EOD
java-home-script >> "$version/$variant/Dockerfile"
cat >> "$version/$variant/Dockerfile" <<-EOD
ENV JAVA_HOME $alpineJavaHome
ENV PATH \$PATH:$alpinePathAdd
EOD
cat >> "$version/$variant/Dockerfile" <<-EOD
ENV JAVA_VERSION $alpineFullVersion
ENV JAVA_ALPINE_VERSION $alpinePackageVersion
EOD
cat >> "$version/$variant/Dockerfile" <<EOD
RUN set -x \\
&& apk add --no-cache \\
${alpinePackage}="\$JAVA_ALPINE_VERSION" \\
&& [ "\$JAVA_HOME" = "\$(docker-java-home)" ]
EOD
travisEnv='\n - VERSION='"$version"' VARIANT='"$variant$travisEnv"
fi
if [ -d "$version/windows" ]; then
ojdkbuildVersion="$(
git ls-remote --tags 'https://github.com/ojdkbuild/ojdkbuild' \
| cut -d/ -f3 \
| grep -E '^1[.]'"$javaVersion"'[.]' \
| sort -V \
| tail -1
)"
if [ -z "$ojdkbuildVersion" ]; then
echo >&2 "error: '$version/windows' exists, but Java $javaVersion doesn't appear to have a corresponding ojdkbuild release"
exit 1
fi
ojdkbuildZip="$(
curl -fsSL "https://github.com/ojdkbuild/ojdkbuild/releases/tag/$ojdkbuildVersion" \
| grep --only-matching -E 'java-'"$(echo "$ojdkbuildVersion" | cut -d. -f1-3)"'-openjdk-'"$ojdkbuildVersion"'[.][b0-9]+[.]ojdkbuild[.]windows[.]x86_64[.]zip' \
| sort -u
)"
if [ -z "$ojdkbuildZip" ]; then
echo >&2 "error: $ojdkbuildVersion doesn't appear to have the release file we need (yet?)"
exit 1
fi
ojdkbuildSha256="$(curl -fsSL "https://github.com/ojdkbuild/ojdkbuild/releases/download/${ojdkbuildVersion}/${ojdkbuildZip}.sha256" | cut -d' ' -f1)"
if [ -z "$ojdkbuildSha256" ]; then
echo >&2 "error: $ojdkbuildVersion seems to have $ojdkbuildZip, but no sha256 for it"
exit 1
fi
ojdkJavaVersion="$(echo "$ojdkbuildVersion" | cut -d. -f2,4 | cut -d- -f1 | tr . u)" # convert "1.8.0.111-3" into "8u111"
echo "$version: $ojdkJavaVersion (windows ojdkbuild $ojdkbuildVersion)"
sed -ri \
-e 's/^(ENV JAVA_VERSION) .*/\1 '"$ojdkJavaVersion"'/' \
-e 's/^(ENV JAVA_OJDKBUILD_VERSION) .*/\1 '"$ojdkbuildVersion"'/' \
-e 's/^(ENV JAVA_OJDKBUILD_ZIP) .*/\1 '"$ojdkbuildZip"'/' \
-e 's/^(ENV JAVA_OJDKBUILD_SHA256) .*/\1 '"$ojdkbuildSha256"'/' \
"$version"/windows/*/Dockerfile
fi
travisEnv='\n - VERSION='"$version$travisEnv"
done
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml