This article promises on bringing a SpringBoot binary file to life and make from it a fully running application on OpenShift.
Our today’s Use-Case: Deploy to Openshift a resultant artifact of an already built packaged springboot application. This is useful for software built on a platform different from the one where the application is going to run.
Prerequisites for our Experiments
First, we need a running OpenShift cluster on which we can do our experiments. I invite you then to run the next steps using either a free account on OpenShift.io or download & run an OpenShift cluster locally using minishift.
Do not forget to download/install the OpenShift-Client tool.
OpenShift provides natively with different options for building and deploying containers, which includes building/deploying applications either from source code or from binaries.
Platforms like Java allows developers to package all the dependencies, resources and configuration files in a single archive file, or which we call JAR binary files.
Our project is based on an OpenSource SpringBoot project.
The JAR file can be downloaded from here “HelloWorld-2.0.jar”, renamed as “springboot.jar” and placed in a deployments folder.
For our use-case, we need a builder image that contains tools like Maven to build our artifacts provided as a jar file.
In OpenShift, an OpenJDK Image stream is already provided in the “openshift” namespace.
Let’s check what images are available for us:
oc get is -n openshift | grep -i openjdk
Create a new Project
Let’s start by creating an OpenShift project.
oc new-project springproject --display-name "Spring Project"
Create a new Build
We’re going to use a builder image, so we’ll use the “redhat-openjdk18-openshift”. The following creates a build, and accept a binary content as a source.
Here we are naming the application as myspringboot.
oc new-build --name=myspringboot --strategy=source --binary \
Executing the Build
Once the BuildConfig is created in OpenShift, we can then take care of the creation of a final docker container image. This image is based on OpenJDK as a Base-Image and our artifact file, which is mainly a binary JDK file.
oc start-build myspringboot --from-file=myspringboot.jar --follow
The command starts by uploading/copying the binary file into the appropriate location within the destination container.
The “ — follow” flag is helpful as it provides you with the ability to watch the build logs.
You can check the builds history by launching this command:
oc get builds
Create the Application
Now we already have the image built, including the application artifcats. One easy step is remaining to make the application deployed and up & running.
Let’s launch the creation of our spring boot application:
oc new-app myspringboot
As a result, this command dynamically generates a DeploymentConfig, make the application run as pods and expose it using a Service. However, there is no route for this application yet. So you cannot access this application from outside.
Expose your application
Let’s create an OpenShift route to make the “myspringboot” service exposed to the internet.
oc expose svc/myspringboot
We can check the exposed routes:
oc get route myspringboot
Let’s curl our application:
curl $(oc get route myspringboot \
We’ve succeeded in building, and deploying a basic JAR file. Now there’s an opportunity to improve these experiments and I have some suggestions for you:
- Set up a Github webhooks to react to source code changes,
- Make the exposed route secure,
- Make it repeatable and configurable: abstract all the complexities in one template and then instantiate the template by providing the location of the artifacts.
This how you can export / create a template file from an existing OpenShift resources:
oc get bc myspringboot -o yaml > myspringboot-bc.yaml
Please do not hesitate to tweet me with your valuables comments/questions.