I updated my spring-boot application to use buildpacks to create my docker-image instead of a dockerfile. I also use Apache POI in my application and since that update I get an error when generating an xlsx file. After some digging, I think it happens because the fontconfig and/or ttf-dejavu packages are missing. But how do I add these in the dockerimage? With a dockerfile I would just add something like
RUN apt-get update && apt-get install fontconfig ttf-dejavu
But how do I achieve the same with buildpacks?
This answer assumes that by "... spring-boot application to use buildpacks" you mean the use of the
spring-boot:build-imagemaven goal.The issue lays with the default builder (
gcr.io/paketo-buildpacks/builder:base) used by the maven plugin. Builder is responsible for configuring the OS image, and the "base" builder doesn't includefontconfigpackage. .The easiest way to enable
fontconfigpackage is to use the "full" builder (gcr.io/paketo-buildpacks/builder:full-cforgcr.io/paketo-buildpacks/builder:latest); you can do so for example in one of the following ways:by specifying the builder configuration parameter in the maven plugin,
or directly on your
mvncommand line by adding-Dspring-boot.build-image.builder=gcr.io/paketo-buildpacks/builder:latest.However, this is not ideal because the full OS image is much larger (approx. 1.45GB for "full" vs. 644MB for "base" - observed in docker image listing), a fair bit of overhead "just" for enabling
fontconfig.A more involved approach would require creating a custom builder with custom mixins, in order to create a tailored "base" image with the extra packages. But I personally found it easier to just use the dockerfile approach in this scenario. Some articles on creating a custom builder: