Exercise 6: Deploy a Java application with Build Config (CLI version)

In this exercise we'll revisit the application from exercise 1, except we'll use equivalent CLI commands to deploy our "Authors" application.

From the IBM Cloud console launch the IBM Cloud Shell. Refer to our Getting Starting material to learn how to access the IBM Cloud Shell.

Deploy Authors application (CLI version)

First, clone the Authors source code and change to that directory.

git clone https://github.com/IBM/openshift-on-ibm-cloud-workshops
cd openshift-on-ibm-cloud-workshops
cd deploying-to-openshift

Take note of the new Dockerfile in the application's directory. We've pre-written it for you. But we've copied it here too, go through each line and read the corresponding comment.

# Use an official JDK image
FROM maven:3.5-jdk-8 as BUILD

# Copy the application source code
COPY src /usr/src/app/src
COPY pom.xml /usr/src/app

# Run maven to build the application
RUN mvn -f /usr/src/app/pom.xml clean package

FROM open-liberty:microProfile2-java11

COPY liberty/server.xml /config/

COPY --from=BUILD /usr/src/app/target/authors.war /config/apps/

# Allow traffic on port 3000
EXPOSE 3000

From the OpenShift console click the user name in the top right corner and select Copy Login Command.

Copy Login Command

The login command will be copied to the clipboard, in the IBM Cloud Shell, paste that command. For example:

Create a new OpenShift project to deploy our application, call it cloud-native-starter.

Build your application's image by running the oc new-build command from your source code root directory. This will create a Build and an ImageStream of the app.

The output should look like below:

Start a new build using the oc start-build command.

The output should look like below:

View the build logs by running the oc logs command.

Finally, deploy the application by running oc new-app.

The output should look like below:

View the deployment logs by running the oc logs command.

The output should look like:

Expose the service using oc expose, a route will be created.

Find the application's route by running oc get routes.

The output should look like below:

Copy the URL into a browser and append /openapi/ui.

Swagger in a browser

Also verify this works with curl by running

The output should look like the following:

Congratulations on completing this exercise!

Last updated

Was this helpful?