Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 12 additions & 63 deletions Dockerfile-linux.template
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
{{
def is_alpine:
env.variant | startswith("alpine")
;
def alpine_version:
env.variant | ltrimstr("alpine")
-}}
{{
def is_oracle:
env.variant | startswith("oraclelinux")
;
def oracle_version:
env.variant | ltrimstr("oraclelinux")
-}}
{{
def is_debian:
is_alpine or is_oracle | not
;
def is_debian_slim:
is_debian and (env.variant | startswith("slim-"))
env.variant | startswith("slim-")
;
def debian_suite:
env.variant | ltrimstr("slim-")
-}}
{{
if is_alpine then (
-}}
FROM alpine:{{ alpine_version }}

RUN apk add --no-cache java-cacerts

ENV JAVA_HOME /opt/openjdk-{{ env.version }}
{{
) elif is_oracle then (
if is_oracle then (
-}}
FROM oraclelinux:{{ oracle_version }}-slim

Expand All @@ -57,13 +38,7 @@ FROM {{
if is_debian_slim then
"debian:" + debian_suite + "-slim"
else
"buildpack-deps:" + debian_suite + (
if env.javaType == "jdk" then
"-scm"
else
"-curl"
end
)
"buildpack-deps:" + debian_suite + "-scm"
end
}}

Expand Down Expand Up @@ -96,30 +71,18 @@ ENV JAVA_HOME /usr/local/openjdk-{{ env.version }}
-}}
ENV PATH $JAVA_HOME/bin:$PATH

{{ if is_alpine then "" else ( -}}
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8

{{ ) end -}}
{{ def java_version: if is_alpine then .alpine.version else .version end -}}
# https://jdk.java.net/
# >
# > Java Development Kit builds, from Oracle
# >
ENV JAVA_VERSION {{ java_version }}
{{ if is_alpine then ( -}}
# "For Alpine Linux, builds are produced on a reduced schedule and may not be in sync with the other platforms."
{{ ) else "" end -}}
ENV JAVA_VERSION {{ .version }}

{{
def arches:
if is_alpine then .alpine else . end
| .[env.javaType].arches
;
def get_arch_command:
if is_alpine then
"apk --print-arch"
elif is_oracle then
if is_oracle then
"rpm --query --queryformat='%{ARCH}' rpm"
else
"dpkg --print-architecture"
Expand All @@ -131,10 +94,7 @@ ENV JAVA_VERSION {{ java_version }}
# output is a shell "case" expression for matching the output of running "get_arch_command"
# - "i[3456]86", "aarch64", "x86_64", etc
. as $bashbrewArch
| if is_alpine then {
amd64: "x86_64",
arm64v8: "aarch64",
} elif is_oracle then {
| if is_oracle then {
amd64: "x86_64",
arm64v8: "aarch64",
} else {
Expand All @@ -148,11 +108,7 @@ ENV JAVA_VERSION {{ java_version }}
if is_oracle then
"curl -fL -o"
else
[
"wget",
if is_alpine then empty else "--progress=dot:giga" end,
"-O"
] | join(" ")
"wget --progress=dot:giga -O"
end
-}}
RUN set -eux; \
Expand All @@ -161,7 +117,8 @@ RUN set -eux; \
case "$arch" in \
{{
[
arches | to_entries[]
.arches
| to_entries[]
| select(.key | startswith("windows-") | not)
| .key as $bashbrewArch | .value
| (
Expand Down Expand Up @@ -189,8 +146,8 @@ RUN set -eux; \
\
{{ ) else "" end -}}
{{ wget_command }} openjdk.tgz "$downloadUrl"; \
{{ if [ arches[] ] | any(has("sha256")) then ( -}}
echo "$downloadSha256 *openjdk.tgz" | sha256sum {{ if is_alpine then "-c" else "--strict --check" end }} -; \
{{ if .arches | any(has("sha256")) then ( -}}
echo "$downloadSha256 *openjdk.tgz" | sha256sum --strict --check -; \
{{ ) else "" end -}}
\
mkdir -p "$JAVA_HOME"; \
Expand All @@ -208,11 +165,7 @@ RUN set -eux; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
\
{{ ) else "" end -}}
{{ if is_alpine then ( -}}
rm -rf "$JAVA_HOME/lib/security/cacerts"; \
# see "java-cacerts" package installed above (which maintains "/etc/ssl/certs/java/cacerts" for us)
ln -sT /etc/ssl/certs/java/cacerts "$JAVA_HOME/lib/security/cacerts"; \
{{ ) elif is_oracle then ( -}}
{{ if is_oracle then ( -}}
rm -rf "$JAVA_HOME/lib/security/cacerts"; \
# see "update-ca-trust" script which creates/maintains this cacerts bundle
ln -sT /etc/pki/ca-trust/extracted/java/cacerts "$JAVA_HOME/lib/security/cacerts"; \
Expand Down Expand Up @@ -249,13 +202,9 @@ RUN set -eux; \
java -Xshare:dump; \
\
# basic smoke test
{{ if env.javaType == "jdk" then ( -}}
fileEncoding="$(echo 'System.out.println(System.getProperty("file.encoding"))' | jshell -s -)"; [ "$fileEncoding" = 'UTF-8' ]; rm -rf ~/.java; \
javac --version; \
java --version

# "jshell" is an interactive REPL for Java (see https://en.wikipedia.org/wiki/JShell)
CMD ["jshell"]
{{ ) else ( -}}
java --version
{{ ) end -}}
35 changes: 20 additions & 15 deletions Dockerfile-windows.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
FROM mcr.microsoft.com/windows/{{ env.windowsVariant }}:{{ env.windowsRelease }}
{{
def windows_variant: # "servercore", "nanoserver"
env.variant
| split("/")[-1]
| split("-")[0]
| ltrimstr("windows")
;
def windows_release: # "ltsc2025", "ltsc2022"
env.variant
| split("-")[-1]
-}}
FROM mcr.microsoft.com/windows/{{ windows_variant }}:{{ windows_release }}

{{ if env.windowsVariant == "servercore" then ( -}}
{{ if windows_variant == "servercore" then ( -}}
# $ProgressPreference: https://github.com/PowerShell/PowerShell/issues/2138#issuecomment-251261324
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

Expand Down Expand Up @@ -40,19 +51,19 @@ USER ContainerUser
# > Java Development Kit builds, from Oracle
# >
ENV JAVA_VERSION {{ .version }}
{{ if env.windowsVariant == "servercore" then ( -}}
{{ if windows_variant == "servercore" then ( -}}
{{ # TODO $env:PROCESSOR_ARCHITECTURE for arm64v8 someday (https://superuser.com/a/1441469/101945) -}}
ENV JAVA_URL {{ .[env.javaType].arches["windows-amd64"].url }}
{{ if .[env.javaType].arches["windows-amd64"] | has("sha256") then ( -}}
ENV JAVA_SHA256 {{ .[env.javaType].arches["windows-amd64"].sha256 }}
ENV JAVA_URL {{ .arches["windows-amd64"].url }}
{{ if .arches["windows-amd64"] | has("sha256") then ( -}}
ENV JAVA_SHA256 {{ .arches["windows-amd64"].sha256 }}
{{ ) else "" end -}}
{{ ) else "" end -}}

{{ if env.windowsVariant == "servercore" then ( -}}
{{ if windows_variant == "servercore" then ( -}}
RUN Write-Host ('Downloading {0} ...' -f $env:JAVA_URL); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -Uri $env:JAVA_URL -OutFile 'openjdk.zip'; \
{{ if .[env.javaType].arches["windows-amd64"] | has("sha256") then ( -}}
{{ if .arches["windows-amd64"] | has("sha256") then ( -}}
Write-Host ('Verifying sha256 ({0}) ...' -f $env:JAVA_SHA256); \
if ((Get-FileHash openjdk.zip -Algorithm sha256).Hash -ne $env:JAVA_SHA256) { \
Write-Host 'FAILED!'; \
Expand All @@ -72,24 +83,18 @@ RUN Write-Host ('Downloading {0} ...' -f $env:JAVA_URL); \
Remove-Item openjdk.zip -Force; \
\
Write-Host 'Verifying install ...'; \
{{ if env.javaType == "jdk" then ( -}}
Write-Host ' javac --version'; javac --version; \
{{ ) else "" end -}}
Write-Host ' java --version'; java --version; \
\
Write-Host 'Complete.'
{{ ) else ( -}}
COPY --from=openjdk:{{ .version | gsub("[+]"; "-") }}-{{ env.javaType }}-windowsservercore-{{ env.windowsRelease }} $JAVA_HOME $JAVA_HOME
COPY --from=openjdk:{{ .version | gsub("[+]"; "-") }}-windowsservercore-{{ windows_release }} $JAVA_HOME $JAVA_HOME

RUN echo Verifying install ... \
{{ if env.javaType == "jdk" then ( -}}
&& echo javac --version && javac --version \
{{ ) else "" end -}}
&& echo java --version && java --version \
&& echo Complete.
{{ ) end -}}
{{ if env.javaType == "jdk" then ( -}}

# "jshell" is an interactive REPL for Java (see https://en.wikipedia.org/wiki/JShell)
CMD ["jshell"]
{{ ) else "" end -}}
51 changes: 17 additions & 34 deletions apply-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,27 @@ for version; do
variants="$(jq -r '.[env.version].variants | map(@sh) | join(" ")' versions.json)"
eval "variants=( $variants )"

for javaType in jdk jre; do
export javaType
for variant in "${variants[@]}"; do
export variant

if ! hasJavaType="$(jq -r '.[env.version] | if has(env.javaType) then "1" else "" end' versions.json)" || [ -z "$hasJavaType" ]; then
continue
fi
dir="$version/$variant"
mkdir -p "$dir"

for variant in "${variants[@]}"; do
export variant
case "$variant" in
windows/*)
template='Dockerfile-windows.template'
;;

if [ "$javaType" = 'jre' ] && [[ "$variant" == oraclelinux* ]]; then
continue # no Oracle-based JRE images (for now? gotta figure a few things out to do that)
fi
*)
template='Dockerfile-linux.template'
;;
esac

dir="$version/$javaType/$variant"
mkdir -p "$dir"
echo "processing $dir ..."

case "$variant" in
windows/*)
variant="$(basename "$dir")" # "buster", "windowsservercore-1809", etc
windowsVariant="${variant%%-*}" # "windowsservercore", "nanoserver"
windowsRelease="${variant#$windowsVariant-}" # "ltsc2022", "1809", etc
windowsVariant="${windowsVariant#windows}" # "servercore", "nanoserver"
export windowsVariant windowsRelease
template='Dockerfile-windows.template'
;;

*)
template='Dockerfile-linux.template'
;;
esac

echo "processing $dir ..."

{
generated_warning
gawk -f "$jqt" "$template"
} > "$dir/Dockerfile"
done
{
generated_warning
gawk -f "$jqt" "$template"
} > "$dir/Dockerfile"
done
done
Loading
Loading