Getting started with Spring Boot on OpenShift

In the previous post, I described how to run MongoDB on an OpenShift gear. In this, I expand the topic and explain about deploying a Spring Boot application to OpenShift. Basically, Spring Boot is an abstracted version of Spring with the purpose of fast development of production-ready apps. Spring Boot has minimal configuration and quickly deployable, very suitable for microservices.
Unfortunately, OpenShift by default does not support Spring and Spring Boot applications, not a big deal at all, hence you need to configure the instance to be able to run a Spring Boot app, steps are described in following.
The first thing is to create a DIY (Do It Yourself) instance either from OpenShift Console or using rhc command. If you decided to go with the latter, you can utilize the command in below:

$ rhc create-app [Application Name] diy-0.1

Keep in mind that DIY gears are not autoscale.
The next step is to clone the gear.

$ git clone ssh://[repository URL]

Now need to create a remote branch for the gear called openshift.

$ git remote add openshift -f ssh://[repository URL]

And then merge the branch to master.

$ git merge openshift/master -s recursive -X ours

The reason of creating openshift branch is that whenever code is pushed to the repository, Openshift automatically runs build and start scripts respectively.
Hence, need to have three bash scripts for build, start, and stop.
The scripts should be placed under ProjectDirectory/.openshift/action_hooks.
I have added the content of each file, just need to copy/paste and replace with the original ones if exist.

The final step is to add settings.xml which sets the location where JDK 8 and Maven are stored. This file is very crucial and if you forget to add it, like what I did couple of times, your project will not build and deploy.
The file should be placed under ProjectDirectory/.openshift/

Now you should be able to deploy your Spring Boot application to an OpenShift gear.
Further reading:

Leave a Reply