Add support for build workspace option when building images
Closes gh-37478
This commit is contained in:
@@ -202,12 +202,19 @@ The value supplied will be passed unvalidated to Docker when creating the builde
|
||||
The values provided to the `tags` option should be full image references in the form of `[image name]:[tag]` or `[repository]/[image name]:[tag]`.
|
||||
|
|
||||
|
||||
| `buildWorkspace`
|
||||
| A temporary workspace that will be used by the builder and buildpacks to store files during image building.
|
||||
The value can be a named volume or a bind mount location.
|
||||
| A named volume in the Docker daemon, with a name derived from the image name.
|
||||
|
||||
| `buildCache`
|
||||
| A cache containing layers created by buildpacks and used by the image building process.
|
||||
The value can be a named volume or a bind mount location.
|
||||
| A named volume in the Docker daemon, with a name derived from the image name.
|
||||
|
||||
| `launchCache`
|
||||
| A cache containing layers created by buildpacks and used by the image launching process.
|
||||
The value can be a named volume or a bind mount location.
|
||||
| A named volume in the Docker daemon, with a name derived from the image name.
|
||||
|
||||
| `createdDate` +
|
||||
@@ -403,7 +410,7 @@ include::../maven/packaging-oci-image/docker-pom-authentication-command-line.xml
|
||||
----
|
||||
|
||||
[[build-image.examples.caches]]
|
||||
=== Builder Cache Configuration
|
||||
=== Builder Cache and Workspace Configuration
|
||||
|
||||
The CNB builder caches layers that are used when building and launching an image.
|
||||
By default, these caches are stored as named volumes in the Docker daemon with names that are derived from the full name of the target image.
|
||||
@@ -416,7 +423,10 @@ The cache volumes can be configured to use alternative names to give more contro
|
||||
include::../maven/packaging-oci-image/caches-pom.xml[tags=caches]
|
||||
----
|
||||
|
||||
The caches can be configured to use bind mounts instead of named volumes, as shown in the following example:
|
||||
Builders and buildpacks need a location to store temporary files during image building.
|
||||
By default, this temporary build workspace is stored in a named volume.
|
||||
|
||||
The caches and the build workspace can be configured to use bind mounts instead of named volumes, as shown in the following example:
|
||||
|
||||
[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
|
||||
----
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<image>
|
||||
<buildWorkspace>
|
||||
<bind>
|
||||
<source>/tmp/cache-${project.artifactId}.work</source>
|
||||
</bind>
|
||||
</buildWorkspace>
|
||||
<buildCache>
|
||||
<bind>
|
||||
<source>/tmp/cache-${project.artifactId}.build</source>
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
<configuration>
|
||||
<image>
|
||||
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
|
||||
<buildWorkspace>
|
||||
<bind>
|
||||
<source>${java.io.tmpdir}/junit-image-cache-${test-build-id}-work</source>
|
||||
</bind>
|
||||
</buildWorkspace>
|
||||
<buildCache>
|
||||
<bind>
|
||||
<source>${java.io.tmpdir}/junit-image-cache-${test-build-id}-build</source>
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
<configuration>
|
||||
<image>
|
||||
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
|
||||
<buildWorkspace>
|
||||
<volume>
|
||||
<name>cache-${test-build-id}.work</name>
|
||||
</volume>
|
||||
</buildWorkspace>
|
||||
<buildCache>
|
||||
<volume>
|
||||
<name>cache-${test-build-id}.build</name>
|
||||
|
||||
@@ -69,6 +69,8 @@ public class Image {
|
||||
|
||||
List<String> tags;
|
||||
|
||||
CacheInfo buildWorkspace;
|
||||
|
||||
CacheInfo buildCache;
|
||||
|
||||
CacheInfo launchCache;
|
||||
@@ -243,6 +245,9 @@ public class Image {
|
||||
if (!CollectionUtils.isEmpty(this.tags)) {
|
||||
request = request.withTags(this.tags.stream().map(ImageReference::of).toList());
|
||||
}
|
||||
if (this.buildWorkspace != null) {
|
||||
request = request.withBuildWorkspace(this.buildWorkspace.asCache());
|
||||
}
|
||||
if (this.buildCache != null) {
|
||||
request = request.withBuildCache(this.buildCache.asCache());
|
||||
}
|
||||
|
||||
@@ -170,6 +170,14 @@ class ImageTests {
|
||||
ImageReference.of("example.com/my-app:0.0.1-SNAPSHOT"), ImageReference.of("example.com/my-app:latest"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBuildRequestWhenHasBuildWorkspaceVolumeUsesWorkspace() {
|
||||
Image image = new Image();
|
||||
image.buildWorkspace = CacheInfo.fromVolume(new VolumeCacheInfo("build-work-vol"));
|
||||
BuildRequest request = image.getBuildRequest(createArtifact(), mockApplicationContent());
|
||||
assertThat(request.getBuildWorkspace()).isEqualTo(Cache.volume("build-work-vol"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBuildRequestWhenHasBuildCacheVolumeUsesCache() {
|
||||
Image image = new Image();
|
||||
@@ -186,6 +194,14 @@ class ImageTests {
|
||||
assertThat(request.getLaunchCache()).isEqualTo(Cache.volume("launch-cache-vol"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBuildRequestWhenHasBuildWorkspaceBindUsesWorkspace() {
|
||||
Image image = new Image();
|
||||
image.buildWorkspace = CacheInfo.fromBind(new BindCacheInfo("build-work-dir"));
|
||||
BuildRequest request = image.getBuildRequest(createArtifact(), mockApplicationContent());
|
||||
assertThat(request.getBuildWorkspace()).isEqualTo(Cache.bind("build-work-dir"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBuildRequestWhenHasBuildCacheBindUsesCache() {
|
||||
Image image = new Image();
|
||||
|
||||
Reference in New Issue
Block a user