Skip to content

Open Liberty Devfile Stack Customization

Edward Mezarina edited this page Dec 10, 2021 · 4 revisions

This sample shows how to customize the default Devfile Liberty Stack to meet your artifact version requirements.

The examples provided here show how to customize the stack for Open Liberty Gradle and Maven deployments.

Procedure

Building a Custom Open Liberty Devfile Stack Base Image

  1. Clone the Open Liberty devfile stack repository and go into the devfile-stack directory.
git clone https://github.com/OpenLiberty/devfile-stack.git
cd devfile-stack
  1. Create a git branch to persist your customization.

There are different ways to persist your customization. Here, we explore the option of persisting the customized Liberty devfile stack in a branch off of your cloned devfile Liberty stack main branch.

git checkout -b custom-stack-ol210012-java11
  1. Customize the Liberty devfile stack base image.

The stack provides two customization files for the following supported runtimes:

  • Open Liberty: customize-ol.env
  • WebSphere Liberty: customize-wl.env

Modify either or both files and save them.

Example

For this Open Liberty example customization, the outer-loop Dockerfile locations are predefined to point to the customized files in the branch used for this customization.

Update the customize-ol file:

BASE_OS_IMAGE="ibmsemeruruntime/open-11-jdk:ubi-jdk"
LIBERTY_RUNTIME_VERSION="21.0.0.12"
STACK_IMAGE_MAVEN="<registry>/<maven-image-name>"
STACK_IMAGE_GRADLE="<registry>/<gradle-image-name>"
OUTERLOOP_LIBERTY_IMAGE="openliberty/open-liberty:21.0.0.12-full-java8-openj9-ubi"
OUTERLOOP_DOCKERFILE_MAVEN_LOC="https://<your-git-repo-path>/devfile-stack/tree/custom-stack-ol210012-java11/stack/open-liberty/outer-loop/maven/Dockerfile"
OUTERLOOP_DOCKERFILE_GRADLE_LOC="https://<your-git-repo-path>/devfile-stack/tree/custom-stack-ol210012-java11/stack/open-liberty/outer-loop/gradle/Dockerfile"

Once the customization files are updated with the needed values, run the build command to customize the stack artifacts.

  • To customize the stack for all of the supported Liberty deployments, issue the following command:
./build.sh

or

./build.sh all
  • To customize the stack for Open Liberty deployments issue this command:
./build.sh ol
  • To customize the stack for WebSphere Liberty deployments issue this command:
./build.sh wl

The customized artifacts are located in the stack directory.

Example

For this Open Liberty example customization, run this command:

build.sh ol
  1. Build the customized Liberty devfile stack images for Maven and Gradle deployments.

Open Liberty

docker build -t <the value of STACK_IMAGE_MAVEN in your customization file> -f stack/open-liberty/image/maven/Dockerfile tools/image
docker build -t <the value of STACK_IMAGE_GRADLE in your customization file> -f stack/open-liberty/image/gradle/Dockerfile tools/image

WebSphere Liberty

docker build -t <the value of STACK_IMAGE_MAVEN in your customization file> -f stack/websphere-liberty/image/maven/Dockerfile tools/image
docker build -t <the value of STACK_IMAGE_GRADLE in your customization file> -f stack/websphere-liberty/image/gradle/Dockerfile tools/image

Example

For this Open Liberty example customization, run these commands:

docker build -t <registry>/<maven-image-name> -f stack/open-liberty/image/maven/Dockerfile tools/image
docker build -t <registry>/<gradle-image-name> -f stack/open-liberty/image/gradle/Dockerfile tools/image
  1. Push your custom Liberty devfile stack images to an accessible repository.

Example

For this Open Liberty example customization, run these commands:

docker push <registry>/<maven-image-name>
docker push <registry>/<gradle-image-name>
  1. Persist your customized Liberty devfile stack.
  • Add, commit, and push the updates to the branch created for this customization.

Example

For this Open Liberty example customization, run these commands:

git add <files>
git commit -m 'Customized OL Stack using Java 11 with OpenJ9 and OpenLiberty 21.0.0.12'
git push

That is all. You now have customized stack, built a set of stack images that will speed up your deployments, and stored the customized artifacts in a git branch. Let's test the customization next.

Running an Application Using the Customized Stack

The following steps show how to deploy your application using a customized Liberty devfile stack.

  1. Login to your Kubernetes cluster.
oc login https://<your_cluster_hostname> -u <username> -p <password>
  1. Deploy your application for inner loop development.

If your application supports both Maven and Gradle, you can validate both by executing the steps below twice. Follow either the Maven or Gradle instructions below for each iteration.

For this example, we will use the Open Liberty devfile stack intro located here. It supports both Maven and Gradle.

  • Access the application.

Example

For this Open Liberty example customization, run these commands:

git clone https://github.com/OpenLiberty/devfile-stack-intro.git
cd devfile-stack-intro
  • Create an odo component for the application.

Example

For this Open Liberty example customization, run these commands:

Maven:

odo create mavenCustomizationSample --devfile https://<your-git-repo-path>/devfile-stack/tree/custom-stack-ol210012-java11/stack/open-liberty/devfiles/maven/devfile.yaml
odo push 

Gradle:

odo create gradleCustomizationSample --devfile https://<your-git-repo-path>/devfile-stack/tree/custom-stack-ol210012-java11/stack/open-liberty/devfiles/gradle/devfile.yaml
odo push 
  1. Validate that the applications was deployed successfully.

Example

For this Open Liberty example customization, run this command:

odo url list

Output:

Found the following URLs for component ...
NAME     STATE      URL                                                                      PORT     SECURE     KIND
ep1      Pushed     http://ep1-component-name-test.apps.xxxxxxx.yy.zzz.aaa.com               9080     false      route

Open a browser using the shown URL: http://ep1-component-name-test.apps.xxxxxxx.yy.zzz.aaa.com.

You should see a welcome page with the heading:

Welcome to your Open Liberty Microservice built with Odo