From ab4932741b998febc1e5063300b6d1bc77707b09 Mon Sep 17 00:00:00 2001 From: George Adams Date: Wed, 25 Oct 2023 23:19:57 +0100 Subject: [PATCH] further dockerfile refactor enhancements --- docker_templates/alpine-linux.Dockerfile.j2 | 22 ++++++++---- docker_templates/centos.Dockerfile.j2 | 34 ++++++++----------- docker_templates/nanoserver.Dockerfile.j2 | 7 +++- docker_templates/partials/arch-variable.j2 | 7 ++++ docker_templates/partials/binutils.j2 | 5 +++ .../partials/multi-arch-install.j2 | 2 ++ .../partials/version-check-windows.j2 | 11 ++---- docker_templates/partials/version-check.j2 | 6 ++-- docker_templates/ubi9-minimal.Dockerfile.j2 | 16 +++++++-- docker_templates/ubuntu.Dockerfile.j2 | 32 +++++++---------- 10 files changed, 81 insertions(+), 61 deletions(-) create mode 100644 docker_templates/partials/arch-variable.j2 create mode 100644 docker_templates/partials/binutils.j2 diff --git a/docker_templates/alpine-linux.Dockerfile.j2 b/docker_templates/alpine-linux.Dockerfile.j2 index eeffbc49a..fbe694aa5 100644 --- a/docker_templates/alpine-linux.Dockerfile.j2 +++ b/docker_templates/alpine-linux.Dockerfile.j2 @@ -5,16 +5,26 @@ FROM {{ base_image }} {% include 'partials/nix-env.j2' %} RUN set -eux; \ - # fontconfig and ttf-dejavu added to support serverside image generation by Java programs - # java-cacerts added to support adding CA certificates to the Java keystore - # bash is required for the entrypoint script (see https://github.com/adoptium/containers/issues/415) - apk add --no-cache fontconfig java-cacerts bash libretls musl-locales musl-locales-lang ttf-dejavu tzdata zlib; \ + apk add --no-cache \ + # bash is required for the entrypoint script + # see https://github.com/adoptium/containers/issues/415 + bash \ + # fontconfig and ttf-dejavu added to support serverside image generation by Java programs + fontconfig ttf-dejavu \ + # java-cacerts added to support adding CA certificates to the Java keystore + java-cacerts \ + # fixes issues with apk del apk-tools + # see https://github.com/adoptium/containers/issues/136 + libretls zlib \ + # locales ensures proper character encoding and locale-specific behaviors using en_US.UTF-8 + musl-locales musl-locales-lang \ +{% include 'partials/binutils.j2' -%} + tzdata \ + ; \ rm -rf /var/cache/apk/* ENV JAVA_VERSION {{ java_version }} -RUN set -eux; \ - ARCH="$(apk --print-arch)"; \ {% include 'partials/multi-arch-install.j2' %} {% include 'partials/version-check.j2' %} diff --git a/docker_templates/centos.Dockerfile.j2 b/docker_templates/centos.Dockerfile.j2 index f28e53fb7..c4d65146e 100644 --- a/docker_templates/centos.Dockerfile.j2 +++ b/docker_templates/centos.Dockerfile.j2 @@ -6,31 +6,25 @@ FROM {{ base_image }} RUN set -eux; \ yum install -y \ - gzip \ - tar \ - {% if version|int < 22 -%} - # curl required for historical reasons, see https://github.com/adoptium/containers/issues/255 - curl \ - {% endif -%} - wget \ - tzdata \ - openssl \ - # utilities for keeping Ubuntu and OpenJDK CA certificates in sync - # https://github.com/adoptium/containers/issues/293 - ca-certificates \ - fontconfig \ - {% if version|int >= 13 -%} - # jlink --strip-debug on 13+ needs objcopy: https://github.com/docker-library/openjdk/issues/351 - # Error: java.io.IOException: Cannot run program "objcopy": error=2, No such file or directory - binutils \ - {% endif -%} + gzip \ + tar \ + {% if version|int < 22 -%} + # curl required for historical reasons, see https://github.com/adoptium/containers/issues/255 + curl \ + {% endif -%} + wget \ + tzdata \ + openssl \ + # utilities for keeping Centos and OpenJDK CA certificates in sync + # https://github.com/adoptium/containers/issues/293 + ca-certificates \ +{% include 'partials/binutils.j2' -%} + fontconfig \ ; \ rm -rf /var/cache/yum ENV JAVA_VERSION {{ java_version }} -RUN set -eux; \ - ARCH="$(objdump="$(command -v objdump)" && objdump --file-headers "$objdump" | awk -F '[:,]+[[:space:]]+' '$1 == "architecture" { print $2 }')"; \ {% include 'partials/multi-arch-install.j2' %} {% include 'partials/version-check.j2' %} diff --git a/docker_templates/nanoserver.Dockerfile.j2 b/docker_templates/nanoserver.Dockerfile.j2 index d40f7fd9b..7341568bc 100644 --- a/docker_templates/nanoserver.Dockerfile.j2 +++ b/docker_templates/nanoserver.Dockerfile.j2 @@ -16,5 +16,10 @@ USER ContainerUser COPY --from=eclipse-temurin:{{ arch_data.copy_from }} $JAVA_HOME $JAVA_HOME -{% include 'partials/version-check.j2' %} +RUN echo Verifying install ... \ + {% if image_type == "jdk" -%} + && echo javac {% if version|int >= 11 %}--{% else %}-{% endif %}version && javac {% if version|int >= 11 %}--{% else %}-{% endif %}version \ + {% endif -%} + && echo java {% if version|int >= 11 %}--{% else %}-{% endif %}version && java {% if version|int >= 11 %}--{% else %}-{% endif %}version \ + && echo Complete. {% include 'partials/jshell.j2' %} \ No newline at end of file diff --git a/docker_templates/partials/arch-variable.j2 b/docker_templates/partials/arch-variable.j2 new file mode 100644 index 000000000..0256e81e9 --- /dev/null +++ b/docker_templates/partials/arch-variable.j2 @@ -0,0 +1,7 @@ +{%- if os == "ubuntu" %} + ARCH="$(dpkg --print-architecture)"; \ +{%- elif os == "alpine-linux" %} + ARCH="$(apk --print-arch)"; \ +{%- elif os == "centos" or os == "ubi9-minimal" %} + ARCH="$(objdump="$(command -v objdump)" && objdump --file-headers "$objdump" | awk -F '[:,]+[[:space:]]+' '$1 == "architecture" { print $2 }')"; \ +{%- endif -%} \ No newline at end of file diff --git a/docker_templates/partials/binutils.j2 b/docker_templates/partials/binutils.j2 new file mode 100644 index 000000000..9a1aa8da3 --- /dev/null +++ b/docker_templates/partials/binutils.j2 @@ -0,0 +1,5 @@ + {% if version|int >= 13 -%} + # jlink --strip-debug on 13+ needs objcopy: https://github.com/docker-library/openjdk/issues/351 + # Error: java.io.IOException: Cannot run program "objcopy": error=2, No such file or directory + binutils \ + {% endif -%} \ No newline at end of file diff --git a/docker_templates/partials/multi-arch-install.j2 b/docker_templates/partials/multi-arch-install.j2 index b315f1358..1b32f8a77 100644 --- a/docker_templates/partials/multi-arch-install.j2 +++ b/docker_templates/partials/multi-arch-install.j2 @@ -1,3 +1,5 @@ +RUN set -eux; \ +{%- include 'partials/arch-variable.j2' %} case "${ARCH}" in \ {% for architecture, details in arch_data.items() -%} {{ architecture }}) \ diff --git a/docker_templates/partials/version-check-windows.j2 b/docker_templates/partials/version-check-windows.j2 index 780eb25a4..fa4c2daac 100644 --- a/docker_templates/partials/version-check-windows.j2 +++ b/docker_templates/partials/version-check-windows.j2 @@ -1,14 +1,7 @@ RUN Write-Host 'Verifying install ...'; \ - {% if version|int >= 11 -%} {% if image_type == "jdk" -%} - Write-Host 'javac --version'; javac --version; \ - {% endif -%} - Write-Host 'java --version'; java --version; \ - {% else -%} - {% if image_type == "jdk" -%} - Write-Host 'javac -version'; javac -version; \ - {% endif -%} - Write-Host 'java -version'; java -version; \ + Write-Host 'javac {% if version|int >= 11 %}--{% else %}-{% endif %}version'; javac {% if version|int >= 11 %}--{% else %}-{% endif %}version; \ {% endif -%} + Write-Host 'java {% if version|int >= 11 %}--{% else %}-{% endif %}version'; java {% if version|int >= 11 %}--{% else %}-{% endif %}version; \ \ Write-Host 'Complete.' \ No newline at end of file diff --git a/docker_templates/partials/version-check.j2 b/docker_templates/partials/version-check.j2 index 5ed2fe14a..50afca768 100644 --- a/docker_templates/partials/version-check.j2 +++ b/docker_templates/partials/version-check.j2 @@ -1,6 +1,6 @@ -RUN {% if os_family != "windows" %}set -eux; \ - {% else %}{% endif %}echo "Verifying install ..."; \ - {% if os_family != "windows" and image_type == "jdk" and version|int >= 11 -%} +RUN set -eux; \ + echo "Verifying install ..."; \ + {% if image_type == "jdk" and version|int >= 11 -%} fileEncoding="$(echo 'System.out.println(System.getProperty("file.encoding"))' | jshell -s -)"; [ "$fileEncoding" = 'UTF-8' ]; rm -rf ~/.java; \ {% endif -%} {% if image_type == "jdk" -%} diff --git a/docker_templates/ubi9-minimal.Dockerfile.j2 b/docker_templates/ubi9-minimal.Dockerfile.j2 index 9a2ebbfa3..38dd86c75 100644 --- a/docker_templates/ubi9-minimal.Dockerfile.j2 +++ b/docker_templates/ubi9-minimal.Dockerfile.j2 @@ -5,13 +5,23 @@ FROM {{ base_image }} {% include 'partials/nix-env.j2' %} RUN set -eux; \ - microdnf install -y binutils tzdata openssl wget ca-certificates fontconfig glibc-langpack-en gzip tar; \ + microdnf install -y \ + gzip \ + tar \ +{% include 'partials/binutils.j2' -%} + tzdata \ + openssl \ + wget \ + # utilities for keeping UBI and OpenJDK CA certificates in sync + # https://github.com/adoptium/containers/issues/293 + ca-certificates \ + fontconfig \ + glibc-langpack-en \ + ; \ microdnf clean all ENV JAVA_VERSION {{ java_version }} -RUN set -eux; \ - ARCH="$(objdump="$(command -v objdump)" && objdump --file-headers "$objdump" | awk -F '[:,]+[[:space:]]+' '$1 == "architecture" { print $2 }')"; \ {% include 'partials/multi-arch-install.j2' %} {% include 'partials/version-check.j2' %} diff --git a/docker_templates/ubuntu.Dockerfile.j2 b/docker_templates/ubuntu.Dockerfile.j2 index 8991dc917..8d8531b24 100644 --- a/docker_templates/ubuntu.Dockerfile.j2 +++ b/docker_templates/ubuntu.Dockerfile.j2 @@ -7,23 +7,19 @@ FROM {{ base_image }} RUN set -eux; \ apt-get update; \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - {% if version|int < 22 -%} - # curl required for historical reasons, see https://github.com/adoptium/containers/issues/255 - curl \ - {% endif -%} - wget \ - fontconfig \ - # utilities for keeping Ubuntu and OpenJDK CA certificates in sync - # https://github.com/adoptium/containers/issues/293 - ca-certificates p11-kit \ - {% if version|int >= 13 -%} - # jlink --strip-debug on 13+ needs objcopy: https://github.com/docker-library/openjdk/issues/351 - # Error: java.io.IOException: Cannot run program "objcopy": error=2, No such file or directory - binutils \ - {% endif -%} - tzdata \ - # locales ensures proper character encoding and locale-specific behaviors using en_US.UTF-8 - locales \ + {% if version|int < 22 -%} + # curl required for historical reasons, see https://github.com/adoptium/containers/issues/255 + curl \ + {% endif -%} + wget \ + fontconfig \ + # utilities for keeping Ubuntu and OpenJDK CA certificates in sync + # https://github.com/adoptium/containers/issues/293 + ca-certificates p11-kit \ +{% include 'partials/binutils.j2' -%} + tzdata \ + # locales ensures proper character encoding and locale-specific behaviors using en_US.UTF-8 + locales \ ; \ echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen; \ locale-gen en_US.UTF-8; \ @@ -31,8 +27,6 @@ RUN set -eux; \ ENV JAVA_VERSION {{ java_version }} -RUN set -eux; \ - ARCH="$(dpkg --print-architecture)"; \ {% include 'partials/multi-arch-install.j2' %} \ # https://github.com/docker-library/openjdk/issues/331#issuecomment-498834472 find "$JAVA_HOME/lib" -name '*.so' -exec dirname '{}' ';' | sort -u > /etc/ld.so.conf.d/docker-openjdk.conf; \