8272398: Update DockerTestUtils.buildJdkDockerImage()
Reviewed-by: iignatyev, hseigel
This commit is contained in:
parent
14623cde3a
commit
ec63957f9d
@ -48,7 +48,7 @@ public class DockerBasicTest {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageNameAndTag, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageNameAndTag);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
testJavaVersion();
|
testJavaVersion();
|
||||||
|
@ -52,7 +52,7 @@ public class TestCPUAwareness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
|
System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// cpuset, period, shares, expected Active Processor Count
|
// cpuset, period, shares, expected Active Processor Count
|
||||||
|
@ -57,7 +57,7 @@ public class TestCPUSets {
|
|||||||
|
|
||||||
|
|
||||||
Common.prepareWhiteBox();
|
Common.prepareWhiteBox();
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Sanity test the cpu sets reader and parser
|
// Sanity test the cpu sets reader and parser
|
||||||
|
@ -58,7 +58,7 @@ public class TestJFREvents {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class TestJFRNetworkEvents {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
runTest("jdk.SocketWrite");
|
runTest("jdk.SocketWrite");
|
||||||
|
@ -80,7 +80,7 @@ public class TestJFRWithJMX {
|
|||||||
throw new SkippedException("test cannot be run under rootless podman configuration");
|
throw new SkippedException("test cannot be run under rootless podman configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
test();
|
test();
|
||||||
|
@ -65,7 +65,7 @@ public class TestJcmdWithSideCar {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(IMAGE_NAME, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(IMAGE_NAME);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Start the loop process in the "main" container, then run test cases
|
// Start the loop process in the "main" container, then run test cases
|
||||||
|
@ -50,7 +50,7 @@ public class TestMemoryAwareness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Common.prepareWhiteBox();
|
Common.prepareWhiteBox();
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
testMemoryLimit("100m", "104857600");
|
testMemoryLimit("100m", "104857600");
|
||||||
|
@ -50,7 +50,7 @@ public class TestMisc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Common.prepareWhiteBox();
|
Common.prepareWhiteBox();
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
testMinusContainerSupport();
|
testMinusContainerSupport();
|
||||||
|
@ -52,7 +52,7 @@ public class TestPids {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Common.prepareWhiteBox();
|
Common.prepareWhiteBox();
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
testPids();
|
testPids();
|
||||||
|
@ -54,7 +54,7 @@ public class TestDockerCpuMetrics {
|
|||||||
// container include the Java test class to be run along with the
|
// container include the Java test class to be run along with the
|
||||||
// resource to be examined and expected result.
|
// resource to be examined and expected result.
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int numCpus = CPUSetsReader.getNumCpus();
|
int numCpus = CPUSetsReader.getNumCpus();
|
||||||
|
@ -52,7 +52,7 @@ public class TestDockerMemoryMetrics {
|
|||||||
// container include the Java test class to be run along with the
|
// container include the Java test class to be run along with the
|
||||||
// resource to be examined and expected result.
|
// resource to be examined and expected result.
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
try {
|
try {
|
||||||
testMemoryLimit("200m");
|
testMemoryLimit("200m");
|
||||||
testMemoryLimit("1g");
|
testMemoryLimit("1g");
|
||||||
|
@ -43,7 +43,7 @@ public class TestGetFreeSwapSpaceSize {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
testGetFreeSwapSpaceSize(
|
testGetFreeSwapSpaceSize(
|
||||||
|
@ -48,7 +48,7 @@ public class TestPidsLimit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
testPidsLimit("1000");
|
testPidsLimit("1000");
|
||||||
|
@ -45,7 +45,7 @@ public class TestSystemMetrics {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Common.logNewTestCase("Test SystemMetrics");
|
Common.logNewTestCase("Test SystemMetrics");
|
||||||
|
@ -44,7 +44,7 @@ public class TestUseContainerSupport {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
testUseContainerSupport(true);
|
testUseContainerSupport(true);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -120,59 +120,66 @@ public class DockerTestUtils {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* Build a container image that contains JDK under test.
|
||||||
* Build a docker image that contains JDK under test.
|
* The jdk will be placed under the "/jdk/" folder inside the image/container file system.
|
||||||
* The jdk will be placed under the "/jdk/" folder inside the docker file system.
|
|
||||||
*
|
*
|
||||||
* @param imageName name of the image to be created, including version tag
|
* @param imageName name of the image to be created, including version tag
|
||||||
* @param dockerfile name of the dockerfile residing in the test source;
|
|
||||||
* we check for a platform specific dockerfile as well
|
|
||||||
* and use this one in case it exists
|
|
||||||
* @param buildDirName name of the docker build/staging directory, which will
|
|
||||||
* be created in the jtreg's scratch folder
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static void
|
public static void buildJdkContainerImage(String imageName) throws Exception {
|
||||||
buildJdkDockerImage(String imageName, String dockerfile, String buildDirName)
|
buildJdkContainerImage(imageName, null);
|
||||||
throws Exception {
|
}
|
||||||
|
|
||||||
Path buildDir = Paths.get(".", buildDirName);
|
/**
|
||||||
|
* Build a container image that contains JDK under test.
|
||||||
|
* The jdk will be placed under the "/jdk/" folder inside the image/container file system.
|
||||||
|
*
|
||||||
|
* @param imageName name of the image to be created, including version tag
|
||||||
|
* @param dockerfileContent content of the Dockerfile; use null to generate default content
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static void buildJdkContainerImage(String imageName, String dockerfileContent) throws Exception {
|
||||||
|
// image name may contain tag, hence replace ':'
|
||||||
|
String imageDirName = imageName.replace(":", "-");
|
||||||
|
|
||||||
|
// Create an image build/staging directory
|
||||||
|
Path buildDir = Paths.get(imageDirName);
|
||||||
if (Files.exists(buildDir)) {
|
if (Files.exists(buildDir)) {
|
||||||
throw new RuntimeException("The docker build directory already exists: " + buildDir);
|
throw new RuntimeException("The docker build directory already exists: " + buildDir);
|
||||||
}
|
}
|
||||||
|
Files.createDirectories(buildDir);
|
||||||
|
|
||||||
Path jdkSrcDir = Paths.get(JDK_UNDER_TEST);
|
// Generate Dockerfile
|
||||||
Path jdkDstDir = buildDir.resolve("jdk");
|
if (dockerfileContent != null) {
|
||||||
|
Files.writeString(buildDir.resolve("Dockerfile"), dockerfileContent);
|
||||||
Files.createDirectories(jdkDstDir);
|
} else {
|
||||||
|
generateDockerFile(buildDir.resolve("Dockerfile"),
|
||||||
|
DockerfileConfig.getBaseImageName(),
|
||||||
|
DockerfileConfig.getBaseImageVersion());
|
||||||
|
}
|
||||||
|
|
||||||
// Copy JDK-under-test tree to the docker build directory.
|
// Copy JDK-under-test tree to the docker build directory.
|
||||||
// This step is required for building a docker image.
|
// This step is required for building a docker image.
|
||||||
|
Path jdkSrcDir = Paths.get(JDK_UNDER_TEST);
|
||||||
|
Path jdkDstDir = buildDir.resolve("jdk");
|
||||||
|
Files.createDirectories(jdkDstDir);
|
||||||
Files.walkFileTree(jdkSrcDir, new CopyFileVisitor(jdkSrcDir, jdkDstDir));
|
Files.walkFileTree(jdkSrcDir, new CopyFileVisitor(jdkSrcDir, jdkDstDir));
|
||||||
buildDockerImage(imageName, Paths.get(Utils.TEST_SRC, dockerfile), buildDir);
|
|
||||||
|
buildImage(imageName, buildDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a docker image based on given docker file and docker build directory.
|
* Build a container image based on image build directory.
|
||||||
*
|
*
|
||||||
* @param imageName name of the image to be created, including version tag
|
* @param imageName name of the image to be created, including version tag
|
||||||
* @param dockerfile path to the Dockerfile to be used for building the docker
|
* @param buildDir build directory; it should already contain all the content
|
||||||
* image. The specified dockerfile will be copied to the docker build
|
* needed to build the image.
|
||||||
* directory as 'Dockerfile'
|
|
||||||
* @param buildDir build directory; it should already contain all the content
|
|
||||||
* needed to build the docker image.
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static void
|
private static void buildImage(String imageName, Path buildDir) throws Exception {
|
||||||
buildDockerImage(String imageName, Path dockerfile, Path buildDir) throws Exception {
|
|
||||||
|
|
||||||
generateDockerFile(buildDir.resolve("Dockerfile"),
|
|
||||||
DockerfileConfig.getBaseImageName(),
|
|
||||||
DockerfileConfig.getBaseImageVersion());
|
|
||||||
try {
|
try {
|
||||||
// Build the docker
|
|
||||||
execute(Container.ENGINE_COMMAND, "build", "--no-cache", "--tag", imageName, buildDir.toString())
|
execute(Container.ENGINE_COMMAND, "build", "--no-cache", "--tag", imageName, buildDir.toString())
|
||||||
.shouldHaveExitValue(0);
|
.shouldHaveExitValue(0);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user