spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.76k stars 40.59k forks source link

Provide a single command for generating a CDS archive from an uber jar #41241

Open joshlong opened 3 months ago

joshlong commented 3 months ago

Ideally there'd be one command ('appcds'?) that I can run on an Uber jar that extracts everything, runs the app to a .jsa file, and then prints out the command required to run the program from the .jsa file

wilkinsona commented 3 months ago

For reference, it's currently three commands to create the archive:

$ java -Djarmode=tools -jar my-app.jar extract --destination application
$ cd application
$ java -XX:ArchiveClassesAtExit=application.jsa -Dspring.context.exit=onRefresh -jar my-app.jar

The command to run the application is then:

$ java -XX:SharedArchiveFile=application.jsa -jar my-app.jar
philwebb commented 3 months ago

We're interested in doing something here, but we really want to see how much CDS is adopted and how the landscape might change with project leyden. We also anticipate that the training run of the app might evolve over time. For example we have issue #4779, we also have ideas around Flyway/Liquibase migrations and if they should run during the training run.

sdeleuze commented 3 months ago

+1 for waiting for feedback and adoption.

I understand this kind of feature can be tempting, but I have mixed feelings about it. I mean, currently Spring Boot provides already a single command to do that with containers (gradle bootBuildImage or Maven equivalent with the related BP flag enabled) and on the other side of the spectrum it provides java -Djarmode=tools -jar my-app.jar extract command + related documentation to allow people to leverage the efficient layout for custom use cases (local testing, Dockerfiles, etc.). Providing something in between could be confusing, especially with the need to customize the training run configuration for most use cases involving databases.

Maybe the most attractive use case I see is for easy local testing or demos on Mac M1/M2/M3, but this is going to be fixed shortly by the multi-architecture support in Buildpacks (already possible to use it with custom configuration, see https://github.com/sdeleuze/spring-boot-cds-demo for Maven and Gradle example), so I think my current preferred option would be to not provide this kind of capability unless we see strong use case that we are not covering, and improve the existing CDS Buildpacks support to make it even more easy to use.

wilkinsona commented 2 months ago

https://github.com/spring-projects/spring-boot/issues/41348 is a good example of the complexity that database migrations introduce, particularly when combined with AOT.