Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/containers/docker/DockerBasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void main(String[] args) throws Exception {
return;
}

DockerTestUtils.buildJdkDockerImage(imageNameAndTag, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageNameAndTag);

try {
testJavaVersion();
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/containers/docker/TestCPUAwareness.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void main(String[] args) throws Exception {
}

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
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/containers/docker/TestCPUSets.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void main(String[] args) throws Exception {


Common.prepareWhiteBox();
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
// Sanity test the cpu sets reader and parser
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/containers/docker/TestJFREvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void main(String[] args) throws Exception {
return;
}

DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void main(String[] args) throws Exception {
return;
}

DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
runTest("jdk.SocketWrite");
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/containers/docker/TestJFRWithJMX.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void main(String[] args) throws Exception {
throw new SkippedException("test cannot be run under rootless podman configuration");
}

DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
test();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void main(String[] args) throws Exception {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception {
}

Common.prepareWhiteBox();
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
testMemoryLimit("100m", "104857600");
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/containers/docker/TestMisc.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception {
}

Common.prepareWhiteBox();
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
testMinusContainerSupport();
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/containers/docker/TestPids.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void main(String[] args) throws Exception {
}

Common.prepareWhiteBox();
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
testPids();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void main(String[] args) throws Exception {
// 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void main(String[] args) throws Exception {
// 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void main(String[] args) throws Exception {
return;
}

DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
testGetFreeSwapSpaceSize(
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/jdk/internal/platform/docker/TestPidsLimit.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void main(String[] args) throws Exception {
return;
}

DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
testPidsLimit("1000");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception {
return;
}

DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
Common.logNewTestCase("Test SystemMetrics");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void main(String[] args) throws Exception {
return;
}

DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
DockerTestUtils.buildJdkContainerImage(imageName);

try {
testUseContainerSupport(true);
Expand Down
71 changes: 39 additions & 32 deletions test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -120,59 +120,66 @@ private static boolean isDockerEngineAvailableCheck() throws Exception {
return true;
}

/**
* 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
* @throws Exception
*/
public static void buildJdkContainerImage(String imageName) throws Exception {
buildJdkContainerImage(imageName, null);
}

/**
* 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
* @param dockerfileContent content of the Dockerfile; use null to generate default content
* @throws Exception
*/
public static void
buildJdkDockerImage(String imageName, String dockerfile, String buildDirName)
throws Exception {
public static void buildJdkContainerImage(String imageName, String dockerfileContent) throws Exception {
// image name may contain tag, hence replace ':'
String imageDirName = imageName.replace(":", "-");

Path buildDir = Paths.get(".", buildDirName);
// 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) {
Expand Down