Skip to content

Commit 77c0766

Browse files
committed
Add a "docker-java-home" script and use it to verify our hard-coded "JAVA_HOME" values during build
1 parent e856a9e commit 77c0766

File tree

9 files changed

+114
-9
lines changed

9 files changed

+114
-9
lines changed

openjdk-6-jdk/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
1616
# Default to UTF-8 file.encoding
1717
ENV LANG C.UTF-8
1818

19+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
20+
# based on whether the JDK or only the JRE is installed
21+
RUN { \
22+
echo '#!/bin/bash'; \
23+
echo 'set -e'; \
24+
echo; \
25+
echo 'dirname "/usr/libexec/eselect-java"'; \
26+
} > /usr/local/bin/docker-java-home \
27+
&& chmod +x /usr/local/bin/docker-java-home
28+
1929
ENV JAVA_HOME /usr/lib/jvm/java-6-openjdk-amd64
2030

2131
ENV JAVA_VERSION 6b36
@@ -25,7 +35,8 @@ RUN set -x \
2535
&& apt-get update \
2636
&& apt-get install -y \
2737
openjdk-6-jdk="$JAVA_DEBIAN_VERSION" \
28-
&& rm -rf /var/lib/apt/lists/*
38+
&& rm -rf /var/lib/apt/lists/* \
39+
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
2940

3041
# If you're reading this and have any feedback on how this image could be
3142
# improved, please open an issue or a pull request so we can discuss it!

openjdk-6-jre/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
1616
# Default to UTF-8 file.encoding
1717
ENV LANG C.UTF-8
1818

19+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
20+
# based on whether the JDK or only the JRE is installed
21+
RUN { \
22+
echo '#!/bin/bash'; \
23+
echo 'set -e'; \
24+
echo; \
25+
echo 'dirname "/usr/libexec/eselect-java"'; \
26+
} > /usr/local/bin/docker-java-home \
27+
&& chmod +x /usr/local/bin/docker-java-home
28+
1929
ENV JAVA_HOME /usr/lib/jvm/java-6-openjdk-amd64/jre
2030

2131
ENV JAVA_VERSION 6b36
@@ -25,7 +35,8 @@ RUN set -x \
2535
&& apt-get update \
2636
&& apt-get install -y \
2737
openjdk-6-jre-headless="$JAVA_DEBIAN_VERSION" \
28-
&& rm -rf /var/lib/apt/lists/*
38+
&& rm -rf /var/lib/apt/lists/* \
39+
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
2940

3041
# If you're reading this and have any feedback on how this image could be
3142
# improved, please open an issue or a pull request so we can discuss it!

openjdk-7-jdk/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
1616
# Default to UTF-8 file.encoding
1717
ENV LANG C.UTF-8
1818

19+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
20+
# based on whether the JDK or only the JRE is installed
21+
RUN { \
22+
echo '#!/bin/bash'; \
23+
echo 'set -e'; \
24+
echo; \
25+
echo 'dirname "/usr/libexec/eselect-java"'; \
26+
} > /usr/local/bin/docker-java-home \
27+
&& chmod +x /usr/local/bin/docker-java-home
28+
1929
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
2030

2131
ENV JAVA_VERSION 7u91
@@ -25,7 +35,8 @@ RUN set -x \
2535
&& apt-get update \
2636
&& apt-get install -y \
2737
openjdk-7-jdk="$JAVA_DEBIAN_VERSION" \
28-
&& rm -rf /var/lib/apt/lists/*
38+
&& rm -rf /var/lib/apt/lists/* \
39+
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
2940

3041
# If you're reading this and have any feedback on how this image could be
3142
# improved, please open an issue or a pull request so we can discuss it!

openjdk-7-jre/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
1616
# Default to UTF-8 file.encoding
1717
ENV LANG C.UTF-8
1818

19+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
20+
# based on whether the JDK or only the JRE is installed
21+
RUN { \
22+
echo '#!/bin/bash'; \
23+
echo 'set -e'; \
24+
echo; \
25+
echo 'dirname "/usr/libexec/eselect-java"'; \
26+
} > /usr/local/bin/docker-java-home \
27+
&& chmod +x /usr/local/bin/docker-java-home
28+
1929
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64/jre
2030

2131
ENV JAVA_VERSION 7u91
@@ -25,7 +35,8 @@ RUN set -x \
2535
&& apt-get update \
2636
&& apt-get install -y \
2737
openjdk-7-jre-headless="$JAVA_DEBIAN_VERSION" \
28-
&& rm -rf /var/lib/apt/lists/*
38+
&& rm -rf /var/lib/apt/lists/* \
39+
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
2940

3041
# If you're reading this and have any feedback on how this image could be
3142
# improved, please open an issue or a pull request so we can discuss it!

openjdk-8-jdk/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ RUN echo 'deb http://httpredir.debian.org/debian jessie-backports main' > /etc/a
1818
# Default to UTF-8 file.encoding
1919
ENV LANG C.UTF-8
2020

21+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
22+
# based on whether the JDK or only the JRE is installed
23+
RUN { \
24+
echo '#!/bin/bash'; \
25+
echo 'set -e'; \
26+
echo; \
27+
echo 'dirname "/usr/libexec/eselect-java"'; \
28+
} > /usr/local/bin/docker-java-home \
29+
&& chmod +x /usr/local/bin/docker-java-home
30+
2131
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
2232

2333
ENV JAVA_VERSION 8u66
@@ -32,7 +42,8 @@ RUN set -x \
3242
&& apt-get install -y \
3343
openjdk-8-jdk="$JAVA_DEBIAN_VERSION" \
3444
ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
35-
&& rm -rf /var/lib/apt/lists/*
45+
&& rm -rf /var/lib/apt/lists/* \
46+
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
3647

3748
# see CA_CERTIFICATES_JAVA_VERSION notes above
3849
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure

openjdk-8-jre/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ RUN echo 'deb http://httpredir.debian.org/debian jessie-backports main' > /etc/a
1818
# Default to UTF-8 file.encoding
1919
ENV LANG C.UTF-8
2020

21+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
22+
# based on whether the JDK or only the JRE is installed
23+
RUN { \
24+
echo '#!/bin/bash'; \
25+
echo 'set -e'; \
26+
echo; \
27+
echo 'dirname "/usr/libexec/eselect-java"'; \
28+
} > /usr/local/bin/docker-java-home \
29+
&& chmod +x /usr/local/bin/docker-java-home
30+
2131
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/jre
2232

2333
ENV JAVA_VERSION 8u66
@@ -32,7 +42,8 @@ RUN set -x \
3242
&& apt-get install -y \
3343
openjdk-8-jre-headless="$JAVA_DEBIAN_VERSION" \
3444
ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
35-
&& rm -rf /var/lib/apt/lists/*
45+
&& rm -rf /var/lib/apt/lists/* \
46+
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
3647

3748
# see CA_CERTIFICATES_JAVA_VERSION notes above
3849
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure

openjdk-9-jdk/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ RUN echo 'deb http://httpredir.debian.org/debian experimental main' > /etc/apt/s
1818
# Default to UTF-8 file.encoding
1919
ENV LANG C.UTF-8
2020

21+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
22+
# based on whether the JDK or only the JRE is installed
23+
RUN { \
24+
echo '#!/bin/bash'; \
25+
echo 'set -e'; \
26+
echo; \
27+
echo 'dirname "/usr/libexec/eselect-java"'; \
28+
} > /usr/local/bin/docker-java-home \
29+
&& chmod +x /usr/local/bin/docker-java-home
30+
2131
ENV JAVA_HOME /usr/lib/jvm/java-9-openjdk-amd64
2232

2333
ENV JAVA_VERSION 9~b96
@@ -32,7 +42,8 @@ RUN set -x \
3242
&& apt-get install -y \
3343
openjdk-9-jdk="$JAVA_DEBIAN_VERSION" \
3444
ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
35-
&& rm -rf /var/lib/apt/lists/*
45+
&& rm -rf /var/lib/apt/lists/* \
46+
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
3647

3748
# see CA_CERTIFICATES_JAVA_VERSION notes above
3849
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure

openjdk-9-jre/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ RUN echo 'deb http://httpredir.debian.org/debian experimental main' > /etc/apt/s
1818
# Default to UTF-8 file.encoding
1919
ENV LANG C.UTF-8
2020

21+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
22+
# based on whether the JDK or only the JRE is installed
23+
RUN { \
24+
echo '#!/bin/bash'; \
25+
echo 'set -e'; \
26+
echo; \
27+
echo 'dirname "/usr/libexec/eselect-java"'; \
28+
} > /usr/local/bin/docker-java-home \
29+
&& chmod +x /usr/local/bin/docker-java-home
30+
2131
ENV JAVA_HOME /usr/lib/jvm/java-9-openjdk-amd64/jre
2232

2333
ENV JAVA_VERSION 9~b96
@@ -32,7 +42,8 @@ RUN set -x \
3242
&& apt-get install -y \
3343
openjdk-9-jre-headless="$JAVA_DEBIAN_VERSION" \
3444
ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
35-
&& rm -rf /var/lib/apt/lists/*
45+
&& rm -rf /var/lib/apt/lists/* \
46+
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
3647

3748
# see CA_CERTIFICATES_JAVA_VERSION notes above
3849
RUN /var/lib/dpkg/info/ca-certificates-java.postinst configure

update.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ for version in "${versions[@]}"; do
8383
8484
# Default to UTF-8 file.encoding
8585
ENV LANG C.UTF-8
86+
EOD
87+
88+
cat >> "$version/Dockerfile" <<EOD
89+
90+
# add a simple script that can auto-detect the appropriate JAVA_HOME value
91+
# based on whether the JDK or only the JRE is installed
92+
RUN { \\
93+
echo '#!/bin/bash'; \\
94+
echo 'set -e'; \\
95+
echo; \\
96+
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \\
97+
} > /usr/local/bin/docker-java-home \\
98+
&& chmod +x /usr/local/bin/docker-java-home
99+
EOD
100+
101+
cat >> "$version/Dockerfile" <<-EOD
86102
87103
ENV JAVA_HOME $javaHome
88104
@@ -112,7 +128,8 @@ EOD
112128
EOD
113129
fi
114130
cat >> "$version/Dockerfile" <<EOD
115-
&& rm -rf /var/lib/apt/lists/*
131+
&& rm -rf /var/lib/apt/lists/* \\
132+
&& [ "\$JAVA_HOME" = "\$(docker-java-home)" ]
116133
EOD
117134

118135
if [ "$needCaHack" ]; then

0 commit comments

Comments
 (0)