Chapter 8. Running a SpringBoot business application on Red Hat OpenShift Container Platform
To run your Red Hat Decision Manager SpringBoot business application on Red Hat OpenShift Container Platform, create an immutable image and push this image to your Red Hat OpenShift Container Platform environment.
Prerequisites
- You have developed a Red Hat Decision Manager SpringBoot business application. For instructions about creating the application, see Chapter 2, Creating a business application.
- If necessary, you have configured Spring security for the application. For instructions about configuring Spring security, see Chapter 4, Spring Security with Red Hat Decision Manager.
- You have completed any necessary additional Spring configuration for the business application. For instructions about Spring configuration for your business application, see Chapter 5, Red Hat Decision Manager Spring Boot configuration.
- You created a single JAR file for the business application. For instructions about creating a single JAR file for your SpringBoot business application, see Chapter 6, Creating a self-contained Red Hat Decision Manager Spring Boot JAR file.
-
You are logged on to your Red Hat OpenShift Container Platform environment using the
oc
command and the required project is active.
Procedure
Outside the business application project directories, create an
ocp-image
directory with the following subdirectories:ocp-image |--/root |--/opt |-- /spring-service
Copy the single JAR file for your business application into the
root/opt/spring-service
subdirectory. For example:cd ../business-application-service cp target/business-application-service-1.0-SNAPSHOT.jar ../ocp-image/root/opt/spring-service/
In the
ocp-image
directory, create aDockerfile
file with the following content:FROM registry.access.redhat.com/ubi8/openjdk-11:latest COPY root / EXPOSE 8090 WORKDIR /opt/spring-service/ CMD ["sh","-c", "java ${JAVA_OPTIONS} -Dorg.kie.server.mode=PRODUCTION -jar /opt/spring-service/<FILENAME>.jar"]
Replace
<FILENAME>.jar
with the name of the single JAR file for your business application.To build the initial image and deploy it in your Red Hat OpenShift Container Platform environment, complete the following steps:
To build the image, run the following commands in the
ocp-image
directory:oc new-build --binary --strategy=docker --name openshift-kie-springboot oc start-build openshift-kie-springboot --from-dir=. --follow
Optional: replace
openshift-kie-springboot
with a custom application name in these commands and all subsequent commands.To deploy the image in the Red Hat OpenShift Container Platform environment, run the following command:
oc new-app openshift-kie-springboot
Optional: To expose the route for the image, run the following command:
oc expose service/openshift-kie-springboot --port=8090
If you already built and deployed the image and need to update it, for example if you built the JAR file for a new version of Red Hat Decision Manager or of Spring Boot, run the following command in the
ocp-image
directory:oc start-build openshift-kie-springboot --from-dir=. --follow