In this tutorial we will learn how to deploy a Thorntail application on Openshift. This is the quickest path to leverage Microprofile applications in a PaaS.

Thorntail is the new name for WildFly Swarm, and contains everything you need to develop and run Microprofile applications by packaging server runtime libraries with your application code and running it as Uber Jar application.

In order to deploy Thorntail application we need a Java Runtime that can be used to run the JAR file produced by Thorntail Maven plugin. For this purpose we will use Red Hat Java S2I builder image

Red Hat Java S2I for OpenShift is a Source-to-Image (S2I) builder image designed for use with OpenShift. It allows users to build and run plain Java applications (fat-jar and flat classpath) within a containerized image on OpenShift.

Let's start by creating a new Openshift project named "microprofile-demo":

oc new-project "microprofile-demo"

Now let's import the Java version 8 image from Red Hat's Repository:

oc import-image java:8 --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift --confirm

Now let's use any Thorntail example available on Github. For example this is my fork of Thorntail's examples:

oc new-app --name rest-demo 'java:8~https://github.com/fmarchioni/thorntail-examples' --context-dir='jaxrs/jaxrs-cdi'

As you can see from the output, the following resources will be created:

--> Found image b4b953c (2 weeks old) in image stream "microprofile-demo/java" under tag "8" for "java:8"

    Java Applications 
    ----------------- 
    Platform for building and running plain Java applications (fat-jar and flat classpath)

    Tags: builder, java

    * A source build using source code from https://github.com/fmarchioni/thorntail-examples will be created
      * The resulting image will be pushed to image stream tag "rest-demo:latest"
      * Use 'start-build' to trigger a new build
    * This image will be deployed in deployment config "rest-demo"
    * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "rest-demo"
      * Other containers can access this service through the hostname "rest-demo"

--> Creating resources ...
    imagestream.image.openshift.io "rest-demo" created
    buildconfig.build.openshift.io "rest-demo" created
    deploymentconfig.apps.openshift.io "rest-demo" created
    service "rest-demo" created
--> Success
    Build scheduled, use 'oc logs -f bc/rest-demo' to track its progress.
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
     'oc expose svc/rest-demo' 
    Run 'oc status' to view your app.

Great! now we only need to expose the Service through a Route so that we can test it:

$  oc expose svc/rest-demo

Check that the Pod has started:

Thorntail application on Openshift

Now we can test the application, as discussed in the README.md of the project:

curl http://rest-demo-microprofile-demo.192.168.42.103.nip.io/employees |jq
 
[
  {
    "id": 1,
    "name": "emp01"
  },
  {
    "id": 2,
    "name": "emp02"
  }
]

Basically this application showed how to create a REST Service in a MicroProfile applications. As you can see, running Microprofile applications with Openshift is pretty simple and you can combine its features with the standard Enterprise API that are available as Thorntail fractions.

0
0
0
s2smodern

Related articles available on mastertheboss.com

Openshift installation quick tutorial

IMPORTANT: This tutorial is now outdated. Openishift origin has b

Java EE example application on Openshift

In this tutorial we will learn how to deploy a Java EE applicatio

Running tomcat Docker image on Openshift

A common issue when porting Docker images on Openshift is that th

Deploy Docker images on Openshift

This tutorial will teach you how you can build and deploy a custo

Using Property files in your Openshift applications

A common need for most application is to store its configuration

Accessing Openshift services remotely

In this article we will learn how to connect to services running