dockerspring-boot-maven-pluginplaywright-javapaketo

Spring Boot Maven Plugin - build docker image with custom binary dependencies


I use spring-boot-maven-plugin to build docker images. Under the hood, this uses buildpacks (paketo). My knowledge around buildpacks is very limited.

The problem is a new requirement: we will use the playwrite library. This library needs specific binaries to be installed in the host (browser engines, if I am not mistaken).

The Playwrite folks also have a custom docker image for this. If I would work with dockerfiles, I would simply use their image in mf FROM instruction.

But when it comes to buildpacks, is there a way to configure Spring Boot Maven Plugin to add the extra binaries on my image? Or should I migrate to some other maven plugin (like this one) that works with good-old dockerfiles and gain back explicit control over the image creation?

I have no specific reason to use buildpacks. I only used them because spring-boot-maven-plugin works with them. It is not clear to me if they are preferable to dockerfiles, so I am open to both trying to configure them to include the binaries, or, if this is not possible, to migrate to dockerfiles or some other alternative way to build docker images.


Solution

  • One way to do this would be to create a custom docker image and use another plugin to build it, like maven exec plugin.

    Here is an example of a production ready docker image, like the one Buildpacks generates for you:

    FROM eclipse-temurin:21 AS builder
    WORKDIR workspace
    ARG JAR_FILE=build/libs/*.jar
    COPY ${JAR_FILE} catalog-service.jar
    RUN java -Djarmode=layertools -jar catalog-service.jar extract
    
    FROM eclipse-temurin:21
    RUN useradd spring
    USER spring
    WORKDIR workspace
    COPY --from=builder workspace/dependencies/ ./
    COPY --from=builder workspace/spring-boot-loader/ ./
    COPY --from=builder workspace/snapshot-dependencies/ ./
    COPY --from=builder workspace/application/ ./
    ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
    

    You can customize this image as you see fit.