|
1 | | -# |
2 | | -# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh" |
3 | | -# |
4 | | -# PLEASE DO NOT EDIT IT DIRECTLY. |
5 | | -# |
6 | | - |
7 | 1 | FROM debian:stretch-slim |
8 | 2 |
|
9 | | -# A few reasons for installing distribution-provided OpenJDK: |
10 | | -# |
11 | | -# 1. Oracle. Licensing prevents us from redistributing the official JDK. |
12 | | -# |
13 | | -# 2. Compiling OpenJDK also requires the JDK to be installed, and it gets |
14 | | -# really hairy. |
15 | | -# |
16 | | -# For some sample build times, see Debian's buildd logs: |
17 | | -# https://buildd.debian.org/status/logs.php?pkg=openjdk-11 |
18 | | - |
19 | | -RUN apt-get update && apt-get install -y --no-install-recommends \ |
20 | | - bzip2 \ |
21 | | - unzip \ |
22 | | - xz-utils \ |
23 | | - && rm -rf /var/lib/apt/lists/* |
24 | | - |
25 | | -RUN echo 'deb http://deb.debian.org/debian stretch-backports main' > /etc/apt/sources.list.d/stretch-backports.list |
26 | | - |
27 | 3 | # Default to UTF-8 file.encoding |
28 | 4 | ENV LANG C.UTF-8 |
29 | 5 |
|
30 | | -# add a simple script that can auto-detect the appropriate JAVA_HOME value |
31 | | -# based on whether the JDK or only the JRE is installed |
32 | | -RUN { \ |
33 | | - echo '#!/bin/sh'; \ |
34 | | - echo 'set -e'; \ |
35 | | - echo; \ |
36 | | - echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \ |
37 | | - } > /usr/local/bin/docker-java-home \ |
38 | | - && chmod +x /usr/local/bin/docker-java-home |
| 6 | +ENV JAVA_HOME /usr/local/openjdk-11 |
| 7 | +ENV PATH $JAVA_HOME/bin:$PATH |
39 | 8 |
|
40 | | -# do some fancy footwork to create a JAVA_HOME that's cross-architecture-safe |
41 | | -RUN ln -svT "/usr/lib/jvm/java-11-openjdk-$(dpkg --print-architecture)" /docker-java-home |
42 | | -ENV JAVA_HOME /docker-java-home |
| 9 | +# backwards compatibility shim |
| 10 | +RUN { echo '#/bin/sh'; echo 'echo "$JAVA_HOME"'; } > /usr/local/bin/docker-java-home && chmod +x /usr/local/bin/docker-java-home && [ "$JAVA_HOME" = "$(docker-java-home)" ] |
43 | 11 |
|
| 12 | +# https://adoptopenjdk.net/upstream.html |
44 | 13 | ENV JAVA_VERSION 11.0.3 |
45 | | -ENV JAVA_DEBIAN_VERSION 11.0.3+1-1~bpo9+2 |
| 14 | +ENV JAVA_BASE_URL https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases/download/jdk-11.0.3%2B7/OpenJDK11U- |
| 15 | +ENV JAVA_URL_VERSION 11.0.3_7 |
| 16 | +# https://github.com/docker-library/openjdk/issues/320#issuecomment-494050246 |
46 | 17 |
|
47 | | -RUN set -ex; \ |
| 18 | +RUN set -eux; \ |
48 | 19 | \ |
49 | | -# deal with slim variants not having man page directories (which causes "update-alternatives" to fail) |
50 | | - if [ ! -d /usr/share/man/man1 ]; then \ |
51 | | - mkdir -p /usr/share/man/man1; \ |
52 | | - fi; \ |
53 | | - \ |
54 | | -# ca-certificates-java does not work on src:openjdk-11 with no-install-recommends: (https://bugs.debian.org/914860, https://bugs.debian.org/775775) |
55 | | -# /var/lib/dpkg/info/ca-certificates-java.postinst: line 56: java: command not found |
56 | | - ln -svT /docker-java-home/bin/java /usr/local/bin/java; \ |
| 20 | + dpkgArch="$(dpkg --print-architecture)"; \ |
| 21 | + case "$dpkgArch" in \ |
| 22 | + amd64) upstreamArch='x64' ;; \ |
| 23 | +# TODO filter out arm64 for openjdk:8 (https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/tag/jdk8u212-b04 vs https://github.com/AdoptOpenJDK/openjdk11-upstream-binaries/releases/tag/jdk-11.0.3%2B7) |
| 24 | + arm64) upstreamArch='aarch64' ;; \ |
| 25 | + *) echo >&2 "error: unsupported architecture: $dpkgArch" ;; \ |
| 26 | + esac; \ |
57 | 27 | \ |
| 28 | + savedAptMark="$(apt-mark showmanual)"; \ |
58 | 29 | apt-get update; \ |
59 | 30 | apt-get install -y --no-install-recommends \ |
60 | | - openjdk-11-jdk-headless="$JAVA_DEBIAN_VERSION" \ |
| 31 | + ca-certificates wget \ |
| 32 | + gnupg dirmngr \ |
61 | 33 | ; \ |
62 | 34 | rm -rf /var/lib/apt/lists/*; \ |
63 | 35 | \ |
64 | | - rm -v /usr/local/bin/java; \ |
| 36 | + wget -O openjdk.tgz.asc "${JAVA_BASE_URL}${upstreamArch}_linux_${JAVA_URL_VERSION}.tar.gz.sign"; \ |
| 37 | + wget -O openjdk.tgz "${JAVA_BASE_URL}${upstreamArch}_linux_${JAVA_URL_VERSION}.tar.gz" --progress=dot:giga; \ |
| 38 | + \ |
| 39 | + export GNUPGHOME="$(mktemp -d)"; \ |
| 40 | +# TODO find a good link for users to verify this key is right (https://mail.openjdk.java.net/pipermail/jdk-updates-dev/2019-April/000951.html is one of the only mentions of it I can find); perhaps a note added to https://adoptopenjdk.net/upstream.html would make sense? |
| 41 | + gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys CA5F11C6CE22644D42C6AC4492EF8D39DC13168F; \ |
| 42 | + gpg --batch --verify openjdk.tgz.asc openjdk.tgz; \ |
| 43 | + rm -rf "$GNUPGHOME"; \ |
65 | 44 | \ |
66 | | -# ca-certificates-java does not work on src:openjdk-11: (https://bugs.debian.org/914424, https://bugs.debian.org/894979, https://salsa.debian.org/java-team/ca-certificates-java/commit/813b8c4973e6c4bb273d5d02f8d4e0aa0b226c50#d4b95d176f05e34cd0b718357c532dc5a6d66cd7_54_56) |
67 | | - keytool -importkeystore -srckeystore /etc/ssl/certs/java/cacerts -destkeystore /etc/ssl/certs/java/cacerts.jks -deststoretype JKS -srcstorepass changeit -deststorepass changeit -noprompt; \ |
68 | | - mv /etc/ssl/certs/java/cacerts.jks /etc/ssl/certs/java/cacerts; \ |
69 | | - /var/lib/dpkg/info/ca-certificates-java.postinst configure; \ |
| 45 | + mkdir -p "$JAVA_HOME"; \ |
| 46 | + tar --extract --file openjdk.tgz --directory "$JAVA_HOME" --strip-components 1; \ |
| 47 | + rm openjdk.tgz*; \ |
70 | 48 | \ |
71 | | -# verify that "docker-java-home" returns what we expect |
72 | | - [ "$(readlink -f "$JAVA_HOME")" = "$(docker-java-home)" ]; \ |
| 49 | +# TODO strip "demo" and "man" folders? |
73 | 50 | \ |
74 | | -# update-alternatives so that future installs of other OpenJDK versions don't change /usr/bin/java |
75 | | - update-alternatives --get-selections | awk -v home="$(readlink -f "$JAVA_HOME")" 'index($3, home) == 1 { $2 = "manual"; print | "update-alternatives --set-selections" }'; \ |
76 | | -# ... and verify that it actually worked for one of the alternatives we care about |
77 | | - update-alternatives --query java | grep -q 'Status: manual' |
| 51 | + apt-mark auto '.*' > /dev/null; \ |
| 52 | + [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \ |
| 53 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ |
| 54 | + \ |
| 55 | +# basic smoke test |
| 56 | + javac --version; \ |
| 57 | + java --version |
78 | 58 |
|
79 | | -# https://docs.oracle.com/javase/10/tools/jshell.htm |
80 | | -# https://en.wikipedia.org/wiki/JShell |
| 59 | +# "jshell" is an interactive REPL for Java (see https://en.wikipedia.org/wiki/JShell) |
81 | 60 | CMD ["jshell"] |
82 | | - |
83 | | -# If you're reading this and have any feedback on how this image could be |
84 | | -# improved, please open an issue or a pull request so we can discuss it! |
85 | | -# |
86 | | -# https://github.com/docker-library/openjdk/issues |
0 commit comments