Skip to content

Commit

Permalink
Honor container and docker command line properties for dev mode (#1751)
Browse files Browse the repository at this point in the history
* Honor container and docker command line properties for dev mode

* Update devc parameters

* Use setKeepTempContainerfile() to pass keepTempDockerfile value
  • Loading branch information
mattbsox authored Nov 17, 2023
1 parent f8008dc commit 3817695
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void setUpBeforeClass() throws Exception {
setUpBeforeClass(null, "../resources/container-test-project", true, false, null, null);

// run dev mode with container flag
startProcess("-Dcontainer", true);
startProcess("-Dcontainer -Dliberty.dev.podman=true -DcontainerBuildTimeout=599 -DdockerBuildTimeout=601", true);
}

@AfterClass
Expand All @@ -35,4 +35,19 @@ public void runContainerTest() throws Exception {
assertTrue("The application start message is missing: "+getLogTail(), verifyLogMessageExists("CWWKZ0001I: Application rest started", 2000));
}

@Test
public void devcMetaDataTest() throws Exception {
File devcMetaDataFile = new File("../resources/container-test-project/target/defaultServer-liberty-devc-metadata.xml");

assertTrue("The devc metadata file does not exist.", devcMetaDataFile.exists());

String content = FileUtils.readFileToString(devcMetaDataFile, "UTF-8");

assertTrue("Container name is incorrect in devc metadata XML.", content.contains("<containerName>liberty-dev</containerName"));
assertTrue("Container alive status is incorrect in devc metadata XML.", content.contains("<containerAlive>true</containerAlive>"));
assertTrue("Container build timeout is incorrect in devc metadata XML.", content.contains("<containerBuildTimeout>599</containerBuildTimeout>"));
assertTrue("Container engine is incorrect in devc metadata XML.", content.contains("<containerEngine>podman</containerEngine>"));
assertTrue("Container run options are incorrect in devc metadata XML.", content.contains("<containerRunOpts></containerRunOpts>"));
assertTrue("Container image name is incorrect in devc metadata XML.", content.contains("<imageName>dev-containers-it-dev-mode</imageName>"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,31 @@ public class DevMojo extends LooseAppSupport {
* Containerfile used to build an image to then start a container with
*/
@Parameter(alias="containerfile", property = "containerfile")
private File dockerfile;
private File containerfile;

@Parameter(alias="dockerfile", property = "dockerfile")
public void setDockerfile(File dockerfile) {
if (dockerfile != null && this.containerfile != null) {
getLog().warn("Both containerfile and dockerfile have been set. Using containerfile value.");
} else {
this.containerfile = dockerfile;
}
}

/**
* Context (directory) to use for the build when building the container image
*/
@Parameter(alias="containerBuildContext", property = "containerBuildContext")
private File dockerBuildContext;
private File containerBuildContext;

@Parameter(alias="dockerBuildContext", property = "dockerBuildContext")
public void setDockerBuildContext(File dockerBuildContext) {
if (dockerBuildContext != null && this.containerBuildContext != null) {
getLog().warn("Both containerBuildContext and dockerBuildContext have been set. Using containerBuildContext value.");
} else {
this.containerBuildContext = dockerBuildContext;
}
}

/**
* The directory for source files.
Expand Down Expand Up @@ -231,17 +249,35 @@ public class DevMojo extends LooseAppSupport {

/**
* Additional options for the container run command when dev mode starts a
* container.
* container. Takes precedence over dockerRunOpts.
*/
@Parameter(alias="containerRunOpts", property = "containerRunOpts")
private String dockerRunOpts;
private String containerRunOpts;

@Parameter(alias="dockerRunOpts", property = "dockerRunOpts")
public void setDockerRunOpts(String dockerRunOpts) {
if (dockerRunOpts != null && this.containerRunOpts != null) {
getLog().warn("Both containerRunopts and dockerRunOpts have been set. Using containerRunOpts value.");
} else {
this.containerRunOpts = dockerRunOpts;
}
}

/**
* Specify the amount of time in seconds that dev mode waits for the container
* build command to run to completion. Default to 600 seconds.
*/
@Parameter(alias="containerBuildTimeout", property = "containerBuildTimeout", defaultValue = "600")
private int dockerBuildTimeout;
private int containerBuildTimeout;

@Parameter(alias="dockerBuildTimeout", property = "dockerBuildTimeout")
public void setDockerBuildTimeout(int dockerBuildTimeout) {
if (dockerBuildTimeout != 600 && this.containerBuildTimeout != 600) {
getLog().warn("Both containerBuildTimeout and dockerBuildTimeout have been set. Using containerBuildTimeout value.");
} else if (dockerBuildTimeout != 600) {
this.containerBuildTimeout = dockerBuildTimeout;
}
}

/**
* If true, the default container port mappings are skipped in the container run
Expand All @@ -253,8 +289,19 @@ public class DevMojo extends LooseAppSupport {
/**
* If true, preserve the temporary Containerfile/Dockerfile used in the container build command
*/
@Parameter(alias="keepTempContainerfile", property = "keepTempContainerfile", defaultValue = "false")
private boolean keepTempDockerfile;
private Boolean keepTempContainerfile;

@Parameter(alias="keepTempContainerfile", property = "keepTempContainerfile")
public void setKeepTempContainerfile(Boolean keepTempContainerfile) {
this.keepTempContainerfile = keepTempContainerfile;
}

@Parameter(alias="keepTempDockerfile", property = "keepTempDockerfile", defaultValue = "false")
public void setKeepTempDockerfile(Boolean keepTempDockerfile) {
if (this.keepTempContainerfile == null) {
setKeepTempContainerfile(keepTempDockerfile);
}
}

private boolean isExplodedLooseWarApp = false;
private boolean isNewInstallation = true;
Expand Down Expand Up @@ -302,9 +349,9 @@ public DevMojoUtil(File installDir, File userDir, File serverDirectory, File sou
super(new File(project.getBuild().getDirectory()), serverDirectory, sourceDirectory, testSourceDirectory,
configDirectory, projectDirectory, multiModuleProjectDirectory, resourceDirs, hotTests, skipTests,
skipUTs, skipITs, skipInstallFeature, project.getArtifactId(), serverStartTimeout, verifyTimeout, verifyTimeout,
((long) (compileWait * 1000L)), libertyDebug, false, false, pollingTest, container, dockerfile,
dockerBuildContext, dockerRunOpts, dockerBuildTimeout, skipDefaultPorts, compilerOptions,
keepTempDockerfile, mavenCacheLocation, upstreamProjects, recompileDeps, project.getPackaging(),
((long) (compileWait * 1000L)), libertyDebug, false, false, pollingTest, container, containerfile,
containerBuildContext, containerRunOpts, containerBuildTimeout, skipDefaultPorts, compilerOptions,
keepTempContainerfile, mavenCacheLocation, upstreamProjects, recompileDeps, project.getPackaging(),
pom, parentPoms, generateFeatures, compileArtifactPaths, testArtifactPaths, webResourceDirs);

this.libertyDirPropertyFiles = BasicSupport.getLibertyDirectoryPropertyFiles(installDir, userDir,
Expand Down

0 comments on commit 3817695

Please sign in to comment.