Skip to content

Commit

Permalink
further dockerfile refactor enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
gdams committed Oct 25, 2023
1 parent 585b61f commit ab49327
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 61 deletions.
22 changes: 16 additions & 6 deletions docker_templates/alpine-linux.Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}
Expand Down
34 changes: 14 additions & 20 deletions docker_templates/centos.Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}
Expand Down
7 changes: 6 additions & 1 deletion docker_templates/nanoserver.Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}
7 changes: 7 additions & 0 deletions docker_templates/partials/arch-variable.j2
Original file line number Diff line number Diff line change
@@ -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 -%}
5 changes: 5 additions & 0 deletions docker_templates/partials/binutils.j2
Original file line number Diff line number Diff line change
@@ -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 -%}
2 changes: 2 additions & 0 deletions docker_templates/partials/multi-arch-install.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
RUN set -eux; \
{%- include 'partials/arch-variable.j2' %}
case "${ARCH}" in \
{% for architecture, details in arch_data.items() -%}
{{ architecture }}) \
Expand Down
11 changes: 2 additions & 9 deletions docker_templates/partials/version-check-windows.j2
Original file line number Diff line number Diff line change
@@ -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.'
6 changes: 3 additions & 3 deletions docker_templates/partials/version-check.j2
Original file line number Diff line number Diff line change
@@ -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" -%}
Expand Down
16 changes: 13 additions & 3 deletions docker_templates/ubi9-minimal.Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}
Expand Down
32 changes: 13 additions & 19 deletions docker_templates/ubuntu.Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,26 @@ 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; \
rm -rf /var/lib/apt/lists/*

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; \
Expand Down

0 comments on commit ab49327

Please sign in to comment.