Add support for caching to bind mounts when building images
When building an image using the Maven `spring-boot:build-image` goal or the Gradle `bootBuildImage` task, the build and launch caches can be configured to use a bind mount as an alternative to using a named volume. Closes gh-28387
This commit is contained in:
@@ -440,6 +440,20 @@ include::../gradle/packaging/boot-build-image-caches.gradle[tags=caches]
|
||||
include::../gradle/packaging/boot-build-image-caches.gradle.kts[tags=caches]
|
||||
----
|
||||
|
||||
The caches can be configured to use bind mounts instead of named volumes, as shown in the following example:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
|
||||
.Groovy
|
||||
----
|
||||
include::../gradle/packaging/boot-build-image-bind-caches.gradle[tags=caches]
|
||||
----
|
||||
|
||||
[source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
include::../gradle/packaging/boot-build-image-bind-caches.gradle.kts[tags=caches]
|
||||
----
|
||||
|
||||
[[build-image.examples.docker]]
|
||||
=== Docker Configuration
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '{gradle-project-version}'
|
||||
}
|
||||
|
||||
tasks.named("bootJar") {
|
||||
mainClass = 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::caches[]
|
||||
tasks.named("bootBuildImage") {
|
||||
buildCache {
|
||||
bind {
|
||||
source = "/tmp/cache-${rootProject.name}.build"
|
||||
}
|
||||
}
|
||||
launchCache {
|
||||
bind {
|
||||
source = "/tmp/cache-${rootProject.name}.launch"
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::caches[]
|
||||
|
||||
tasks.register("bootBuildImageCaches") {
|
||||
doFirst {
|
||||
bootBuildImage.buildCache.asCache().with { println "buildCache=$source" }
|
||||
bootBuildImage.launchCache.asCache().with { println "launchCache=$source" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
|
||||
|
||||
plugins {
|
||||
java
|
||||
id("org.springframework.boot") version "{gradle-project-version}"
|
||||
}
|
||||
|
||||
// tag::caches[]
|
||||
tasks.named<BootBuildImage>("bootBuildImage") {
|
||||
buildCache {
|
||||
bind {
|
||||
source.set("/tmp/cache-${rootProject.name}.build")
|
||||
}
|
||||
}
|
||||
launchCache {
|
||||
bind {
|
||||
source.set("/tmp/cache-${rootProject.name}.launch")
|
||||
}
|
||||
}
|
||||
}
|
||||
// end::caches[]
|
||||
|
||||
tasks.register("bootBuildImageCaches") {
|
||||
doFirst {
|
||||
println("buildCache=" + tasks.getByName<BootBuildImage>("bootBuildImage").buildCache.asCache().bind.source)
|
||||
println("launchCache=" + tasks.getByName<BootBuildImage>("bootBuildImage").launchCache.asCache().bind.source)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user