Custom Dockerfile, base image or docker image extension for Spring Boot 3.x

huangapple go评论75阅读模式
英文:

Custom Dockerfile, base image or docker image extension for Spring Boot 3.x

问题

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

I can build with gralde bootBuildImage

and run with docker run spring305gradlenativeimage:0.0.1-SNAPSHOT

如何使用自定义的 Dockerfile 或扩展此 Docker 镜像以添加附加软件包?

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. 我已检查了 https://graalvm.github.io/native-build-tools/latest/gradle-plugin.htmlhttps://graalvm.github.io/native-build-tools/latest/javadocs/native-gradle-plugin/org/graalvm/buildtools/gradle/dsl/NativeImageOptions.html

英文:

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

答案1

得分: 1

The bootBuildImage task 不是来自 GraalVM,而是来自 Spring Boot。
可以在 https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#build-image 找到它的文档和选项。
所以从我快速查看的内容来看,我猜你需要首先构建一个包含你想要的内容的自定义镜像,然后配置它供 bootBuildImage 任务使用。

另外,你应该开始移除过时的 io.spring.dependency-management,并使用 Gradle 内置的 BOM 支持,使用 platform(...) 来替代。即使该插件的维护者也建议这样做。

这里还有一个关于 Spring Boot 和 Docker 的链接:https://spring.io/guides/topicals/spring-boot-docker/

英文:

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/

huangapple
  • 本文由 发表于 2023年4月20日 04:14:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058479.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定