Skip to content

Commit

Permalink
Update libertyDev task and docs for Podman (#843)
Browse files Browse the repository at this point in the history
* Update libertyDev task and docs for Podman

* Use action to install Podman

* Disable DevContainerTest

* Update libertyDev properties and docs
  • Loading branch information
mattbsox authored Sep 21, 2023
1 parent 0f51fc5 commit bb5e6b5
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 91 deletions.
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
}
147 changes: 93 additions & 54 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy

Large diffs are not rendered by default.

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* (C) Copyright IBM Corporation 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.openliberty.tools.gradle;

import static org.junit.Assert.*;

import java.io.BufferedWriter;
import org.apache.commons.io.FileUtils;
import java.io.File;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import org.junit.Test;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

class DevContainerTest extends BaseDevTest {

static final String projectName = "dev-container";
static File resourceDir = new File("build/resources/test/dev-test/" + projectName);
static File testBuildDir = new File(integTestDir, "/test-dev-container")

@BeforeClass
public static void setup() throws IOException, InterruptedException, FileNotFoundException {
createDir(testBuildDir)
createTestProject(testBuildDir, resourceDir, "build.gradle", true)

File buildFile = new File(resourceDir, buildFilename)
copyBuildFiles(buildFile, testBuildDir, false)

runDevMode("--container", testBuildDir)
}

@Test
public void devmodeContainerTest() throws Exception {
assertTrue("The container build did not complete.", verifyLogMessage(20000, "Completed building container image.", logFile));
assertTrue("The application start message is missing.", verifyLogMessage(20000, "CWWKZ0001I: Application rest started", logFile));
}

@AfterClass
public static void cleanUpAfterClass() throws Exception {
String stdout = getContents(logFile, "Dev mode std output");
System.out.println(stdout);
String stderr = getContents(errFile, "Dev mode std error");
System.out.println(stderr);
cleanUpAfterClassCheckLogFile(true);
}
}
33 changes: 33 additions & 0 deletions src/test/resources/dev-test/dev-container/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Start with OL runtime.
# tag::from[]
FROM icr.io/appcafe/open-liberty:full-java11-openj9-ubi
# end::from[]

ARG VERSION=1.0
ARG REVISION=SNAPSHOT
# tag::label[]

LABEL \
org.opencontainers.image.authors="Your Name" \
org.opencontainers.image.vendor="IBM" \
org.opencontainers.image.url="local" \
org.opencontainers.image.source="https://github.com/OpenLiberty/guide-docker" \
org.opencontainers.image.version="$VERSION" \
org.opencontainers.image.revision="$REVISION" \
vendor="Open Liberty" \
name="system" \
version="$VERSION-$REVISION" \
summary="The system microservice from the Docker Guide" \
# tag::description[]
description="This image contains the system microservice running with the Open Liberty runtime."
# end::description[]
# end::label[]


USER root

COPY --chown=1001:0 src/main/liberty/config/server.xml /config/

COPY --chown=1001:0 build/libs/*.war /config/apps/

USER 1001
44 changes: 44 additions & 0 deletions src/test/resources/dev-test/dev-container/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apply plugin: "liberty"
apply plugin: "war"

sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

buildscript {
repositories {
mavenCentral()
mavenLocal()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion"
}
}

repositories {
mavenCentral()
}

dependencies {
providedCompile 'jakarta.platform:jakarta.jakartaee-api:9.1.0'
providedCompile 'org.eclipse.microprofile:microprofile:5.0'

testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
testImplementation 'org.jboss.resteasy:resteasy-client:6.0.0.Final'
testImplementation 'org.jboss.resteasy:resteasy-json-binding-provider:6.0.0.Final'
testImplementation 'org.glassfish:jakarta.json:2.0.1'
testImplementation 'javax.xml.bind:jaxb-api:2.3.1'
}

war {
archiveBaseName = 'rest'
}

test {
systemProperty 'liberty.test.port', '9080'
}
1 change: 1 addition & 0 deletions src/test/resources/dev-test/dev-container/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//Empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2022 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial implementation
*******************************************************************************/
// end::copyright[]
package io.openliberty.guides.rest;

import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Produces;

import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.Json;

// tag::Path[]
@Path("properties")
// end::Path[]
public class PropertiesResource {

@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getProperties() {

JsonObjectBuilder builder = Json.createObjectBuilder();

System.getProperties()
.entrySet()
.stream()
.forEach(entry -> builder.add((String) entry.getKey(),
(String) entry.getValue()));

return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017, 2022 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - Initial implementation
*******************************************************************************/
// end::copyright[]
package io.openliberty.guides.rest;

import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.ApplicationPath;

@ApplicationPath("system")
public class SystemApplication extends Application {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<server description="Sample Liberty server">

<featureManager>
<feature>restfulWS-3.0</feature>
<feature>jsonb-2.0</feature>
<feature>jsonp-2.0</feature>
</featureManager>

<variable name="default.http.port" defaultValue="9080"/>
<variable name="default.https.port" defaultValue="9443"/>

<httpEndpoint httpPort="${default.http.port}" httpsPort="${default.https.port}"
id="defaultHttpEndpoint" host="*" />

<webApplication location="rest.war" contextRoot="/"/>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Liberty Project</display-name>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
Copyright (c) 2016, 2022 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<body>
<h1>Welcome to your Open Liberty application</h1>
<p>Open Liberty is a lightweight open framework for building fast and efficient cloud-native Java microservices. Find out more at <a href="http://openliberty.io/" target="_blank" rel="noopener noreferrer">openliberty.io</a>.</p>
<div>
<h2>Eclipse MicroProfile</h2>
<p>
The <a href="https://microprofile.io/" target="_blank" rel="noopener noreferrer">Eclipse MicroProfile project</a> is an open community with the aim of optimizing enterprise Java for a microservices architecture.
MicroProfile evolves with guidance from the community.
</p>
<p>
If you want to share your thoughts, you can post straight to the
<a href="https://groups.google.com/forum/#!forum/microprofile" target="_blank" rel="noopener noreferrer">MicroProfile Google group</a>.
</p>
<p>
For more information about the features used in this application, see the Open Liberty documentation:
<ul>
<li><a href="https://openliberty.io/docs/ref/feature/#microProfile-5.0.html" target="_blank" rel="noopener noreferrer">MicroProfile 5.0</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#restfulWS-3.0.html" target="_blank" rel="noopener noreferrer">Java RESTful Services 3.0</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonp-2.0.html" target="_blank" rel="noopener noreferrer">JavaScript Object Notation Processing 2.0</a></li>
<li><a href="https://openliberty.io/docs/ref/feature/#jsonb-2.0.html" target="_blank" rel="noopener noreferrer">JavaScript Object Notation Binding 2.0</a></li>
</ul>
</p>
</div>
</body>
</html>
Loading

0 comments on commit bb5e6b5

Please sign in to comment.