Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libertyDev task and docs for Podman #843

Merged
merged 7 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
# Run tests
- name: Run tests with Gradle on Ubuntu
run:
./gradlew clean install check -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info
./gradlew clean install check -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" -P"test.exclude"="**/DevContainerTest*" --stacktrace --info
# Copy build reports and upload artifact if build failed
- name: Copy build/report/tests/test for upload
if: ${{ failure() }}
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
- name: Run tests with Gradle on Windows
working-directory: C:/ci.gradle
# LibertyTest is excluded because test0_run hangs
run: ./gradlew clean install check -P"test.exclude"="**/Polling*,**/LibertyTest*,**/GenerateFeaturesTest*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info --no-daemon
run: ./gradlew clean install check -P"test.exclude"="**/Polling*,**/LibertyTest*,**/GenerateFeaturesTest*,**/DevContainerTest*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" --stacktrace --info --no-daemon
timeout-minutes: 75
# Copy build reports and upload artifact if build failed
- name: Copy build/report/tests/test for upload
Expand Down
76 changes: 46 additions & 30 deletions docs/libertyDev.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corporation 2020.
* (C) Copyright IBM Corporation 2020, 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,10 +18,17 @@ package io.openliberty.tools.gradle.extensions

class DevExtension {
boolean container = false
File containerfile
File containerBuildContext
String containerRunOpts
int containerBuildTimeout
boolean skipDefaultPorts = false
boolean keepTempContainerfile = false

//Docker aliases to maintain backwards compatability
File dockerfile
File dockerBuildContext
String dockerRunOpts
int dockerBuildTimeout
boolean skipDefaultPorts = false
boolean keepTempDockerfile = false
}
138 changes: 88 additions & 50 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DevTask extends AbstractFeatureTask {
private static final boolean DEFAULT_POLLING_TEST = false;
private static final boolean DEFAULT_CONTAINER = false;
private static final boolean DEFAULT_SKIP_DEFAULT_PORTS = false;
private static final boolean DEFAULT_KEEP_TEMP_DOCKERFILE = false;
private static final boolean DEFAULT_KEEP_TEMP_CONTAINERFILE = false;
private static final boolean DEFAULT_GENERATE_FEATURES = false;
private static final boolean DEFAULT_SKIP_INSTALL_FEATURE = false;

Expand Down Expand Up @@ -184,7 +184,7 @@ class DevTask extends AbstractFeatureTask {
@Input
private Boolean container = null;

@Option(option = 'container', description = 'Run the server in a Docker container instead of locally. The default value is false for the libertyDev task, and true for the libertyDevc task.')
@Option(option = 'container', description = 'Run the server in a container instead of locally. The default value is false for the libertyDev task, and true for the libertyDevc task.')
void setContainer(boolean container) {
this.container = container;
project.liberty.dev.container = container; // Needed in DeployTask and AbstractServerTask
Expand All @@ -194,23 +194,41 @@ class DevTask extends AbstractFeatureTask {
return container;
}

private File containerfile;

@Option(option = 'containerfile', description = 'Dev mode will build a container image from the provided Containerfile/Dockerfile and start a container from the new image.')
void setContainerfile(String containerfile) {
if (containerfile != null) {
// ensures the containerfile is defined with the full path - matches how maven behaves
this.containerfile = convertParameterToCanonicalFile(containerfile, "containerfile");
}
}

private File dockerfile;

@Option(option = 'dockerfile', description = 'Dev mode will build a docker image from the provided Dockerfile and start a container from the new image.')
@Option(option = 'dockerfile', description = 'Alias for containerfile')
void setDockerfile(String dockerfile) {
if (dockerfile != null) {
// ensures the dockerfile is defined with the full path - matches how maven behaves
this.dockerfile = convertParameterToCanonicalFile(dockerfile, "dockerfile");
if (dockerfile != null && containerfile == null) {
setContainerFile(dockerfile)
}
}

private File containerBuildContext;

@Option(option = 'containerBuildContext', description = 'The container build context used when building the container in dev mode. Defaults to the directory of the Containerfile/Dockerfile if not specified.')
void setContainerBuildContext(String containerBuildContext) {
if (containerBuildContext != null) {
// ensures the containerBuildContext is defined with the full path - matches how maven behaves
this.containerBuildContext = convertParameterToCanonicalFile(containerBuildContext, "containerBuildContext");
}
}

private File dockerBuildContext;

@Option(option = 'dockerBuildContext', description = 'The Docker build context used when building the container in dev mode. Defaults to the directory of the Dockerfile if not specified.')
@Option(option = 'dockerBuildContext', description = 'Alias for containerBuildContext')
void setDockerBuildContext(String dockerBuildContext) {
if (dockerBuildContext != null) {
// ensures the dockerBuildContext is defined with the full path - matches how maven behaves
this.dockerBuildContext = convertParameterToCanonicalFile(dockerBuildContext, "dockerBuildContext");
if (dockerBuildContext != null && containerBuildContext == null) {
setContainerBuildContext(dockerBuildContext)
}
}

Expand All @@ -231,37 +249,57 @@ class DevTask extends AbstractFeatureTask {
return result;
}

private String dockerRunOpts;
private String containerRunOpts;

@Option(option = 'dockerRunOpts', description = 'Additional options for the docker run command when dev mode starts a container.')
@Option(option = 'containerRunOpts', description = 'Additional options for the container run command when dev mode starts a container.')
void setContainerRunOpts(String containerRunOpts) {
this.containerRunOpts = containerRunOpts;
}

private String dockerRunOpts;
@Option(option = 'dockerRunOpts', description = 'Alias for containerRunOpts')
void setDockerRunOpts(String dockerRunOpts) {
this.dockerRunOpts = dockerRunOpts;
if (containerRunOpts == null) {
setContainerRunOpts(dockerRunOpts)
}
}

private int dockerBuildTimeout;
private int containerBuildTimeout;

@Option(option = 'dockerBuildTimeout', description = 'Specifies the amount of time to wait (in seconds) for the completion of the Docker operation to build the image.')
void setDockerBuildTimeout(String inputValue) {
@Option(option = 'containerBuildTimeout', description = 'Specifies the amount of time to wait (in seconds) for the completion of the container operation to build the image.')
void setContainerBuildTimeout(String inputValue) {
try {
this.dockerBuildTimeout = Integer.valueOf(inputValue);
this.containerBuildTimeout = Integer.valueOf(inputValue);
} catch (NumberFormatException e) {
logger.error(String.format("Unexpected value: %s for dev mode option dockerBuildTimeout. dockerBuildTimeout should be a valid integer.", inputValue));
logger.error(String.format("Unexpected value: %s for dev mode option containerBuildTimeout. containerBuildTimeout should be a valid integer.", inputValue));
throw e;
}
}

private int dockerBuildTimeout;
@Option(option = 'dockerBuildTimeout', description = 'Alias for containerBuildTimeout')
void setDockerBuildTimeout(String inputValue) {
setContainerBuildTimeout(inputValue)
cherylking marked this conversation as resolved.
Show resolved Hide resolved
}

private Boolean skipDefaultPorts;

@Option(option = 'skipDefaultPorts', description = 'If true, the default Docker port mappings are skipped in the docker run command.')
@Option(option = 'skipDefaultPorts', description = 'If true, the default container port mappings are skipped in the container run command.')
void setSkipDefaultPorts(boolean skipDefaultPorts) {
this.skipDefaultPorts = skipDefaultPorts;
}

private Boolean keepTempDockerfile;
private Boolean keepTempContainerfile;

@Option(option = 'keepTempDockerfile', description = 'If true, preserve the temporary Dockerfile used to build the container.')
@Option(option = 'keepTempContainerfile', description = 'If true, preserve the temporary Containerfile/Dockerfile used to build the container.')
void setKeepTempContainerfile(boolean keepTempContainerfile) {
this.keepTempContainerfile = keepTempContainerfile;
}

private Boolean keepTempDockerfile;
@Option(option = 'keepTempDockerfile', description = 'Alias for keepTempContainerfile')
void setKeepTempDockerfile(boolean keepTempDockerfile) {
this.keepTempDockerfile = keepTempDockerfile;
setKeepTempContainerfile(keepTempDockerfile)
cherylking marked this conversation as resolved.
Show resolved Hide resolved
}

@Optional
Expand Down Expand Up @@ -315,15 +353,15 @@ class DevTask extends AbstractFeatureTask {
File configDirectory, File projectDirectory, List<File> resourceDirs,
boolean hotTests, boolean skipTests, boolean skipInstallFeature, String artifactId, int serverStartTimeout,
int verifyAppStartTimeout, int appUpdateTimeout, double compileWait,
boolean libertyDebug, boolean pollingTest, boolean container, File dockerfile, File dockerBuildContext,
String dockerRunOpts, int dockerBuildTimeout, boolean skipDefaultPorts, boolean keepTempDockerfile,
boolean libertyDebug, boolean pollingTest, boolean container, File containerfile, File containerBuildContext,
String containerRunOpts, int containerBuildTimeout, boolean skipDefaultPorts, boolean keepTempContainerfile,
String mavenCacheLocation, String packagingType, File buildFile, boolean generateFeatures
) throws IOException {
super(buildDir, serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, /* multi module project directory */ projectDirectory,
resourceDirs, hotTests, skipTests, false /* skipUTs */, false /* skipITs */, skipInstallFeature, artifactId, serverStartTimeout,
verifyAppStartTimeout, appUpdateTimeout, ((long) (compileWait * 1000L)), libertyDebug,
true /* useBuildRecompile */, true /* gradle */, pollingTest, container, dockerfile, dockerBuildContext, dockerRunOpts, dockerBuildTimeout, skipDefaultPorts,
null /* compileOptions not needed since useBuildRecompile is true */, keepTempDockerfile, mavenCacheLocation, null /* multi module upstream projects */,
true /* useBuildRecompile */, true /* gradle */, pollingTest, container, containerfile, containerBuildContext, containerRunOpts, containerBuildTimeout, skipDefaultPorts,
null /* compileOptions not needed since useBuildRecompile is true */, keepTempContainerfile, mavenCacheLocation, null /* multi module upstream projects */,
false /* recompileDependencies only supported in ci.maven */, packagingType, buildFile, null /* parent build files */, generateFeatures, null /* compileArtifactPaths */, null /* testArtifactPaths */, new ArrayList<Path>() /* webResources */
);

Expand Down Expand Up @@ -1133,8 +1171,8 @@ class DevTask extends AbstractFeatureTask {
serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, project.getRootDir(),
resourceDirs, hotTests.booleanValue(), skipTests.booleanValue(), skipInstallFeature.booleanValue(), artifactId, serverStartTimeout.intValue(),
verifyAppStartTimeout.intValue(), verifyAppStartTimeout.intValue(), compileWait.doubleValue(),
libertyDebug.booleanValue(), pollingTest.booleanValue(), container.booleanValue(), dockerfile, dockerBuildContext, dockerRunOpts,
dockerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempDockerfile.booleanValue(), localMavenRepoForFeatureUtility,
libertyDebug.booleanValue(), pollingTest.booleanValue(), container.booleanValue(), containerfile, containerBuildContext, containerRunOpts,
containerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempContainerfile.booleanValue(), localMavenRepoForFeatureUtility,
getPackagingType(), buildFile, generateFeatures.booleanValue()
);

Expand Down Expand Up @@ -1224,7 +1262,7 @@ class DevTask extends AbstractFeatureTask {
} else {
// skip creating the server and installing features and just propagate the option to 'deploy'
createServerDirectories();
gradleBuildLauncher.addArguments("--exclude-task", "installFeature"); // skip installing features at startup since Dockerfile should have RUN features.sh
gradleBuildLauncher.addArguments("--exclude-task", "installFeature"); // skip installing features at startup since Containerfile/Dockerfile should have RUN features.sh
gradleBuildLauncher.addArguments(CONTAINER_PROPERTY_ARG);
}
runGradleTask(gradleBuildLauncher, 'deploy');
Expand Down Expand Up @@ -1302,31 +1340,31 @@ class DevTask extends AbstractFeatureTask {
}
}

if (dockerfile == null) {
File buildDockerfileSetting = project.liberty.dev.dockerfile; // get from build.gradle
if (buildDockerfileSetting != null) {
setDockerfile(buildDockerfileSetting.getAbsolutePath()); // setDockerfile will convert it to canonical path
if (containerfile == null) {
File buildcontainerfileSetting = project.liberty.dev.containerfile; // get from build.gradle
cherylking marked this conversation as resolved.
Show resolved Hide resolved
if (buildcontainerfileSetting != null) {
setContainerfile(buildcontainerfileSetting.getAbsolutePath()); // setContainerfile will convert it to canonical path
}
}

if (dockerBuildContext == null) {
File buildDockerBuildContextSetting = project.liberty.dev.dockerBuildContext; // get from build.gradle
if (buildDockerBuildContextSetting != null) {
setDockerBuildContext(buildDockerBuildContextSetting.getAbsolutePath()); // setDockerBuildContext will convert it to canonical path
if (containerBuildContext == null) {
File buildContainerBuildContextSetting = project.liberty.dev.containerBuildContext; // get from build.gradle
if (buildContainerBuildContextSetting != null) {
cherylking marked this conversation as resolved.
Show resolved Hide resolved
setContainerBuildContext(buildContainerBuildContextSetting.getAbsolutePath()); // setContainerBuildContext will convert it to canonical path
}
}

if (dockerRunOpts == null) {
String buildDockerRunOptsSetting = project.liberty.dev.dockerRunOpts; // get from build.gradle
if (buildDockerRunOptsSetting != null) {
setDockerRunOpts(buildDockerRunOptsSetting);
if (containerRunOpts == null) {
String buildContainerRunOptsSetting = project.liberty.dev.containerRunOpts; // get from build.gradle
if (buildContainerRunOptsSetting != null) {
cherylking marked this conversation as resolved.
Show resolved Hide resolved
setContainerRunOpts(buildContainerRunOptsSetting);
}
}

if (dockerBuildTimeout == 0) {
String buildDockerBuildTimeoutSetting = project.liberty.dev.dockerBuildTimeout; // get from build.gradle
if (buildDockerBuildTimeoutSetting != null) {
setDockerBuildTimeout(buildDockerBuildTimeoutSetting);
if (containerBuildTimeout == 0) {
String buildContainerBuildTimeoutSetting = project.liberty.dev.containerBuildTimeout; // get from build.gradle
if (buildContainerBuildTimeoutSetting != null) {
cherylking marked this conversation as resolved.
Show resolved Hide resolved
setContainerBuildTimeout(buildContainerBuildTimeoutSetting);
}
}

Expand All @@ -1339,12 +1377,12 @@ class DevTask extends AbstractFeatureTask {
}
}

if (keepTempDockerfile == null) {
boolean buildKeepTempDockerfileSetting = project.liberty.dev.keepTempDockerfile; // get from build.gradle
if (buildKeepTempDockerfileSetting == null) {
setKeepTempDockerfile(DEFAULT_KEEP_TEMP_DOCKERFILE);
if (keepTempContainerfile == null) {
boolean buildKeepTempContainerfileSetting = project.liberty.dev.keepTempContainerfile; // get from build.gradle
if (buildKeepTempContainerfileSetting == null) {
cherylking marked this conversation as resolved.
Show resolved Hide resolved
setKeepTempContainerfile(DEFAULT_KEEP_TEMP_CONTAINERFILE);
} else {
setKeepTempDockerfile(buildKeepTempDockerfileSetting);
setKeepTempContainerfile(buildKeepTempContainerfileSetting);
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/test/groovy/io/openliberty/tools/gradle/BaseDevTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,20 @@ class BaseDevTest extends AbstractIntegrationTest {
}

protected static void cleanUpAfterClass(boolean isDevMode) throws Exception {
stopProcess(isDevMode);
stopProcess(isDevMode, errFile);
if (buildDir != null && buildDir.exists()) {
FileUtils.deleteQuietly(buildDir); // try this method that does not throw an exception
}
}

private static void stopProcess(boolean isDevMode) throws IOException, InterruptedException, FileNotFoundException {
protected static void cleanUpAfterClassCheckLogFile(boolean isDevMode) throws Exception {
stopProcess(isDevMode, logFile);
if (buildDir != null && buildDir.exists()) {
FileUtils.deleteQuietly(buildDir); // try this method that does not throw an exception
}
}

private static void stopProcess(boolean isDevMode, File testLogFile) throws IOException, InterruptedException, FileNotFoundException {
// shut down dev mode
if (writer != null) {
int serverStoppedOccurrences = countOccurrences("CWWKE0036I", logFile);
Expand All @@ -301,7 +308,7 @@ class BaseDevTest extends AbstractIntegrationTest {
}

// test that dev mode has stopped running
assertTrue(verifyLogMessage(100000, "CWWKE0036I", errFile, ++serverStoppedOccurrences));
assertTrue(verifyLogMessage(100000, "CWWKE0036I", testLogFile, ++serverStoppedOccurrences));
Thread.sleep(5000); // wait 5s to ensure java process has stopped
}
}
Expand Down
Loading
Loading