0

With https://start.spring.io/ I created Spring Boot 3.x app with support for native image

I can build with gralde bootBuildImage

and run with docker run spring305gradlenativeimage:0.0.1-SNAPSHOT

How to use custom Dockerfile or extend this docker image with additional packages?

build.gradle :

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.5'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'org.graalvm.buildtools.native' version '0.9.20'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-graphql'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework:spring-webflux'
    testImplementation 'org.springframework.graphql:spring-graphql-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

P.S. I have checked https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html and https://graalvm.github.io/native-build-tools/latest/javadocs/native-gradle-plugin/org/graalvm/buildtools/gradle/dsl/NativeImageOptions.html

Paul Verest
  • 60,022
  • 51
  • 208
  • 332

1 Answers1

1

The bootBuildImage task is not coming from GraalVM, but from Spring Boot.
Its documentation and options can be found at https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#build-image.
So from what I see there from a quick look I guess you need to build an own image first that contains what you want and then configure that to be used by the bootBuildImage task.

Btw. you should start with removing the obsolete relict io.spring.dependency-management and replace it by the Gradle built-in BOM support using platform(...). Even the maintainer of that plugin recommends that.

Here another link about Spring Boot and Docker: https://spring.io/guides/topicals/spring-boot-docker/

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • +1 for the link, however reference has no mean to configure base image. I think it would be possible to create new image based on the one produced by gradle build. BTW `io.spring.dependency-management` comes by default with https://start.spring.io/ I bet they will replace it with something better, when ready. – Paul Verest Apr 19 '23 at 22:22
  • Here another link: https://spring.io/guides/topicals/spring-boot-docker/ :-) Regarding "base image" I assumed `runImage` might be it, but maybe not. But yeah, modifying the image after creation should also work out, or maybe you need a build pack to right away do you customizations. Regarding the dependency management plugin, yes, it comes from their generator, but that doesn't change anything I said. It is an obsolete relict from former times that is not necessary and sometimes even harmful and even the maintainer of the plugin recommends to not use it anymore. – Vampire Apr 19 '23 at 23:01
  • 1
    That they don't have the time to update their toolings is a different topic. – Vampire Apr 19 '23 at 23:02