Search code examples
spring-bootopenshiftuberjar

How is Openshift starting a fat-jar


I deploy an image with a Spring-boot fat-jar on Openshift. I base my image on redhat-openjdk18-openshift:1.2.

My application starts fine and i see in the terminal the following

Starting the Java application using /opt/run-java/run-java.sh ...

exec java -javaagent:/opt/jolokia/jolokia.jar=config=/opt/jolokia/etc/jolokia.properties
-XX:+UseParallelGC -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40
-XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=100m 
-XX:+ExitOnOutOfMemoryError -cp . -jar /deployments/MYAPPLICATION.jar

My questions is:

  1. Where is this glue coming from (the exec java ...)? And how does Openshift know this jar file is executable?
  2. I would like to add some command line arguments. I found the following way that works: enter image description here

But then i loose the Jolokia stuff above. Is there a beter way?

Update: I use the following Strategy:

strategy:
..sourceStrategy:
....from:
......kind: ImageStreamTag
......name: 'redhat-openjdk18-openshift:1.2'
......namespace: openshift

Then like: oc start-build $SERVICE_NAME --from-file=my-app.jar

Also, the documentation you linked is exactly what I did follow. Seen in step (2) above. And then i loose the Jolokia stuff. I guess I look for a way jo just extend the existing Entrypoint, instead of overloading it.


Solution

  • The command exec java -javaagent:/opt/jolokia/jolokia.jar=config=/opt/jolokia/etc/jolokia.properties is the container's entrypoint, which is the command and parameters that execute when a container is run. The entrypoint is set when the image is built.

    You didn't say what strategy you're using to build the image, but if you want more control over the entrypoint and other container parameters, then you can use a Docker strategy. You'll have full control over the image using this method, so you can set things like environment variables, parameters, and arguments.

    If you don't want to bother with a build configuration, then you can just build the image outside of Openshift using a Dockerfile, and then deploy the image directly to openshift. Here's Dockerfile tutorial.

    Edit:

    Also, I think you can still use the method you're currently trying, but you'll need to add the Jolokia args to the spec manually, but I think the best way would still be to configure everything in a build configuration where you can control the entrypoint and parameters for the entire image instead of overriding the existing entrypoint. Here's the documentation for running commands inside of a container.

    Edit:

    Based on the update you provided, I think switching to a docker strategy is still your best option. The source strategy is just automatically building the image for you, but like I mentioned above the dockerfile strategy will let you control the whole build process. Here's an example of an inline dockerfile:

      apiVersion: v1
      kind: BuildConfig
      metadata:
        annotations:
          description: Defines how to build the application
        labels:
          application: MYAPPLICATION
        name: MYAPPLICATION
        namespace: PROJECT_NAME
      spec:
        output:
          to:
            kind: ImageStreamTag
            name: MYAPPLICATION:latest
        source:
          binary: {}
          dockerfile: |-
            FROM redhat-openjdk18-openshift:1.2
            COPY deployments/* /
            ENTRYPOINT  java -jar MYAPPLICATION.jar
          type: Binary
        strategy:
          dockerStrategy:
            from:
              kind: ImageStreamTag
              name: redhat-openjdk18-openshift:1.2
          type: Docker
    

    This way you'll be able to extend the entrypoint by copying the existing command and adding on anything else you want. You may have to create the openjdk image stream in your project, if it isn't there already.