diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index ccf2aa81d7..3b62be1336 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -34,6 +34,7 @@ dependencies { implementation("com.fasterxml.jackson.core:jackson-databind:2.11.4") implementation("com.gradle:gradle-enterprise-gradle-plugin:3.12.1") implementation("com.tngtech.archunit:archunit:1.0.0") + implementation("de.undercouch.download:de.undercouch.download.gradle.plugin:5.5.0") implementation("commons-codec:commons-codec:1.13") implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}") implementation("org.apache.maven:maven-embedder:3.6.3") diff --git a/ci/tasks/build-project.yml b/ci/tasks/build-project.yml index db3003af6e..61c86eb759 100644 --- a/ci/tasks/build-project.yml +++ b/ci/tasks/build-project.yml @@ -7,6 +7,7 @@ outputs: - name: git-repo caches: - path: gradle +- path: build/downloads - path: embedmongo params: BRANCH: diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle index fc08e3080e..429c4601d1 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle @@ -2,10 +2,14 @@ plugins { id "java" id "org.springframework.boot.conventions" id "org.springframework.boot.integration-test" + id "de.undercouch.download" } description = "Spring Boot Launch Script Integration Tests" +def jdkVersion = "17.0.8.1+1" +def jdkArch = "aarch64".equalsIgnoreCase(System.getProperty("os.arch")) ? "aarch64" : "amd64" + configurations { app } @@ -38,6 +42,26 @@ task buildApp(type: GradleBuild) { tasks = ["build"] } +task downloadJdk(type: Download) { + def destFolder = new File(rootProject.buildDir, "downloads/jdk/bellsoft") + destFolder.mkdirs() + src "https://download.bell-sw.com/java/${jdkVersion}/bellsoft-jdk${jdkVersion}-linux-${jdkArch}.tar.gz" + dest destFolder + tempAndMove true + overwrite false +} + +task syncJdkDownloads(type: Sync) { + dependsOn downloadJdk + from "${rootProject.buildDir}/downloads/jdk/bellsoft/" + include "bellsoft-jdk${jdkVersion}-linux-${jdkArch}.tar.gz" + into "${project.buildDir}/downloads/jdk/bellsoft/" +} + +processIntTestResources { + dependsOn syncJdkDownloads +} + intTest { dependsOn buildApp } \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/AbstractLaunchScriptIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/AbstractLaunchScriptIntegrationTests.java index a38637b3e9..621808beb9 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/AbstractLaunchScriptIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/AbstractLaunchScriptIntegrationTests.java @@ -17,12 +17,9 @@ package org.springframework.boot.launchscript; import java.io.File; -import java.net.URI; -import java.nio.file.Paths; import java.time.Duration; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.function.Predicate; import org.assertj.core.api.Condition; @@ -50,11 +47,6 @@ import static org.hamcrest.Matchers.containsString; */ abstract class AbstractLaunchScriptIntegrationTests { - private static final Map JAVA_DOWNLOAD_URLS = Map.of(Architecture.AMD64, - URI.create("https://download.bell-sw.com/java/17.0.8.1+1/bellsoft-jdk17.0.8.1+1-linux-amd64.tar.gz"), - Architecture.AARCH64, - URI.create("https://download.bell-sw.com/java/17.0.8.1+1/bellsoft-jdk17.0.8.1+1-linux-aarch64.tar.gz")); - protected static final char ESC = 27; private final String scriptsDir; @@ -108,9 +100,7 @@ abstract class AbstractLaunchScriptIntegrationTests { private static final class LaunchScriptTestContainer extends GenericContainer { private LaunchScriptTestContainer(String os, String version, String scriptsDir, String testScript) { - super(new ImageFromDockerfile("spring-boot-launch-script/" + os.toLowerCase() + "-" + version) - .withDockerfile(Paths.get("src/intTest/resources/conf/" + os + "/" + version + "/Dockerfile")) - .withBuildArg("JAVA_DOWNLOAD_URL", getJavaDownloadUrl())); + super(createImage(os, version)); withCopyFileToContainer(MountableFile.forHostPath(findApplication().getAbsolutePath()), "/app.jar"); withCopyFileToContainer( MountableFile.forHostPath("src/intTest/resources/scripts/" + scriptsDir + "test-functions.sh"), @@ -123,14 +113,15 @@ abstract class AbstractLaunchScriptIntegrationTests { withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5))); } - private static String getJavaDownloadUrl() { - Architecture architecture = Architecture.current(); - Assert.notNull(architecture, - () -> String.format("Failed to find current architecture. Value of os.arch is: '%s'", - System.getProperty("os.arch"))); - URI uri = JAVA_DOWNLOAD_URLS.get(architecture); - Assert.notNull(uri, () -> String.format("No JDK download URL for architecture %s found", architecture)); - return uri.toString(); + private static ImageFromDockerfile createImage(String os, String version) { + ImageFromDockerfile image = new ImageFromDockerfile( + "spring-boot-launch-script/" + os.toLowerCase() + "-" + version); + image.withFileFromFile("Dockerfile", + new File("src/intTest/resources/conf/" + os + "/" + version + "/Dockerfile")); + for (File file : new File("build/downloads/jdk/bellsoft").listFiles()) { + image.withFileFromFile("downloads/" + file.getName(), file); + } + return image; } private static File findApplication() { @@ -142,30 +133,4 @@ abstract class AbstractLaunchScriptIntegrationTests { } - private enum Architecture { - - AMD64, AARCH64; - - /** - * Returns the current architecture. - * @return the current architecture or {@code null} - */ - static Architecture current() { - String arch = System.getProperty("os.arch"); - if (arch == null) { - return null; - } - switch (arch) { - case "amd64": - case "x86_64": - return AMD64; - case "aarch64": - return AARCH64; - default: - return null; - } - } - - } - } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/RedHat/ubi9-9.2-722/Dockerfile b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/RedHat/ubi9-9.2-722/Dockerfile index bfb9ceeefb..777f1a3cd9 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/RedHat/ubi9-9.2-722/Dockerfile +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/RedHat/ubi9-9.2-722/Dockerfile @@ -1,7 +1,10 @@ +FROM redhat/ubi9:9.2-722 as prepare +COPY downloads/* /opt/download/ +RUN mkdir -p /opt/jdk && \ + cd /opt/jdk && \ + tar xzf /opt/download/* --strip-components=1 + FROM redhat/ubi9:9.2-722 -ARG JAVA_DOWNLOAD_URL=https://download.bell-sw.com/java/17.0.8.1+1/bellsoft-jdk17.0.8.1+1-linux-amd64.tar.gz -ENV JAVA_HOME /opt/openjdk +COPY --from=prepare /opt/jdk /opt/jdk +ENV JAVA_HOME /opt/jdk ENV PATH $JAVA_HOME/bin:$PATH -RUN mkdir -p /opt/openjdk && \ - cd /opt/openjdk && \ - curl -L $JAVA_DOWNLOAD_URL | tar zx --strip-components=1 diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/Ubuntu/jammy-20230624/Dockerfile b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/Ubuntu/jammy-20230624/Dockerfile index 08f1f6b76c..4e9da10f8f 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/Ubuntu/jammy-20230624/Dockerfile +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/Ubuntu/jammy-20230624/Dockerfile @@ -1,9 +1,11 @@ +FROM ubuntu:jammy-20230624 as prepare +COPY downloads/* /opt/download/ +RUN mkdir -p /opt/jdk && \ + cd /opt/jdk && \ + tar xzf /opt/download/* --strip-components=1 + FROM ubuntu:jammy-20230624 -RUN apt-get update && \ - apt-get install -y software-properties-common curl && \ - mkdir -p /opt/openjdk -ARG JAVA_DOWNLOAD_URL=https://download.bell-sw.com/java/17.0.8.1+1/bellsoft-jdk17.0.8.1+1-linux-amd64.tar.gz -ENV JAVA_HOME /opt/openjdk +RUN apt-get update && apt-get install -y software-properties-common curl +COPY --from=prepare /opt/jdk /opt/jdk +ENV JAVA_HOME /opt/jdk ENV PATH $JAVA_HOME/bin:$PATH -RUN cd /opt/openjdk && \ - curl -L $JAVA_DOWNLOAD_URL | tar zx --strip-components=1 diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle index 7c4095f73b..c4035df3a5 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle @@ -2,10 +2,14 @@ plugins { id "java" id "org.springframework.boot.conventions" id "org.springframework.boot.integration-test" + id "de.undercouch.download" } description = "Spring Boot Loader Integration Tests" +def oracleJdkVersion = "17.0.8" +def oracleJdkArch = "aarch64".equalsIgnoreCase(System.getProperty("os.arch")) ? "aarch64" : "x86" + configurations { app } @@ -39,6 +43,26 @@ task buildApp(type: GradleBuild) { tasks = ["build"] } +task downloadJdk(type: Download) { + def destFolder = new File(rootProject.buildDir, "downloads/jdk/oracle") + destFolder.mkdirs() + src "https://download.oracle.com/java/17/archive/jdk-${oracleJdkVersion}_linux-${oracleJdkArch}_bin.tar.gz" + dest destFolder + tempAndMove true + overwrite false +} + +task syncJdkDownloads(type: Sync) { + dependsOn downloadJdk + from "${rootProject.buildDir}/downloads/jdk/oracle/" + include "jdk-${oracleJdkVersion}_linux-${oracleJdkArch}_bin.tar.gz" + into "${project.buildDir}/downloads/jdk/oracle/" +} + +processIntTestResources { + dependsOn syncJdkDownloads +} + intTest { dependsOn buildApp -} \ No newline at end of file +} diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java index 7c839e6224..b3b7bd2c09 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java @@ -118,10 +118,11 @@ class LoaderIntegrationTests { } static JavaRuntime oracleJdk17() { - String arch = System.getProperty("os.arch"); - String dockerFile = ("aarch64".equals(arch)) ? "Dockerfile-aarch64" : "Dockerfile"; - ImageFromDockerfile image = new ImageFromDockerfile("spring-boot-loader/oracle-jdk-17") - .withFileFromFile("Dockerfile", new File("src/intTest/resources/conf/oracle-jdk-17/" + dockerFile)); + ImageFromDockerfile image = new ImageFromDockerfile("spring-boot-loader/oracle-jdk"); + image.withFileFromFile("Dockerfile", new File("src/intTest/resources/conf/oracle-jdk-17/Dockerfile")); + for (File file : new File("build/downloads/jdk/oracle").listFiles()) { + image.withFileFromFile("downloads/" + file.getName(), file); + } return new JavaRuntime("Oracle JDK 17", JavaVersion.SEVENTEEN, () -> new GenericContainer<>(image)); } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile index 2a50709dc5..0b920d47fd 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile @@ -1,8 +1,10 @@ +FROM ubuntu:jammy-20230624 as prepare +COPY downloads/* /opt/download/ +RUN mkdir -p /opt/jdk && \ + cd /opt/jdk && \ + tar xzf /opt/download/* --strip-components=1 + FROM ubuntu:jammy-20230624 -RUN apt-get update && \ - apt-get install -y software-properties-common curl && \ - mkdir -p /opt/oraclejdk && \ - cd /opt/oraclejdk && \ - curl -L https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz | tar zx --strip-components=1 -ENV JAVA_HOME /opt/oraclejdk +COPY --from=prepare /opt/jdk /opt/jdk +ENV JAVA_HOME /opt/jdk ENV PATH $JAVA_HOME/bin:$PATH diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile-aarch64 b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile-aarch64 deleted file mode 100644 index 3f8614c7a2..0000000000 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/resources/conf/oracle-jdk-17/Dockerfile-aarch64 +++ /dev/null @@ -1,8 +0,0 @@ -FROM ubuntu:jammy-20230624 -RUN apt-get update && \ - apt-get install -y software-properties-common curl && \ - mkdir -p /opt/oraclejdk && \ - cd /opt/oraclejdk && \ - curl -L https://download.oracle.com/java/17/archive/jdk-17.0.8_linux-aarch64_bin.tar.gz | tar zx --strip-components=1 -ENV JAVA_HOME /opt/oraclejdk -ENV PATH $JAVA_HOME/bin:$PATH