2

Spring Boot 2.3 introduced support for building optimized Docker images using the Spring Boot maven/gradle plugin. The spring-boot:build-image goal does a bunch of things:

  • Create the layers index
  • Invoke the Paketo buildpack
  • Build the OCI image
  • etc.

Is there a way to replicate these steps for modules using an older Spring Boot version? Even better, can these steps be integrated directly into a maven/gradle build?

metacubed
  • 7,031
  • 6
  • 36
  • 65
  • You can use `pack build`, https://github.com/buildpacks/pack, with the Java meta CNB, https://github.com/paketo-buildpacks/java, to generate optimized images for Java apps. The Spring Boot 2.3 integration is utilizing these buildpacks. I'm not sure that'll get you 100% of the optimizations Spring Boot is doing, but it should get you a well-built image based on the Paketo buildpacks. – Daniel Mikusa Sep 27 '20 at 17:56
  • @DanielMikusa, does that include the layer detection/optimization provided by the Spring Boot plugin? – metacubed Sep 27 '20 at 20:06
  • Not sure exactly, I would suggest building images both ways and comparing them. You can use `dive` or something similar to compare the layers. https://github.com/wagoodman/dive – Daniel Mikusa Sep 28 '20 at 13:00

1 Answers1

1

As the layered jars feature (incl. layers.idx file generation and spring-boot-maven-plugin support for Cloud Native Buildpacks / Paketo.io) was introduced in Spring Boot 2.3 I would say that you can't really downgrade it with the standard tooling.

BUT I guess you could try to generate the layers.idx file yourself - or even choose a default file, since the layout of your app may not change that much after all. A example would be (using no SNAPSHOT depencencies):

- "dependencies":
  - "BOOT-INF/lib/"
- "spring-boot-loader":
  - "org/"
- "snapshot-dependencies":
- "application":
  - "BOOT-INF/classes/"
  - "BOOT-INF/classpath.idx"
  - "BOOT-INF/layers.idx"
  - "META-INF/"

Having this file in place (means place it into your target folder (maybe you could automate that with a simple Maven plugin for example)), pack CLI should be able to pick it up. So install pack CLI and run a Paketo build without using the spring-boot-maven-plugin yourself like this:

pack build yourAppNameHere --path . --builder paketobuildpacks/builder:base

I didn't really tried this approach myself - and maybe you run into problems, if the directory structure is much different in older Spring Boot versions. But I would appreciate to hear some feedback!

jonashackt
  • 12,022
  • 5
  • 67
  • 124