June 4, 2019 By Arthur De Magalhaes 4 min read

Deploy Spring Boot with confidence by using the enterprise-level artifacts found in our Certified Open Liberty Spring Cloud Pak

It’s a well-known fact that Open Liberty supports Spring and provides customers with a single platform to run all of their enterprise Java applications, including Java EE, MicroProfile, and Spring Boot.

We went a step further and created a Certified Open Liberty Spring Cloud Pak, which ensures that you get the same reliable, portable, and secure experience with your Spring applications that are running on supported Kubernetes platforms.

Curated Open Liberty images optimized to run your Spring Boot apps

Our Docker images are publicly available from our Docker Hub page. Use the springBoot1 or springBoot2 tags, depending on the version of Spring Boot that your application relies on.

Deploying Spring Boot Application as-is

Let’s say you have built a fat jar with the popular Spring Pet Clinic application. How do you deploy that with Open Liberty?

The most straightforward way is to just copy that application into the image. It’s as simple as a two-line Dockerfile:

FROM openliberty/open-liberty:springBoot2-ubi-min
COPY --chown=1001:0 spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar /config/dropins/spring/

You can build and run this image, which is using Red Hat’s minimum Universal Base Image as the operating system, with the following commands:

docker build -t springimage .
docker run -d --name springcontainer -p 8080:9080 springimage

After the CWWKF0011I message is displayed in the logs, you can enter localhost:8080 in your browser to see your fully functional application, like the one in the following example:

Optimized deployment with the springBootUtility

In the “Using Spring Boot Images” section of our Docker Hub page, you’ll learn how to achieve an optimized application image that uses Open Liberty’s springBootUtility. In this image, the layer containing Spring libraries is pushed between the Open Liberty layer and your application’s layer, allowing for much faster continuous development and build flow since the layer that changes most frequently (the app code) is at the top.

This is different than the approach we took in the previous section, where the application code was packaged together with all the Spring Boot libraries—including an embedded server.

In addition to the improved build time, by using the springBootUtility tool, you will build a smaller image that spawns containers with a faster startup. It’s a triple-win situation!

To showcase this approach, we re-built the Pet Clinic image with this modified Dockerfile:

1.   ARG IMAGE=openliberty/open-liberty:springBoot2-ubi-min
2.   FROM ${IMAGE} as staging
3.   COPY --chown=1001:0 spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar /staging/myFatApp.jar
4.   RUN springBootUtility thin \
5.    --sourceAppPath=/staging/myFatApp.jar \
6.    --targetThinAppPath=/staging/myThinApp.jar \
7.    --targetLibCachePath=/staging/lib.index.cache
8.
9.   FROM ${IMAGE}
10.  COPY --from=staging /staging/lib.index.cache /lib.index.cache
11.  COPY --from=staging /staging/myThinApp.jar /config/dropins/spring/myThinApp.jar

Lines 1-2 specify which image we want to start with. In our case, we picked the Open Liberty tag that uses Red Hat’s minimum Universal Base Image, but you could also use other tags, such as openliberty/open-liberty:springBoot2-java11-openj9 (to run with Java 11 + OpenJ9), by simply specifying that as an ARG during the docker build invocation.

Line 3 copies the previously built Spring Boot fat jar into the image. 

Lines 4-7 use the Open Liberty springBootUtility to separate the composed fat jar into smaller pieces; namely, the thin application jar and the library cache.

Line 9 starts a new Docker image (second stage of our multi-stage Dockerfile).

Lines 10-11 simply copy the artifacts from the first stage, creating an optimized image that has the application artifacts as the top layer. This allows for iterative development of the application without having to rebuild all the layers below.

We have pushed this optimized image our Docker Hub Samples registry, so if you just want to run the image you can do so:

docker run -d --name springApp -p 8080:9080 openliberty/samples:springPetClinic

Enterprise deployments that are ready to go

Once your application is tightly layered with Open Liberty, you’ll want to deploy it into a Kubernetes environment. We have created a new Helm chart, available in our public repository, which helps you deploy your new Spring Boot application with enterprise settings such as Ingress, Auto-scaling and Pod Security Policy.

Just like the other Application Cloud Paks, the Open Liberty Spring Helm chart contains a complete set of hooks to configure all aspects of the deployments (including annotations, labels, init containers, etc) via a single overrides.yaml.

Here’s an example of an overrides file which installs the sample Pet Clinic application with Ingress enabled and three replica pods:

image:
  repository: openliberty/samples
  tag: springPetClinic

replicaCount: 3

ingress:
  enabled: true
  rewriteTarget: "/"
  path: "/petclinic"

You can then install this fully configured deployment with the following commands:

helm repo add ibm-charts https://raw.githubusercontent.com/IBM/charts/master/repo/stable/
helm install -f overrides.yaml ibm-charts/ibm-open-liberty-spring --tls

Within seconds, your deployment is up and running in Kubernetes. The following screenshot illustrates the successful deployment on IBM Cloud Private.

By using the kubectl command you can drill down into new Kubernetes resources that were created: Ingress, Service, Deployment, Role, Service Account, etc.

Reach out to our open source community to let us know your thoughts, or connect directly with Arthur.

Was this article helpful?
YesNo

More from Cloud

A clear path to value: Overcome challenges on your FinOps journey 

3 min read - In recent years, cloud adoption services have accelerated, with companies increasingly moving from traditional on-premises hosting to public cloud solutions. However, the rise of hybrid and multi-cloud patterns has led to challenges in optimizing value and controlling cloud expenditure, resulting in a shift from capital to operational expenses.   According to a Gartner report, cloud operational expenses are expected to surpass traditional IT spending, reflecting the ongoing transformation in expenditure patterns by 2025. FinOps is an evolving cloud financial management discipline…

IBM Power8 end of service: What are my options?

3 min read - IBM Power8® generation of IBM Power Systems was introduced ten years ago and it is now time to retire that generation. The end-of-service (EoS) support for the entire IBM Power8 server line is scheduled for this year, commencing in March 2024 and concluding in October 2024. EoS dates vary by model: 31 March 2024: maintenance expires for Power Systems S812LC, S822, S822L, 822LC, 824 and 824L. 31 May 2024: maintenance expires for Power Systems S812L, S814 and 822LC. 31 October…

24 IBM offerings winning TrustRadius 2024 Top Rated Awards

2 min read - TrustRadius is a buyer intelligence platform for business technology. Comprehensive product information, in-depth customer insights and peer conversations enable buyers to make confident decisions. “Earning a Top Rated Award means the vendor has excellent customer satisfaction and proven credibility. It’s based entirely on reviews and customer sentiment,” said Becky Susko, TrustRadius, Marketing Program Manager of Awards. Top Rated Awards have to be earned: Gain 10+ new reviews in the past 12 months Earn a trScore of 7.5 or higher from…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters