spring-bootdockercontainersbuildpackkamal

How to include curl in image built with bootbuildimage (spring boot) that uses Paketo Buildpacks


I have the below Dockerfile and part of a customization of the bootBuildImage gradle task.

My goal is to build an image that contains curl (and a minimal shell, /bin/sh to execute I think).

I use the Kamal deploy tool to deploy containerized applications. The deploy tool uses curl to do healthchecks after starting the app container.

When I deploy with the Dockerfile (default), everything works fine. Because curl is included in amazoncorretto:23.

But it fails for the default container image built with bootBuildImage (a much smaller container image created, 200MB Vs. 300MB in my app).

I don't understand how to customize the bootBuildImage task to produce an image with curl.

FROM amazoncorretto:23
WORKDIR /app
COPY customerservice/build/libs/A-0.0.1.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

// creates smaller docker images, buildpacks
tasks.named<org.springframework.boot.gradle.tasks.bundling.BootBuildImage>("bootBuildImage") {
    imageName.set("U/A:latest")
    publish.set(true)
    docker {
        publishRegistry {
            username = "U"
            password = System.getenv("DOCKER_REGISTRY_TOKEN")
        }
    }
    builder= "paketobuildpacks/builder-jammy-full:latest"
    environment.set(
        mapOf(
            "BP_IMAGE_LABELS" to "service=\"A\"",
            "BP_JVM_VERSION" to "23",
        )
    )
}

What I tried:


Solution

  • The builder that you use determines the stack that provides the base layers for both building and running the application. By default, Spring Boot uses the builder-jammy-java-tiny builder. It uses the tiny stack that produces the smallest images but does not contain tools like curl in its run image.

    The simplest way to build your application into an image that includes curl is with a builder that uses either the base or full stack, both of which include curl in their run images. For example, you could configure your bootBuildImage task to use paketobuildpacks/builder-jammy-base as its builder.

    If you want more control over exactly what's included in the base layer of your application's image, you can create your own stack and builder. This is certainly more work but, compared to just switching the builder-jammy-base, it provides far more control over exactly what will be in the image.