heidloff.net - Building is my Passion
Post
Cancel

Source to Image Builder for Open Liberty Apps on OpenShift

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’.

1
2
$ 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:

1
2
3
4
5
$ 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:

1
2
3
4
5
6
7
8
$ 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:

1
2
3
4
5
6
7
$ 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.

image

Featured Blog Posts
Disclaimer
The postings on this site are my own and don’t necessarily represent IBM’s positions, strategies or opinions.
Trending Tags