Java
Introduction
We have clients using the SpringBoot framework for apps on OpenShift. We also suggest looking at the Quarkus framework as it has a container first priority.
Getting Started
-
First create a new GitLab project using the instance template from the AppBase for your language.
- The AppBase will provide you with a pattern to deploy applications
- Will automatically setup GitLab CI/CD tools such as security settings
- The quickest way to get up and running with OpenShift.
- Read the README.md file in the repository for latest instructions and notes for your framework.
-
Change into the cloned folder and generate a new Spring Boot application
-
We recommend using the Spring Boot CLI or the Spring Start.
A basic starting point (recommended):
spring init -x --build=maven --force -d=web,actuator -n=projectxA detailed example specifying more packages, spring version and java version would be:
spring init -x --build=maven --force -b=2.7.8-SNAPSHOT -j=1.11 -d=web,actuator,security,cloud-eureka,amqp,lombok,flyway,mysql,jdbc,jpa,cloud-loadbalancer,thymeleaf -n=projectx -
Modify the Dockerfile in the repository as needed:
- The source folder (see line 9, line 31)
- The JDK version (see line 2, line 15)
-
Git add all the changes, commit and push to your repository.
git add .
git commit -m "first change"
git push -
Setup the GitLab CI/CD variables as defined in the README.md in the repository.
TODO
- OpenShift deployment
- Gitops
Notes
JAVA_OPTS
Running in a container can cause issues with the heap size and CPU detection if limits are used. We recommend the following environment variable to be set:
JAVA_OPTS: '-XX:ActiveProcessorCount=2 -XX:+UseParallelGC -XX:MaxRAMPercentage=80'
For more information please read Microsoft's JAVA Containerization recommendations and RedHat's OpenJDK changes.
Actuators
Actuators provide a way to check the health of the application. They should be used for production and zero downtime deployments.