From 0f6342a8821ee6c1ca06439bda8f433d8ee2e331 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 17 Aug 2023 18:09:53 +0200 Subject: [PATCH] Make JarLaunchScript and SysVinit integration tests ARM64 compatible Closes gh-36799 --- .../AbstractLaunchScriptIntegrationTests.java | 55 ++++++++++++++++++- .../SysVinitLaunchScriptIntegrationTests.java | 10 +--- .../resources/conf/CentOS/7.9.2009/Dockerfile | 6 -- .../conf/RedHat/ubi9-9.2-722/Dockerfile | 7 +++ .../conf/Ubuntu/jammy-20230624/Dockerfile | 7 ++- 5 files changed, 66 insertions(+), 19 deletions(-) delete mode 100644 spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/CentOS/7.9.2009/Dockerfile create mode 100644 spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/RedHat/ubi9-9.2-722/Dockerfile 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 d2ae746d6e4..ca4bda6f527 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,9 +17,14 @@ 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.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.function.Predicate; import org.assertj.core.api.Condition; @@ -43,9 +48,20 @@ import static org.hamcrest.Matchers.containsString; * @author Andy Wilkinson * @author Ali Shahbour * @author Alexey Vinogradov + * @author Moritz Halbritter */ abstract class AbstractLaunchScriptIntegrationTests { + private static final Map JAVA_DOWNLOAD_URLS; + static { + Map urls = new HashMap<>(); + urls.put(Architecture.AMD64, + URI.create("https://download.bell-sw.com/java/8u382+6/bellsoft-jdk8u382+6-linux-amd64.tar.gz")); + urls.put(Architecture.AARCH64, + URI.create("https://download.bell-sw.com/java/8u382+6/bellsoft-jdk8u382+6-linux-aarch64.tar.gz")); + JAVA_DOWNLOAD_URLS = Collections.unmodifiableMap(urls); + } + protected static final char ESC = 27; private final String scriptsDir; @@ -100,8 +116,8 @@ abstract class AbstractLaunchScriptIntegrationTests { private LaunchScriptTestContainer(String os, String version, String scriptsDir, String testScript) { super(new ImageFromDockerfile("spring-boot-launch-script/" + os.toLowerCase() + "-" + version) - .withFileFromFile("Dockerfile", - new File("src/intTest/resources/conf/" + os + "/" + version + "/Dockerfile"))); + .withDockerfile(Paths.get("src/intTest/resources/conf/" + os + "/" + version + "/Dockerfile")) + .withBuildArg("JAVA_DOWNLOAD_URL", getJavaDownloadUrl())); withCopyFileToContainer(MountableFile.forHostPath(findApplication().getAbsolutePath()), "/app.jar"); withCopyFileToContainer( MountableFile.forHostPath("src/intTest/resources/scripts/" + scriptsDir + "test-functions.sh"), @@ -114,6 +130,16 @@ 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 File findApplication() { String name = String.format("build/%1$s/build/libs/%1$s.jar", "spring-boot-launch-script-tests-app"); File jar = new File(name); @@ -123,4 +149,29 @@ 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": + 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/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIntegrationTests.java index 513e3527dc9..b31198b29c6 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIntegrationTests.java @@ -19,13 +19,10 @@ package org.springframework.boot.launchscript; import java.util.List; import java.util.regex.Pattern; -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.boot.ansi.AnsiColor; -import org.springframework.boot.testsupport.junit.DisabledOnOs; import org.springframework.boot.testsupport.testcontainers.DisabledIfDockerUnavailable; import static org.assertj.core.api.Assertions.assertThat; @@ -36,10 +33,9 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson * @author Ali Shahbour * @author Alexey Vinogradov + * @author Moritz Halbritter */ @DisabledIfDockerUnavailable -@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64", - disabledReason = "The docker images have no ARM support") class SysVinitLaunchScriptIntegrationTests extends AbstractLaunchScriptIntegrationTests { SysVinitLaunchScriptIntegrationTests() { @@ -47,7 +43,7 @@ class SysVinitLaunchScriptIntegrationTests extends AbstractLaunchScriptIntegrati } static List parameters() { - return parameters((file) -> !file.getName().contains("CentOS")); + return parameters((file) -> !file.getName().contains("RedHat")); } @ParameterizedTest(name = "{0} {1}") @@ -194,8 +190,6 @@ class SysVinitLaunchScriptIntegrationTests extends AbstractLaunchScriptIntegrati @ParameterizedTest(name = "{0} {1}") @MethodSource("parameters") void launchWithUseOfStartStopDaemonDisabled(String os, String version) throws Exception { - // CentOS doesn't have start-stop-daemon - Assumptions.assumeFalse(os.equals("CentOS")); doLaunch(os, version, "launch-with-use-of-start-stop-daemon-disabled.sh"); } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/CentOS/7.9.2009/Dockerfile b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/CentOS/7.9.2009/Dockerfile deleted file mode 100644 index c9a936065ec..00000000000 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/CentOS/7.9.2009/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM centos:7.9.2009 -RUN mkdir -p /opt/openjdk && \ - cd /opt/openjdk && \ - curl -L https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u202-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz | tar zx --strip-components=1 -ENV JAVA_HOME /opt/openjdk -ENV PATH $JAVA_HOME/bin:$PATH 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 new file mode 100644 index 00000000000..ebb51b5214a --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/src/intTest/resources/conf/RedHat/ubi9-9.2-722/Dockerfile @@ -0,0 +1,7 @@ +FROM redhat/ubi9:9.2-722 +ARG JAVA_DOWNLOAD_URL=https://download.bell-sw.com/java/8u382+6/bellsoft-jdk8u382+6-linux-amd64.tar.gz +ENV JAVA_HOME /opt/openjdk +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 50699e373f7..f4e9645f022 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,8 +1,9 @@ FROM ubuntu:jammy-20230624 RUN apt-get update && \ apt-get install -y software-properties-common curl && \ - mkdir -p /opt/openjdk && \ - cd /opt/openjdk && \ - curl -L https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u202-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u202b08.tar.gz | tar zx --strip-components=1 + mkdir -p /opt/openjdk +ARG JAVA_DOWNLOAD_URL=https://download.bell-sw.com/java/8u382+6/bellsoft-jdk8u382+6-linux-amd64.tar.gz ENV JAVA_HOME /opt/openjdk ENV PATH $JAVA_HOME/bin:$PATH +RUN cd /opt/openjdk && \ + curl -L $JAVA_DOWNLOAD_URL | tar zx --strip-components=1