diff --git a/quickstarts/maven/openliberty-microprofile/README.md b/quickstarts/maven/openliberty-microprofile/README.md new file mode 100644 index 0000000000..961d6cb9ec --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/README.md @@ -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. \ No newline at end of file diff --git a/quickstarts/maven/openliberty-microprofile/docs/openliberty-microprofile-minikube.png b/quickstarts/maven/openliberty-microprofile/docs/openliberty-microprofile-minikube.png new file mode 100644 index 0000000000..a2d9f63834 Binary files /dev/null and b/quickstarts/maven/openliberty-microprofile/docs/openliberty-microprofile-minikube.png differ diff --git a/quickstarts/maven/openliberty-microprofile/docs/openliberty-microprofile-openshift.png b/quickstarts/maven/openliberty-microprofile/docs/openliberty-microprofile-openshift.png new file mode 100644 index 0000000000..c9469c1164 Binary files /dev/null and b/quickstarts/maven/openliberty-microprofile/docs/openliberty-microprofile-openshift.png differ diff --git a/quickstarts/maven/openliberty-microprofile/pom.xml b/quickstarts/maven/openliberty-microprofile/pom.xml new file mode 100644 index 0000000000..8b6a403f87 --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/pom.xml @@ -0,0 +1,150 @@ + + + + 4.0.0 + + org.eclipse.jkube.quickstarts.maven + openliberty-microprofile + 1.0.1 + Eclipse JKube :: Quickstarts :: Maven :: Open Liberty & MicroProfile + war + + + 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. + + + + 1.8 + 1.8 + ${project.version} + 19.0.0.9 + 3.3 + 0.34.0 + 3.2 + 9080 + 9443 + false + + + + + org.eclipse.microprofile + microprofile + ${version.microprofile} + pom + provided + + + io.jaegertracing + jaeger-client + ${version.jaeger-client} + + + + + + + io.openliberty.tools + liberty-maven-plugin + ${version.openliberty-maven} + + + package-server + package + + create + install-feature + deploy + package + + + true + true + project + ${project.artifactId} + jar + + + + + runnable + ${final.name} + + ${http.port} + ${https.port} + / + ${project.artifactId} + + + + + + + + + kubernetes + + + + org.eclipse.jkube + kubernetes-maven-plugin + ${jkube.version} + + + + resource + build + + + + + + + + NodePort + + + + + + + + + + openshift + + + + org.eclipse.jkube + openshift-maven-plugin + ${jkube.version} + + + + resource + build + + + + + + + + + \ No newline at end of file diff --git a/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/HelloController.java b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/HelloController.java new file mode 100644 index 0000000000..b6e4652978 --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/HelloController.java @@ -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"; + } +} diff --git a/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/MicroprofileRestApplication.java b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/MicroprofileRestApplication.java new file mode 100644 index 0000000000..b94a1429c6 --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/MicroprofileRestApplication.java @@ -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 { +} diff --git a/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/config/ConfigTestController.java b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/config/ConfigTestController.java new file mode 100644 index 0000000000..69e1edb07e --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/config/ConfigTestController.java @@ -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; + } +} diff --git a/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/health/ServiceLiveHealthCheck.java b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/health/ServiceLiveHealthCheck.java new file mode 100644 index 0000000000..7b7451addb --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/health/ServiceLiveHealthCheck.java @@ -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(); + } +} diff --git a/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/health/ServiceReadyHealthCheck.java b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/health/ServiceReadyHealthCheck.java new file mode 100644 index 0000000000..3a153efa1c --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/java/org/eclipse/jkube/quickstarts/maven/microprofile/customized/image/health/ServiceReadyHealthCheck.java @@ -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(); + + } +} diff --git a/quickstarts/maven/openliberty-microprofile/src/main/jkube/deployment.yml b/quickstarts/maven/openliberty-microprofile/src/main/jkube/deployment.yml new file mode 100644 index 0000000000..f664089b00 --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/jkube/deployment.yml @@ -0,0 +1,35 @@ +# +# 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 +# + +--- +spec: + template: + spec: + containers: + - livenessProbe: + failureThreshold: 3 + httpGet: + path: /health/live + port: ${http.port} + scheme: HTTP + initialDelaySeconds: 60 + successThreshold: 1 + readinessProbe: + failureThreshold: 3 + httpGet: + path: /health/ready + port: ${http.port} + scheme: HTTP + initialDelaySeconds: 60 + successThreshold: 1 diff --git a/quickstarts/maven/openliberty-microprofile/src/main/liberty/config/server.xml b/quickstarts/maven/openliberty-microprofile/src/main/liberty/config/server.xml new file mode 100644 index 0000000000..8d0b82ba44 --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/liberty/config/server.xml @@ -0,0 +1,38 @@ + + + + + + microProfile-3.3 + + + + + + + + + + + + + + + + + diff --git a/quickstarts/maven/openliberty-microprofile/src/main/resources/.gitkeep b/quickstarts/maven/openliberty-microprofile/src/main/resources/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/quickstarts/maven/openliberty-microprofile/src/main/resources/META-INF/microprofile-config.properties b/quickstarts/maven/openliberty-microprofile/src/main/resources/META-INF/microprofile-config.properties new file mode 100644 index 0000000000..01b37ce4c3 --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/resources/META-INF/microprofile-config.properties @@ -0,0 +1,18 @@ +# +# 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 +# + + +injected.value=Injected value +value=lookup value + diff --git a/quickstarts/maven/openliberty-microprofile/src/main/webapp/.gitkeep b/quickstarts/maven/openliberty-microprofile/src/main/webapp/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/quickstarts/maven/openliberty-microprofile/src/main/webapp/WEB-INF/beans.xml b/quickstarts/maven/openliberty-microprofile/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..b57bbcf02d --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,21 @@ + + + + diff --git a/quickstarts/maven/openliberty-microprofile/src/main/webapp/index.html b/quickstarts/maven/openliberty-microprofile/src/main/webapp/index.html new file mode 100644 index 0000000000..cc5294b71d --- /dev/null +++ b/quickstarts/maven/openliberty-microprofile/src/main/webapp/index.html @@ -0,0 +1,37 @@ + + + + + + Eclipse MicroProfile demo with some help from Eclipse JKube! + + + +

MicroProfile

+ +Hello JAX-RS endpoint
+ +

Config

+Injected config values
+Config values by lookup
+ +

Health

+Health (Live) status (with custom status)
+Health (Ready) status (with custom status)
+ + + \ No newline at end of file