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;
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageNameAndTag, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageNameAndTag);
|
||||
|
||||
try {
|
||||
testJavaVersion();
|
||||
|
@ -52,7 +52,7 @@ public class TestCPUAwareness {
|
||||
}
|
||||
|
||||
System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
// cpuset, period, shares, expected Active Processor Count
|
||||
|
@ -57,7 +57,7 @@ public class TestCPUSets {
|
||||
|
||||
|
||||
Common.prepareWhiteBox();
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
// Sanity test the cpu sets reader and parser
|
||||
|
@ -58,7 +58,7 @@ public class TestJFREvents {
|
||||
return;
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class TestJFRNetworkEvents {
|
||||
return;
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
runTest("jdk.SocketWrite");
|
||||
|
@ -80,7 +80,7 @@ public class TestJFRWithJMX {
|
||||
throw new SkippedException("test cannot be run under rootless podman configuration");
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
test();
|
||||
|
@ -65,7 +65,7 @@ public class TestJcmdWithSideCar {
|
||||
return;
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(IMAGE_NAME, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(IMAGE_NAME);
|
||||
|
||||
try {
|
||||
// Start the loop process in the "main" container, then run test cases
|
||||
|
@ -50,7 +50,7 @@ public class TestMemoryAwareness {
|
||||
}
|
||||
|
||||
Common.prepareWhiteBox();
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
testMemoryLimit("100m", "104857600");
|
||||
|
@ -50,7 +50,7 @@ public class TestMisc {
|
||||
}
|
||||
|
||||
Common.prepareWhiteBox();
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
testMinusContainerSupport();
|
||||
|
@ -52,7 +52,7 @@ public class TestPids {
|
||||
}
|
||||
|
||||
Common.prepareWhiteBox();
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
testPids();
|
||||
|
@ -54,7 +54,7 @@ public class TestDockerCpuMetrics {
|
||||
// container include the Java test class to be run along with the
|
||||
// resource to be examined and expected result.
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
int numCpus = CPUSetsReader.getNumCpus();
|
||||
|
@ -52,7 +52,7 @@ public class TestDockerMemoryMetrics {
|
||||
// container include the Java test class to be run along with the
|
||||
// resource to be examined and expected result.
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
try {
|
||||
testMemoryLimit("200m");
|
||||
testMemoryLimit("1g");
|
||||
|
@ -43,7 +43,7 @@ public class TestGetFreeSwapSpaceSize {
|
||||
return;
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
testGetFreeSwapSpaceSize(
|
||||
|
@ -48,7 +48,7 @@ public class TestPidsLimit {
|
||||
return;
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
testPidsLimit("1000");
|
||||
|
@ -45,7 +45,7 @@ public class TestSystemMetrics {
|
||||
return;
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
Common.logNewTestCase("Test SystemMetrics");
|
||||
|
@ -44,7 +44,7 @@ public class TestUseContainerSupport {
|
||||
return;
|
||||
}
|
||||
|
||||
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -120,59 +120,66 @@ public class DockerTestUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a docker image that contains JDK under test.
|
||||
* The jdk will be placed under the "/jdk/" folder inside the docker file system.
|
||||
/**
|
||||
* 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 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
|
||||
* @param imageName name of the image to be created, including version tag
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void
|
||||
buildJdkDockerImage(String imageName, String dockerfile, String buildDirName)
|
||||
throws Exception {
|
||||
public static void buildJdkContainerImage(String imageName) throws Exception {
|
||||
buildJdkContainerImage(imageName, null);
|
||||
}
|
||||
|
||||
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)) {
|
||||
throw new RuntimeException("The docker build directory already exists: " + buildDir);
|
||||
}
|
||||
Files.createDirectories(buildDir);
|
||||
|
||||
Path jdkSrcDir = Paths.get(JDK_UNDER_TEST);
|
||||
Path jdkDstDir = buildDir.resolve("jdk");
|
||||
|
||||
Files.createDirectories(jdkDstDir);
|
||||
// Generate Dockerfile
|
||||
if (dockerfileContent != null) {
|
||||
Files.writeString(buildDir.resolve("Dockerfile"), dockerfileContent);
|
||||
} else {
|
||||
generateDockerFile(buildDir.resolve("Dockerfile"),
|
||||
DockerfileConfig.getBaseImageName(),
|
||||
DockerfileConfig.getBaseImageVersion());
|
||||
}
|
||||
|
||||
// Copy JDK-under-test tree to the docker build directory.
|
||||
// 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));
|
||||
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 dockerfile path to the Dockerfile to be used for building the docker
|
||||
* image. The specified dockerfile will be copied to the docker build
|
||||
* directory as 'Dockerfile'
|
||||
* @param buildDir build directory; it should already contain all the content
|
||||
* needed to build the docker image.
|
||||
* @param buildDir build directory; it should already contain all the content
|
||||
* needed to build the image.
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void
|
||||
buildDockerImage(String imageName, Path dockerfile, Path buildDir) throws Exception {
|
||||
|
||||
generateDockerFile(buildDir.resolve("Dockerfile"),
|
||||
DockerfileConfig.getBaseImageName(),
|
||||
DockerfileConfig.getBaseImageVersion());
|
||||
private static void buildImage(String imageName, Path buildDir) throws Exception {
|
||||
try {
|
||||
// Build the docker
|
||||
execute(Container.ENGINE_COMMAND, "build", "--no-cache", "--tag", imageName, buildDir.toString())
|
||||
.shouldHaveExitValue(0);
|
||||
} catch (Exception e) {
|
||||
|
Loading…
Reference in New Issue
Block a user