Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Source to Image Builder for Open Liberty Apps on OpenShift

DZone 's Guide to

Source to Image Builder for Open Liberty Apps on OpenShift

Check out this open source project that lets you deploy local Open Liberty apps, perfect for OKD use.

· Open Source Zone ·
Free Resource

OKD, the open source upstream Kubernetes distribution embedded in OpenShift, provides several ways to make deployments of applications to Kubernetes for developers easy. I've open sourced a project that demonstrates how to deploy local Open Liberty applications via two simple commands 'oc new-app' and 'oc start-build'.

$ oc new-app s2i-open-liberty:latest~/. --name=<service-name>
$ oc start-build --from-dir . <service-name>


Get the code from GitHub.

Source-to-Image

OKD allows developers to deploy applications without having to understand Docker and Kubernetes in depth. Similarily to the Cloud Foundry cf push experience, developers can deploy applications easily via terminal commands and without having to build Docker images. In order to do this Source-to-Image is used.

Source-to-Image (S2I) is a toolkit for building reproducible container images from source code. S2I produces ready-to-run images by injecting source code into a container image.

In order to use S2I, builder images are needed. These builder images create the actual images with the applications. The builder images are similar to Cloud Foundry buildpacks.

OKD provides several builder images out of the box. In order to support other runtimes, for example Open Liberty, custom builder images can be built and deployed.

Sample Application Running Locally in Docker Desktop

The repo contains a S2I builder image which creates an image running Java web applications on Open Liberty. Additionally the repo comes with a simple sample application which has been implemented with Java/ Jakarta EE and Eclipse MicroProfile.

The Open Liberty builder image can be used in two different environments:

  • OpenShift or MiniShift via 'oc new-app' and 'oc start-build'
  • Local Docker runtime via 's2i'

This is how to run the sample application locally with Docker and S2I:

$ cd ${ROOT_FOLDER}/sample
$ mvn package
$ s2i build . nheidloff/s2i-open-liberty authors
$ docker run -it --rm -p 9080:9080 authors
$ open http://localhost:9080/openapi/ui/


To use "s2i" or "oc new-app/oc start-build" you need to build the application with Maven. The server configuration file and the war file need to be in these directories:

  • server.xml in the root directory
  • *.war file in the target directory

Sample Application Running on Minishift

First, the builder image needs to be built and deployed:

$ cd ${ROOT_FOLDER}
$ eval $(minishift docker-env)
$ oc login -u developer -p developer
$ oc new-project cloud-native-starter
$ docker login -u developer -p $(oc whoami -t) $(minishift openshift registry)
$ docker build -t nheidloff/s2i-open-liberty .
$ docker tag nheidloff/s2i-open-liberty:latest $(minishift openshift registry)/cloud-native-starter/s2i-open-liberty:latest
$ docker push $(minishift openshift registry)/cloud-native-starter/s2i-open-liberty


After the builder image has been deployed, Open Liberty applications can be deployed:

$ cd ${ROOT_FOLDER}/sample
$ mvn package
$ oc new-app s2i-open-liberty:latest~/. --name=authors
$ oc start-build --from-dir . authors 
$ oc expose svc/authors
$ open http://authors-cloud-native-starter.$(minishift ip).nip.io/openapi/ui/
$ curl -X GET "http://authors-cloud-native-starter.$(minishift ip).nip.io/api/v1/getauthor?name=Niklas%20Heidloff" -H "accept: application/json"


After the sample application has been deployed, it shows up in the console.

Topics:
open source ,open liberty ,openshift ,kubernetes ,okd

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}