|
| 1 | +[id='openshift-springboot-proc_{context}'] |
| 2 | += Running a SpringBoot business application on {OPENSHIFT} |
| 3 | + |
| 4 | +To run your {PRODUCT} SpringBoot business application on {OPENSHIFT}, create an immutable image and push this image to your {OPENSHIFT} environment. |
| 5 | + |
| 6 | +ifdef::PAM[] |
| 7 | +Optionally, you can also use {CENTRAL} Monitoring to monitor the execution of business processes in your application. |
| 8 | +endif::PAM[] |
| 9 | + |
| 10 | +.Prerequisites |
| 11 | + |
| 12 | +* You have developed a {PRODUCT} SpringBoot business application. For instructions about creating the application, see xref:bus-app-create_{context}[]. |
| 13 | +* If necessary, you have configured Spring security for the application. For instructions about configuring Spring security, see xref:bus-app-security-con_{context}[]. |
| 14 | +* You have completed any necessary additional Spring configuration for the business application. For instructions about Spring configuration for your business application, see xref:bus-app-configure-con_{context}[]. |
| 15 | +* You created a single JAR file for the business application. For instructions about creating a single JAR file for your SpringBoot business application, see xref:creating-self-contained-image-proc_{context}[]. |
| 16 | +* You are logged on to your {OPENSHIFT} environment using the `oc` command and the required project is active. |
| 17 | +ifdef::PAM[] |
| 18 | +* If you want to use {CENTRAL} Monitoring, you have installed {CENTRAL} Monitoring using the operator. Use the same namespace to deploy {CENTRAL} Monitoring and your business application. |
| 19 | ++ |
| 20 | +[IMPORTANT] |
| 21 | +==== |
| 22 | +You must configure {CENTRAL} Monitoring to use the controller startup strategy. To enable the controller strategy on {CENTRAL} Monitoring, in the *Console* tab of the operator configuration, add a `KIE_SERVER_CONTROLLER_OPENSHIFT_ENABLED` environment variable and set it to `false`. |
| 23 | +==== |
| 24 | +endif::PAM[] |
| 25 | + |
| 26 | +.Procedure |
| 27 | + |
| 28 | +. Outside the business application project directories, create an `ocp-image` directory with the following subdirectories: |
| 29 | ++ |
| 30 | +---- |
| 31 | +ocp-image |
| 32 | +|--/root |
| 33 | + |--/opt |
| 34 | + |-- /spring-service |
| 35 | +---- |
| 36 | ++ |
| 37 | +. Copy the single JAR file for your business application into the `root/opt/spring-service` subdirectory. For example: |
| 38 | ++ |
| 39 | +---- |
| 40 | +cd ../business-application-service |
| 41 | +cp target/business-application-service-1.0-SNAPSHOT.jar ../ocp-image/root/opt/spring-service/ |
| 42 | +---- |
| 43 | ++ |
| 44 | +. In the `ocp-image` directory, create a `Dockerfile` file with the following content: |
| 45 | ++ |
| 46 | +---- |
| 47 | +FROM registry.access.redhat.com/ubi8/openjdk-11:latest |
| 48 | +COPY root / |
| 49 | +EXPOSE 8090 |
| 50 | +WORKDIR /opt/spring-service/ |
| 51 | +CMD ["sh","-c", "java ${JAVA_OPTIONS} -Dorg.kie.server.mode=PRODUCTION -jar /opt/spring-service/<FILENAME>.jar"] |
| 52 | +---- |
| 53 | ++ |
| 54 | +Replace `<FILENAME>.jar` with the name of the single JAR file for your business application. |
| 55 | ++ |
| 56 | +ifdef::PAM[] |
| 57 | +Alternatively, if you want to configure communication with {CENTRAL} Monitoring, use the following content for `Dockerfile`: |
| 58 | ++ |
| 59 | +---- |
| 60 | +FROM registry.access.redhat.com/ubi8/openjdk-11:latest |
| 61 | +COPY root / |
| 62 | +EXPOSE 8090 |
| 63 | +WORKDIR /opt/spring-service/ |
| 64 | +CMD ["sh","-c", "java ${JAVA_OPTIONS} -Dorg.kie.server.location=${KIESERVER_LOCATION} -Dorg.kie.server.controller=${KIESERVER_CONTROLLERS} -Dorg.kie.server.controller.user=${KIE_SERVER_CONTROLLER_USER} -Dorg.kie.server.controller.pwd=${KIE_SERVER_CONTROLLER_PWD} -Dorg.kie.server.mode=PRODUCTION -jar /opt/spring-service/<FILENAME>.jar"] |
| 65 | +---- |
| 66 | ++ |
| 67 | +Replace `<FILENAME>.jar` with the name of the single JAR file for your business application. |
| 68 | ++ |
| 69 | +endif::PAM[] |
| 70 | +. To build the initial image and deploy it in your {OPENSHIFT} environment, complete the following steps: |
| 71 | +.. To build the image, run the following commands in the `ocp-image` directory: |
| 72 | ++ |
| 73 | +---- |
| 74 | +oc new-build --binary --strategy=docker --name openshift-kie-springboot |
| 75 | +oc start-build openshift-kie-springboot --from-dir=. --follow |
| 76 | +---- |
| 77 | ++ |
| 78 | +Optional: replace `openshift-kie-springboot` with a custom application name in these commands and all subsequent commands. |
| 79 | ++ |
| 80 | +.. To deploy the image in the {OPENSHIFT} environment, run the following command: |
| 81 | ++ |
| 82 | +---- |
| 83 | +oc new-app openshift-kie-springboot |
| 84 | +---- |
| 85 | ++ |
| 86 | +ifdef::PAM[] |
| 87 | +Alternatively, to deploy the image and configure it to communicate with {CENTRAL} Monitoring, run the following command: |
| 88 | ++ |
| 89 | +---- |
| 90 | +oc new-app openshift-kie-springboot -e KIESERVER_LOCATION=http://<LOCATION>:<PORT>/rest/server -e KIESERVER_CONTROLLERS=ws://<BC-HOSTNAME>:<BC-PORT>/websocket/controller -e KIE_SERVER_CONTROLLER_USER=USER -e KIE_SERVER_CONTROLLER_PWD=PASSWORD |
| 91 | +---- |
| 92 | ++ |
| 93 | +In this command, replace the following values: |
| 94 | ++ |
| 95 | +** `<LOCATION>` with the fully qualified host name for accessing your service. {CENTRAL} Monitoring accesses the service to retrieve process information and displays a URL for the service with this host name |
| 96 | +** `<PORT>` with the port for accessing your service, for example, `8090` |
| 97 | +** `<BC-HOSTNAME>` with the host name for accessing the {CENTRAL} Monitoring instance. If your application is deployed in the same project/namespace as the {CENTRAL} Monitoring instance, use the service name for {CENTRAL} Monitoring, for example, `myapp-rhpamcentrmon`. Otherwise, you can use use the fully qualified host name of a route for the {CENTRAL} Monitoring instance. |
| 98 | +** `<BC-PORT>` with the port of the {CENTRAL} Monitoring instance, for example, `8080` |
| 99 | +** `<USER>` with the username of a user configured on the {CENTRAL} Monitoring instance |
| 100 | +** `<PASSWORD>` with the password of the user configured on the {CENTRAL} Monitoring instance |
| 101 | ++ |
| 102 | +[NOTE] |
| 103 | +==== |
| 104 | +This configuration uses unsecured HTTP communication for your service. If you configure your Spring Boot business application with a valid SSL certificate, you can replace `http:` with `https:` to use secure HTTPS communication. For more information about configuring SSL on Spring Boot, see https://docs.spring.io/spring-boot/docs/{SPRING_BOOT_VERSION}.RELEASE/reference/html/howto.html#howto-configure-ssl[Spring Boot documentation]. |
| 105 | +==== |
| 106 | ++ |
| 107 | +[NOTE] |
| 108 | +==== |
| 109 | +If you want to view process information from {CENTRAL} Monitoring, you must ensure that the user that is logged into {CENTRAL} Monitoring can also be authenticated with your service using the same password. |
| 110 | +==== |
| 111 | ++ |
| 112 | +endif::PAM[] |
| 113 | +.. Optional: To expose the route for the image, run the following command: |
| 114 | ++ |
| 115 | +---- |
| 116 | +oc expose service/openshift-kie-springboot --port=8090 |
| 117 | +---- |
| 118 | ++ |
| 119 | +. If you already built and deployed the image and need to update it, run the following command in the `ocp-image` directory: |
| 120 | ++ |
| 121 | +---- |
| 122 | +oc start-build openshift-kie-springboot --from-dir=. --follow |
| 123 | +---- |
0 commit comments