Skip to content

Commit

Permalink
use multistage build dockerfiles for JDK24+
Browse files Browse the repository at this point in the history
  • Loading branch information
gdams committed Oct 22, 2024
1 parent 699d31d commit 511753b
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 2 deletions.
File renamed without changes.
47 changes: 47 additions & 0 deletions docker_templates/alpine-linux.multistage.Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% include 'partials/license.j2' %}

FROM {{ base_image }} AS build

{% include 'partials/nix-env.j2' %}

RUN set -eux; \
apk add --no-cache \
# gnupg required to verify the signature
gnupg

{% include 'partials/java-version.j2' %}

{% include 'partials/multi-arch-install.j2' %}

FROM {{ base_image }}

ENV JAVA_HOME=/opt/java/openjdk

RUN set -eux; \
apk add --no-cache \
# java.lang.UnsatisfiedLinkError: libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
# java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
# https://github.com/docker-library/openjdk/pull/235#issuecomment-424466077
fontconfig ttf-dejavu \
# utilities for keeping Alpine and OpenJDK CA certificates in sync
# https://github.com/adoptium/containers/issues/293
ca-certificates p11-kit-trust \
# locales ensures proper character encoding and locale-specific behaviors using en_US.UTF-8
musl-locales musl-locales-lang \
{%- include 'partials/binutils.j2' %}
tzdata \
# Contains `csplit` used for splitting multiple certificates in one file to multiple files, since keytool can
# only import one at a time.
coreutils \
# Needed to extract CN and generate aliases for certificates
openssl \
; \
rm -rf /var/cache/apk/*

{% include 'partials/java-version.j2' %}

COPY --from=build $JAVA_HOME $JAVA_HOME

{% include 'partials/version-check.j2' %}
{% include 'partials/entrypoint.j2' %}
{% include 'partials/jshell.j2' %}
41 changes: 41 additions & 0 deletions docker_templates/ubi9-minimal.multistage.Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% include 'partials/license.j2' %}

FROM {{ base_image }} AS build

ENV JAVA_HOME=/opt/java/openjdk

RUN set -eux; \
microdnf install -y \
gzip \
tar \
wget

{% include 'partials/multi-arch-install.j2' %}

FROM {{ base_image }}

{% include 'partials/nix-env.j2' %}

RUN set -eux; \
microdnf install -y \
# Required for jlink
binutils \
tzdata \
# utilities for keeping UBI and OpenJDK CA certificates in sync
# https://github.com/adoptium/containers/issues/293
ca-certificates \
# java.lang.UnsatisfiedLinkError: libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
# java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
# https://github.com/docker-library/openjdk/pull/235#issuecomment-424466077
fontconfig \
glibc-langpack-en \
; \
microdnf clean all

{% include 'partials/java-version.j2' %}

COPY --from=build $JAVA_HOME $JAVA_HOME

{% include 'partials/version-check.j2' %}
{% include 'partials/entrypoint.j2' %}
{% include 'partials/jshell.j2' %}
58 changes: 58 additions & 0 deletions docker_templates/ubuntu.multistage.Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{% include 'partials/license.j2' %}

FROM {{ base_image }} AS build

ENV JAVA_HOME=/opt/java/openjdk

RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# required for SSL certificate checking
ca-certificates \
# gnupg required to verify the signature
gnupg \
wget

{% include 'partials/multi-arch-install.j2' %}

FROM {{ base_image }}

{% include 'partials/nix-env.j2' %}

RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# java.lang.UnsatisfiedLinkError: libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
# java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager
# https://github.com/docker-library/openjdk/pull/235#issuecomment-424466077
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/*

{% include 'partials/java-version.j2' %}

COPY --from=build $JAVA_HOME $JAVA_HOME

RUN set -eux; \
# 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; \
{% if version|int >= 11 -%}
ldconfig; \
# https://github.com/docker-library/openjdk/issues/212#issuecomment-420979840
# https://openjdk.java.net/jeps/341
java -Xshare:dump;
{% else -%}
ldconfig;
{% endif %}
{% include 'partials/version-check.j2' %}
{% include 'partials/entrypoint.j2' %}
{% include 'partials/jshell.j2' %}
7 changes: 5 additions & 2 deletions generate_dockerfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def archHelper(arch, os_name):


# Load the YAML configuration
with open("config/hotspot.yml", "r") as file:
with open("config/temurin.yml", "r") as file:
config = yaml.safe_load(file)

# Iterate through OS families and then configurations
Expand All @@ -82,10 +82,13 @@ def archHelper(arch, os_name):

# Define the path for the template based on OS
template_name = f"{os_name}.Dockerfile.j2"
template = env.get_template(template_name)

# Create output directories if they don't exist
for version in versions:
# For JDK24+ use multistage build
if version >= 24 and os_family != "windows":
template_name = f"{os_name}.multistage.Dockerfile.j2"
template = env.get_template(template_name)
# if deprecated is set and version is greater than or equal to deprecated, skip
if deprecated and version >= deprecated:
continue
Expand Down

0 comments on commit 511753b

Please sign in to comment.