GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.5k stars 1.42k forks source link

Add additional jvmflag support #4270

Open wleese opened 1 month ago

wleese commented 1 month ago

It would be good for Jib to provide a way to easily take an image previously created by Jib, and to 'append' to it in various ways.

That would benefit the CDS workflow of starting an application via a container, capturing some data and then putting it into a new image (optionally overwriting the old one) and adding some jvm flags.

Note that while there are sufficient workarounds at this point in time, I'm looking for improvements to Jib to make it more elegant.

I currently use the following workflow in a GitLab CICD pipeline to get CDS to work (this being what Spring Framework recommends: https://docs.spring.io/spring-framework/reference/integration/cds.html).

  1. In a job, build the Jib image with containerizingMode=packaged
  2. In the next job, run that image with -XX:ArchiveClassesAtExit=application.jsa -Dspring.context.exit=onRefresh
  3. In the final job, pick up that application.jsa file, add it to the existing image and change the entrypoint to include -XX:SharedArchiveFile=/application.jsa

It works quite well, except step 3. Here I have to run the following

      mkdir cds_output; cp application.jsa cds_output/ 
      ./mvnw -Drevision="${VERSION}" \
        -Djib.to.image="${DOCKER_IMAGE}:${VERSION}" \
        -Djib.from.image="${DOCKER_IMAGE}:${VERSION}" \
        -Djib.containerizingMode=packaged \
        -Djib.extraDirectories.paths=./cds_output \
        -Djib.container.jvmFlags=-XX:SharedArchiveFile=/application.jsa \ 
        jib:build

Now the jvmFlags overwrites whatever the user has already set in their pom.xml.

It would be of great help if there was an option to append to the jvmFlags, so that both options in pom.xml and via the commandline could work together.

This issue is related to the CDS support request https://github.com/GoogleContainerTools/jib/issues/2471