From 88dcb7641e41db233cf20f12edaf69a893a202ed Mon Sep 17 00:00:00 2001 From: Damien Duportal Date: Wed, 24 Apr 2024 12:22:02 +0200 Subject: [PATCH] fix: switch to Adoptium Temurin installer instead of Docker image It introduces the following changes: - Faster build due to less layers to pull (ref. https://github.com/jenkinsci/docker-agent/pull/787) - Retrieving the `netapi32` DLL and `whoami.exe`` from the Python parent image instead of Temurin image - Moving `ARG JAVA_VERSION` into the last stage's scope - Pin JDK21 version to 21+35 to ensure a valid installer is retrieved Signed-off-by: Damien Duportal --- maven/jdk11/Dockerfile.nanoserver | 20 ++++++++----- maven/jdk17/Dockerfile.nanoserver | 19 +++++++----- maven/jdk21/Dockerfile.nanoserver | 48 ++++++++++++------------------- maven/jdk8/Dockerfile.nanoserver | 19 +++++++----- 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/maven/jdk11/Dockerfile.nanoserver b/maven/jdk11/Dockerfile.nanoserver index c06981f..816f296 100644 --- a/maven/jdk11/Dockerfile.nanoserver +++ b/maven/jdk11/Dockerfile.nanoserver @@ -1,34 +1,40 @@ # escape=` -ARG JAVA_VERSION=11.0.22_7 ARG JAVA17_IMAGE_VERSION=3206.vb_15dcf73f6a_9-2 ARG PYTHON_VERSION=3.12.2 -FROM python:"${PYTHON_VERSION}"-windowsservercore-1809 AS python +FROM python:"${PYTHON_VERSION}"-windowsservercore-1809 AS python-core # hadolint ignore=DL3013 RUN "C:/Python/python.exe" -m pip install --no-cache-dir --upgrade pip; ` pip install --no-cache-dir setuptools wheel; -FROM eclipse-temurin:${JAVA_VERSION}-jdk-windowsservercore-1809 AS core +# Use inbound-agent's jdk17 only for running jenkins agent, not as default java FROM jenkins/inbound-agent:"${JAVA17_IMAGE_VERSION}"-jdk17-nanoserver-1809 +ARG JAVA_VERSION=11.0.22_7 + # ProgressPreference => Disable Progress bar for faster downloads SHELL ["pwsh.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] # Adding python -COPY --from=python C:/Python C:/tools/python +COPY --from=python-core C:/Python C:/tools/python # Install Launchable in this layer ARG LAUNCHABLE_VERSION=1.66.0 RUN "C:/tools/python/python.exe" -m pip install --no-cache-dir launchable=="${env:LAUNCHABLE_VERSION}"; # Adding jdk11 from eclipse-temurin -# Use ENV and not ARG : https://docs.docker.com/engine/reference/builder/#using-arg-variables ENV JAVA_HOME="C:\tools\jdk-11" -COPY --from=core C:/openjdk-11 "${JAVA_HOME}" +RUN New-Item -ItemType Directory -Path C:\temp | Out-Null ; ` + $msiUrl = 'https://api.adoptium.net/v3/installer/version/jdk-{0}/windows/x64/jdk/hotspot/normal/eclipse?project=jdk' -f $env:JAVA_VERSION.Replace('+', '%2B') ; ` + Invoke-WebRequest $msiUrl -OutFile 'C:\temp\jdk.msi' ; ` + $proc = Start-Process -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\temp\jdk.msi', '/L*V', 'C:\temp\OpenJDK.log', '/quiet', 'ADDLOCAL=FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome', "INSTALLDIR=${env:JAVA_HOME}" -Wait -Passthru ; ` + $proc.WaitForExit() ; ` + Remove-Item -Path C:\temp -Recurse | Out-Null # https://github.com/StefanScherer/dockerfiles-windows/tree/master/golang-issue-21867 -COPY --from=core C:/windows/system32/netapi32.dll C:/windows/system32/netapi32.dll +COPY --from=python-core C:/windows/system32/netapi32.dll C:/windows/system32/netapi32.dll +COPY --from=python-core C:/windows/system32/whoami.exe C:/windows/system32/whoami.exe ARG MAVEN_VERSION=3.9.6 RUN Invoke-WebRequest -Uri "https://archive.apache.org/dist/maven/maven-3/${env:MAVEN_VERSION}/binaries/apache-maven-${env:MAVEN_VERSION}-bin.zip" -OutFile ${env:TEMP}/apache-maven.zip ; ` diff --git a/maven/jdk17/Dockerfile.nanoserver b/maven/jdk17/Dockerfile.nanoserver index a09dabf..1a32b9e 100644 --- a/maven/jdk17/Dockerfile.nanoserver +++ b/maven/jdk17/Dockerfile.nanoserver @@ -1,35 +1,40 @@ # escape=` -ARG JAVA_VERSION=17.0.10_7 ARG JAVA17_IMAGE_VERSION=3206.vb_15dcf73f6a_9-2 ARG PYTHON_VERSION=3.12.2 -FROM python:"${PYTHON_VERSION}"-windowsservercore-1809 AS python +FROM python:"${PYTHON_VERSION}"-windowsservercore-1809 AS python-core # hadolint ignore=DL3013 RUN "C:/Python/python.exe" -m pip install --no-cache-dir --upgrade pip; ` pip install --no-cache-dir setuptools wheel; -FROM eclipse-temurin:${JAVA_VERSION}-jdk-windowsservercore-1809 AS core # Use inbound-agent's jdk17 only for running jenkins agent, not as default java FROM jenkins/inbound-agent:"${JAVA17_IMAGE_VERSION}"-jdk17-nanoserver-1809 +ARG JAVA_VERSION=17.0.10_7 + # ProgressPreference => Disable Progress bar for faster downloads SHELL ["pwsh.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] # Adding python -COPY --from=python C:/Python C:/tools/python +COPY --from=python-core C:/Python C:/tools/python # Install Launchable in this layer ARG LAUNCHABLE_VERSION=1.66.0 RUN "C:/tools/python/python.exe" -m pip install --no-cache-dir launchable=="${env:LAUNCHABLE_VERSION}"; # Adding jdk17 from eclipse-temurin -# Use ENV and not ARG : https://docs.docker.com/engine/reference/builder/#using-arg-variables ENV JAVA_HOME="C:\tools\jdk-17" -COPY --from=core C:/openjdk-17 "${JAVA_HOME}" +RUN New-Item -ItemType Directory -Path C:\temp | Out-Null ; ` + $msiUrl = 'https://api.adoptium.net/v3/installer/version/jdk-{0}/windows/x64/jdk/hotspot/normal/eclipse?project=jdk' -f $env:JAVA_VERSION.Replace('+', '%2B') ; ` + Invoke-WebRequest $msiUrl -OutFile 'C:\temp\jdk.msi' ; ` + $proc = Start-Process -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\temp\jdk.msi', '/L*V', 'C:\temp\OpenJDK.log', '/quiet', 'ADDLOCAL=FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome', "INSTALLDIR=${env:JAVA_HOME}" -Wait -Passthru ; ` + $proc.WaitForExit() ; ` + Remove-Item -Path C:\temp -Recurse | Out-Null # https://github.com/StefanScherer/dockerfiles-windows/tree/master/golang-issue-21867 -COPY --from=core C:/windows/system32/netapi32.dll C:/windows/system32/netapi32.dll +COPY --from=python-core C:/windows/system32/netapi32.dll C:/windows/system32/netapi32.dll +COPY --from=python-core C:/windows/system32/whoami.exe C:/windows/system32/whoami.exe ARG MAVEN_VERSION=3.9.6 RUN Invoke-WebRequest -Uri "https://archive.apache.org/dist/maven/maven-3/${env:MAVEN_VERSION}/binaries/apache-maven-${env:MAVEN_VERSION}-bin.zip" -OutFile ${env:TEMP}/apache-maven.zip ; ` diff --git a/maven/jdk21/Dockerfile.nanoserver b/maven/jdk21/Dockerfile.nanoserver index d0e629e..068ce6c 100644 --- a/maven/jdk21/Dockerfile.nanoserver +++ b/maven/jdk21/Dockerfile.nanoserver @@ -1,58 +1,46 @@ # escape=` -ARG JAVA_VERSION=21-jdk ARG JAVA17_IMAGE_VERSION=3206.vb_15dcf73f6a_9-2 ARG PYTHON_VERSION=3.12.2 -FROM python:"${PYTHON_VERSION}"-windowsservercore-1809 AS python +FROM python:"${PYTHON_VERSION}"-windowsservercore-1809 AS python-core # hadolint ignore=DL3013 RUN "C:/Python/python.exe" -m pip install --no-cache-dir --upgrade pip; ` pip install --no-cache-dir setuptools wheel; -## Comment out once temurin publishes an official JDK21 container image -#FROM eclipse-temurin:${JAVA_VERSION}-jdk-windowsservercore-1809 AS core # Use inbound-agent's jdk17 only for running jenkins agent, not as default java FROM jenkins/inbound-agent:"${JAVA17_IMAGE_VERSION}"-jdk17-nanoserver-1809 +ARG JAVA_VERSION=21+35 + # ProgressPreference => Disable Progress bar for faster downloads SHELL ["pwsh.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] -ARG toolsDir="C:\tools" -ARG pythonDir="$toolsDir\python" - -ENV PYTHON_PATH="$pythonDir" -ENV PATH="${pythonDir};${pythonDir}\Scripts;${PATH}" - # Adding python -COPY --from=python C:/Python $pythonDir +COPY --from=python-core C:/Python C:/tools/python # Install Launchable in this layer ARG LAUNCHABLE_VERSION=1.66.0 -RUN python.exe -m pip install --no-cache-dir launchable=="${env:LAUNCHABLE_VERSION}"; +RUN "C:/tools/python/python.exe" -m pip install --no-cache-dir launchable=="${env:LAUNCHABLE_VERSION}"; -# Retrieve jdk17 for running jenkins agent process but do not use it as default -# Use ENV and not ARG : https://docs.docker.com/engine/reference/builder/#using-arg-variables -ENV JAVA_HOME="$toolsDir\jdk-21" -ENV PATH="${JAVA_HOME}\bin;${PATH}" - -## Remove once temurin publishes an official JDK21 container image -ARG jdk21Version="2023-08-09-06-56-beta" -# From https://github.com/jenkins-infra/packer-images/blob/f02d850cb1ce74f4cf2a03af90a5ccd06925cb5c/provisioning/windows-provision.ps1#L126 -RUN $jdk21Url = 'https://github.com/adoptium/temurin21-binaries/releases/download/jdk21-{0}/OpenJDK21U-jdk_x64_windows_hotspot_{1}.zip' -f [System.Web.HTTPUtility]::UrlEncode($env:jdk21Version),$env:jdk21Version.Replace('-beta', ''); ` - Invoke-WebRequest -Uri "$jdk21Url" -OutFile "${env:TEMP}/temurin21.zip"; ` - Expand-Archive -Path "${env:TEMP}/temurin21.zip" -Destination "${env:toolsDir}" ; ` - Remove-Item ${env:TEMP}/temurin21.zip; ` - Move-Item -Path "${env:toolsDir}\jdk-21*" -Destination "${env:JAVA_HOME}"; - -## Comment out once temurin publishes an official JDK21 container image -#COPY --from=core C:/openjdk-21 "${JAVA_HOME}" +# Adding jdk21 from eclipse-temurin +ENV JAVA_HOME="C:\tools\jdk-21" +RUN New-Item -ItemType Directory -Path C:\temp | Out-Null ; ` + $msiUrl = 'https://api.adoptium.net/v3/installer/version/jdk-{0}/windows/x64/jdk/hotspot/normal/eclipse?project=jdk' -f $env:JAVA_VERSION.Replace('+', '%2B') ; ` + Invoke-WebRequest $msiUrl -OutFile 'C:\temp\jdk.msi' ; ` + $proc = Start-Process -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\temp\jdk.msi', '/L*V', 'C:\temp\OpenJDK.log', '/quiet', 'ADDLOCAL=FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome', "INSTALLDIR=${env:JAVA_HOME}" -Wait -Passthru ; ` + $proc.WaitForExit() ; ` + Remove-Item -Path C:\temp -Recurse | Out-Null # https://github.com/StefanScherer/dockerfiles-windows/tree/master/golang-issue-21867 -COPY --from=python C:/windows/system32/netapi32.dll C:/windows/system32/netapi32.dll +COPY --from=python-core C:/windows/system32/netapi32.dll C:/windows/system32/netapi32.dll +COPY --from=python-core C:/windows/system32/whoami.exe C:/windows/system32/whoami.exe ARG MAVEN_VERSION=3.9.6 RUN Invoke-WebRequest -Uri "https://archive.apache.org/dist/maven/maven-3/${env:MAVEN_VERSION}/binaries/apache-maven-${env:MAVEN_VERSION}-bin.zip" -OutFile ${env:TEMP}/apache-maven.zip ; ` Expand-Archive -Path "${env:TEMP}/apache-maven.zip -Destination" C:/tools ; ` Remove-Item ${env:TEMP}/apache-maven.zip ; + +ENV PYTHON_PATH="C:\tools\python;C:\tools\python\Scripts" ENV MAVEN_HOME="C:\tools\apache-maven-${MAVEN_VERSION}" -ENV PATH="${MAVEN_HOME}\bin;${PATH}" +ENV PATH="${PYTHON_PATH};${JAVA_HOME}\bin;${PATH};${MAVEN_HOME}\bin;" diff --git a/maven/jdk8/Dockerfile.nanoserver b/maven/jdk8/Dockerfile.nanoserver index b816464..81113ed 100644 --- a/maven/jdk8/Dockerfile.nanoserver +++ b/maven/jdk8/Dockerfile.nanoserver @@ -1,35 +1,40 @@ # escape=` -ARG JAVA_VERSION=8u402-b06 ARG JAVA17_IMAGE_VERSION=3206.vb_15dcf73f6a_9-2 ARG PYTHON_VERSION=3.12.2 -FROM python:"${PYTHON_VERSION}"-windowsservercore-1809 AS python +FROM python:"${PYTHON_VERSION}"-windowsservercore-1809 AS python-core # hadolint ignore=DL3013 RUN "C:/Python/python.exe" -m pip install --no-cache-dir --upgrade pip; ` pip install --no-cache-dir setuptools wheel; -FROM eclipse-temurin:${JAVA_VERSION}-jdk-windowsservercore-1809 AS core # Use inbound-agent's jdk17 only for running jenkins agent, not as default java FROM jenkins/inbound-agent:${JAVA17_IMAGE_VERSION}-jdk17-nanoserver-1809 +ARG JAVA_VERSION=8u402-b06 + # ProgressPreference => Disable Progress bar for faster downloads SHELL ["pwsh.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] # Adding python -COPY --from=python C:/Python C:/tools/python +COPY --from=python-core C:/Python C:/tools/python # Install Launchable in this layer ARG LAUNCHABLE_VERSION=1.66.0 RUN "C:/tools/python/python.exe" -m pip install --no-cache-dir launchable=="${env:LAUNCHABLE_VERSION}"; # Adding jdk8 from eclipse-temurin -# Use ENV and not ARG : https://docs.docker.com/engine/reference/builder/#using-arg-variables ENV JAVA_HOME="C:\tools\jdk-8" -COPY --from=core C:/openjdk-8 "${JAVA_HOME}" +RUN New-Item -ItemType Directory -Path C:\temp | Out-Null ; ` + $msiUrl = 'https://api.adoptium.net/v3/installer/version/jdk-{0}/windows/x64/jdk/hotspot/normal/eclipse?project=jdk' -f $env:JAVA_VERSION.Replace('+', '%2B') ; ` + Invoke-WebRequest $msiUrl -OutFile 'C:\temp\jdk.msi' ; ` + $proc = Start-Process -FilePath 'msiexec.exe' -ArgumentList '/i', 'C:\temp\jdk.msi', '/L*V', 'C:\temp\OpenJDK.log', '/quiet', 'ADDLOCAL=FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome', "INSTALLDIR=${env:JAVA_HOME}" -Wait -Passthru ; ` + $proc.WaitForExit() ; ` + Remove-Item -Path C:\temp -Recurse | Out-Null # https://github.com/StefanScherer/dockerfiles-windows/tree/master/golang-issue-21867 -COPY --from=core C:/windows/system32/netapi32.dll C:/windows/system32/netapi32.dll +COPY --from=python-core C:/windows/system32/netapi32.dll C:/windows/system32/netapi32.dll +COPY --from=python-core C:/windows/system32/whoami.exe C:/windows/system32/whoami.exe ARG MAVEN_VERSION=3.9.6 RUN Invoke-WebRequest -Uri "https://archive.apache.org/dist/maven/maven-3/${env:MAVEN_VERSION}/binaries/apache-maven-${env:MAVEN_VERSION}-bin.zip" -OutFile ${env:TEMP}/apache-maven.zip ; `