-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added quickstart for MicroProfile running on OpenLiberty
Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
Showing
16 changed files
with
518 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Eclipse JKube OpenLiberty MicroProfile Quickstart | ||
|
||
This example shows how to integrate Eclipse JKube in an OpenLiberty-MicroProfile application as downloaded from | ||
[start.microprofile.io](https://start.microprofile.io). | ||
|
||
```shell script | ||
$ curl -O -J 'https://start.microprofile.io/api/project?supportedServer=LIBERTY&mpVersion=MP33&selectedSpecs=CONFIG&selectedSpecs=HEALTH_CHECKS' | ||
``` | ||
|
||
Includes a JAX-RS REST endpoint, CDI injected configuration and healthchecks as provided by | ||
[MicroProfile Health](https://github.com/eclipse/microprofile-health). | ||
|
||
|
||
## Requirements | ||
|
||
- JDK 1.8+ | ||
- Kubernetes Cluster (Minikube, OpenShift, CRC, etc.) | ||
|
||
## Building and deploying the application | ||
|
||
If running on Minikube, share your cluster's Docker daemon first: | ||
```shell script | ||
$ eval $(minikube docker-env) | ||
``` | ||
|
||
```shell script | ||
# Kubernetes | ||
$ mvn clean package -Pkubernetes k8s:deploy | ||
# OpenShift | ||
$ mvn clean package -Popenshift oc:deploy | ||
``` | ||
|
||
## Expected output | ||
|
||
Once you've deployed the application _(please allow 1 minute for the application to start)_, you should be able to do the following: | ||
|
||
### Minikube | ||
|
||
```shell script | ||
$ minikube service openliberty-microprofile | ||
``` | ||
|
||
A browser window should open with the following content: | ||
|
||
![A screenshot of the MicroProfile OpenLiberty Application running on Minikube](./docs/openliberty-microprofile-minikube.png) | ||
|
||
You should now be able to check the exposed links. | ||
|
||
### OpenShift | ||
|
||
Get the automatically created Route for your application: | ||
|
||
```shell script | ||
$ oc get routes.route.openshift.io openliberty-microprofile -o jsonpath='{.spec.host} | ||
openliberty-microprofile-jkube.b6ff.openshift-cluster.example.com | ||
``` | ||
Open the returned URL in your preferred browser: | ||
![A screenshot of the MicroProfile OpenLiberty Application running on OpenShift](./docs/openliberty-microprofile-openshift.png) | ||
You should now be able to check the exposed links. |
Binary file added
BIN
+34.3 KB
...tarts/maven/openliberty-microprofile/docs/openliberty-microprofile-minikube.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.2 KB
...arts/maven/openliberty-microprofile/docs/openliberty-microprofile-openshift.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2019 Red Hat, Inc. | ||
This program and the accompanying materials are made | ||
available under the terms of the Eclipse Public License 2.0 | ||
which is available at: | ||
https://www.eclipse.org/legal/epl-2.0/ | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.eclipse.jkube.quickstarts.maven</groupId> | ||
<artifactId>openliberty-microprofile</artifactId> | ||
<version>1.0.1</version> | ||
<name>Eclipse JKube :: Quickstarts :: Maven :: Open Liberty & MicroProfile</name> | ||
<packaging>war</packaging> | ||
|
||
<description> | ||
How to integrate Eclipse JKube into an OpenLiberty-MicroProfile project as downloaded from start.microprofile.io. | ||
Includes a JAX-RS endpoint, sample CDI injected configuration, and Liveness and Readiness probes. | ||
</description> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<jkube.version>${project.version}</jkube.version> | ||
<version.openliberty>19.0.0.9</version.openliberty> | ||
<version.microprofile>3.3</version.microprofile> | ||
<version.jaeger-client>0.34.0</version.jaeger-client> | ||
<version.openliberty-maven>3.2</version.openliberty-maven> | ||
<http.port>9080</http.port> | ||
<https.port>9443</https.port> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile</groupId> | ||
<artifactId>microprofile</artifactId> | ||
<version>${version.microprofile}</version> | ||
<type>pom</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.jaegertracing</groupId> | ||
<artifactId>jaeger-client</artifactId> | ||
<version>${version.jaeger-client}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.openliberty.tools</groupId> | ||
<artifactId>liberty-maven-plugin</artifactId> | ||
<version>${version.openliberty-maven}</version> | ||
<executions> | ||
<execution> | ||
<id>package-server</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>create</goal> | ||
<goal>install-feature</goal> | ||
<goal>deploy</goal> | ||
<goal>package</goal> | ||
</goals> | ||
<configuration> | ||
<looseApplication>true</looseApplication> | ||
<stripVersion>true</stripVersion> | ||
<installAppPackages>project</installAppPackages> | ||
<packageName>${project.artifactId}</packageName> | ||
<packageType>jar</packageType> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<include>runnable</include> | ||
<serverName>${final.name}</serverName> | ||
<bootstrapProperties> | ||
<default.http.port>${http.port}</default.http.port> | ||
<default.https.port>${https.port}</default.https.port> | ||
<app.context.root>/</app.context.root> | ||
<package.name>${project.artifactId}</package.name> | ||
</bootstrapProperties> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>kubernetes</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>kubernetes-maven-plugin</artifactId> | ||
<version>${jkube.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>resource</goal> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<enricher> | ||
<config> | ||
<jkube-service> | ||
<type>NodePort</type> | ||
</jkube-service> | ||
</config> | ||
</enricher> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>openshift</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>openshift-maven-plugin</artifactId> | ||
<version>${jkube.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>resource</goal> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
...va/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.quickstarts.maven.microprofile.customized.image; | ||
|
||
import javax.inject.Singleton; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("/hello") | ||
@Singleton | ||
public class HelloController { | ||
|
||
@GET | ||
public String sayHello() { | ||
return "Hello World"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...se/jkube/quickstarts/maven/microprofile/customized/image/MicroprofileRestApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.quickstarts.maven.microprofile.customized.image; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
|
||
@ApplicationPath("/data") | ||
public class MicroprofileRestApplication extends Application { | ||
} |
46 changes: 46 additions & 0 deletions
46
...se/jkube/quickstarts/maven/microprofile/customized/image/config/ConfigTestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.quickstarts.maven.microprofile.customized.image.config; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("/config") | ||
@RequestScoped | ||
public class ConfigTestController { | ||
|
||
@Inject | ||
@ConfigProperty(name = "injected.value") | ||
private String injectedValue; | ||
|
||
@Path("/injected") | ||
@GET | ||
public String getInjectedConfigValue() { | ||
return "Config value as Injected by CDI " + injectedValue; | ||
} | ||
|
||
@Path("/lookup") | ||
@GET | ||
public String getLookupConfigValue() { | ||
Config config = ConfigProvider.getConfig(); | ||
String value = config.getValue("value", String.class); | ||
return "Config value from ConfigProvider " + value; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../jkube/quickstarts/maven/microprofile/customized/image/health/ServiceLiveHealthCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.quickstarts.maven.microprofile.customized.image.health; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Liveness; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@Liveness | ||
@ApplicationScoped | ||
public class ServiceLiveHealthCheck implements HealthCheck { | ||
|
||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.named(ServiceLiveHealthCheck.class.getSimpleName()).withData("live",true).up().build(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...jkube/quickstarts/maven/microprofile/customized/image/health/ServiceReadyHealthCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.quickstarts.maven.microprofile.customized.image.health; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Readiness; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@Readiness | ||
@ApplicationScoped | ||
public class ServiceReadyHealthCheck implements HealthCheck { | ||
|
||
@Override | ||
public HealthCheckResponse call() { | ||
|
||
return HealthCheckResponse.named(ServiceReadyHealthCheck.class.getSimpleName()).withData("ready",true).up().build(); | ||
|
||
} | ||
} |
Oops, something went wrong.