Allow image Created date to be configurable

A `createdDate` option on the Maven `spring-boot:build-image` goal
and the Gradle `bootBuildImage` task can be used to set the `Created`
metadata field on a generated OCI image to a specified date or to
the current date.

Closes gh-28798
pull/34945/head
Scott Frederick 2 years ago
parent cacc563fc0
commit 5817c8441d

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
package org.springframework.boot.buildpack.platform.build;
import java.io.File;
import java.time.Instant;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
@ -79,6 +81,8 @@ public class BuildRequest {
private final Cache launchCache;
private final Instant createdDate;
BuildRequest(ImageReference name, Function<Owner, TarArchive> applicationContent) {
Assert.notNull(name, "Name must not be null");
Assert.notNull(applicationContent, "ApplicationContent must not be null");
@ -98,12 +102,14 @@ public class BuildRequest {
this.tags = Collections.emptyList();
this.buildCache = null;
this.launchCache = null;
this.createdDate = null;
}
BuildRequest(ImageReference name, Function<Owner, TarArchive> applicationContent, ImageReference builder,
ImageReference runImage, Creator creator, Map<String, String> env, boolean cleanCache,
boolean verboseLogging, PullPolicy pullPolicy, boolean publish, List<BuildpackReference> buildpacks,
List<Binding> bindings, String network, List<ImageReference> tags, Cache buildCache, Cache launchCache) {
List<Binding> bindings, String network, List<ImageReference> tags, Cache buildCache, Cache launchCache,
Instant createdDate) {
this.name = name;
this.applicationContent = applicationContent;
this.builder = builder;
@ -120,6 +126,7 @@ public class BuildRequest {
this.tags = tags;
this.buildCache = buildCache;
this.launchCache = launchCache;
this.createdDate = createdDate;
}
/**
@ -131,7 +138,8 @@ public class BuildRequest {
Assert.notNull(builder, "Builder must not be null");
return new BuildRequest(this.name, this.applicationContent, builder.inTaggedOrDigestForm(), this.runImage,
this.creator, this.env, this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish,
this.buildpacks, this.bindings, this.network, this.tags, this.buildCache, this.launchCache);
this.buildpacks, this.bindings, this.network, this.tags, this.buildCache, this.launchCache,
this.createdDate);
}
/**
@ -142,7 +150,8 @@ public class BuildRequest {
public BuildRequest withRunImage(ImageReference runImageName) {
return new BuildRequest(this.name, this.applicationContent, this.builder, runImageName.inTaggedOrDigestForm(),
this.creator, this.env, this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish,
this.buildpacks, this.bindings, this.network, this.tags, this.buildCache, this.launchCache);
this.buildpacks, this.bindings, this.network, this.tags, this.buildCache, this.launchCache,
this.createdDate);
}
/**
@ -154,7 +163,7 @@ public class BuildRequest {
Assert.notNull(creator, "Creator must not be null");
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
this.network, this.tags, this.buildCache, this.launchCache);
this.network, this.tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -170,7 +179,8 @@ public class BuildRequest {
env.put(name, value);
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator,
Collections.unmodifiableMap(env), this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish,
this.buildpacks, this.bindings, this.network, this.tags, this.buildCache, this.launchCache);
this.buildpacks, this.bindings, this.network, this.tags, this.buildCache, this.launchCache,
this.createdDate);
}
/**
@ -185,7 +195,7 @@ public class BuildRequest {
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator,
Collections.unmodifiableMap(updatedEnv), this.cleanCache, this.verboseLogging, this.pullPolicy,
this.publish, this.buildpacks, this.bindings, this.network, this.tags, this.buildCache,
this.launchCache);
this.launchCache, this.createdDate);
}
/**
@ -196,7 +206,7 @@ public class BuildRequest {
public BuildRequest withCleanCache(boolean cleanCache) {
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
this.network, this.tags, this.buildCache, this.launchCache);
this.network, this.tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -207,7 +217,7 @@ public class BuildRequest {
public BuildRequest withVerboseLogging(boolean verboseLogging) {
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
this.network, this.tags, this.buildCache, this.launchCache);
this.network, this.tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -218,7 +228,7 @@ public class BuildRequest {
public BuildRequest withPullPolicy(PullPolicy pullPolicy) {
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, pullPolicy, this.publish, this.buildpacks, this.bindings,
this.network, this.tags, this.buildCache, this.launchCache);
this.network, this.tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -229,7 +239,7 @@ public class BuildRequest {
public BuildRequest withPublish(boolean publish) {
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, publish, this.buildpacks, this.bindings,
this.network, this.tags, this.buildCache, this.launchCache);
this.network, this.tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -253,7 +263,7 @@ public class BuildRequest {
Assert.notNull(buildpacks, "Buildpacks must not be null");
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, buildpacks, this.bindings,
this.network, this.tags, this.buildCache, this.launchCache);
this.network, this.tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -277,7 +287,7 @@ public class BuildRequest {
Assert.notNull(bindings, "Bindings must not be null");
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, bindings,
this.network, this.tags, this.buildCache, this.launchCache);
this.network, this.tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -289,7 +299,7 @@ public class BuildRequest {
public BuildRequest withNetwork(String network) {
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
network, this.tags, this.buildCache, this.launchCache);
network, this.tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -311,7 +321,7 @@ public class BuildRequest {
Assert.notNull(tags, "Tags must not be null");
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
this.network, tags, this.buildCache, this.launchCache);
this.network, tags, this.buildCache, this.launchCache, this.createdDate);
}
/**
@ -323,7 +333,7 @@ public class BuildRequest {
Assert.notNull(buildCache, "BuildCache must not be null");
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
this.network, this.tags, buildCache, this.launchCache);
this.network, this.tags, buildCache, this.launchCache, this.createdDate);
}
/**
@ -335,7 +345,31 @@ public class BuildRequest {
Assert.notNull(launchCache, "LaunchCache must not be null");
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
this.network, this.tags, this.buildCache, launchCache);
this.network, this.tags, this.buildCache, launchCache, this.createdDate);
}
/**
* Return a new {@link BuildRequest} with an updated created date.
* @param createdDate the created date
* @return an updated build request
*/
public BuildRequest withCreatedDate(String createdDate) {
Assert.notNull(createdDate, "CreatedDate must not be null");
return new BuildRequest(this.name, this.applicationContent, this.builder, this.runImage, this.creator, this.env,
this.cleanCache, this.verboseLogging, this.pullPolicy, this.publish, this.buildpacks, this.bindings,
this.network, this.tags, this.buildCache, this.launchCache, parseCreatedDate(createdDate));
}
private Instant parseCreatedDate(String createdDate) {
if ("now".equalsIgnoreCase(createdDate)) {
return Instant.now();
}
try {
return Instant.parse(createdDate);
}
catch (DateTimeParseException ex) {
throw new IllegalArgumentException("Error parsing '" + createdDate + "' as an image created date", ex);
}
}
/**
@ -471,6 +505,14 @@ public class BuildRequest {
return this.launchCache;
}
/**
* Return the custom created date that should be used by the lifecycle.
* @return the created date
*/
public Instant getCreatedDate() {
return this.createdDate;
}
/**
* Factory method to create a new {@link BuildRequest} from a JAR file.
* @param jarFile the source jar file

@ -50,6 +50,8 @@ class Lifecycle implements Closeable {
private static final String PLATFORM_API_VERSION_KEY = "CNB_PLATFORM_API";
private static final String SOURCE_DATE_EPOCH_KEY = "SOURCE_DATE_EPOCH";
private static final String DOMAIN_SOCKET_PATH = "/var/run/docker.sock";
private final BuildLog log;
@ -184,6 +186,9 @@ class Lifecycle implements Closeable {
if (this.request.getNetwork() != null) {
phase.withNetworkMode(this.request.getNetwork());
}
if (this.request.getCreatedDate() != null) {
phase.withEnv(SOURCE_DATE_EPOCH_KEY, Long.toString(this.request.getCreatedDate().getEpochSecond()));
}
return phase;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,12 +44,15 @@ public class Image extends MappedObject {
private final String os;
private final String created;
Image(JsonNode node) {
super(node, MethodHandles.lookup());
this.digests = getDigests(getNode().at("/RepoDigests"));
this.config = new ImageConfig(getNode().at("/Config"));
this.layers = extractLayers(valueAt("/RootFS/Layers", String[].class));
this.os = valueAt("/Os", String.class);
this.created = valueAt("/Created", String.class);
}
private List<String> getDigests(JsonNode node) {
@ -100,6 +103,14 @@ public class Image extends MappedObject {
return (this.os != null) ? this.os : "linux";
}
/**
* Return the created date of the image.
* @return the image created date
*/
public String getCreated() {
return this.created;
}
/**
* Create a new {@link Image} instance from the specified JSON content.
* @param content the JSON content

@ -21,6 +21,9 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -258,6 +261,37 @@ class BuildRequestTests {
.withMessage("LaunchCache must not be null");
}
@Test
void withCreatedDateSetsCreatedDate() throws Exception {
Instant createDate = Instant.now();
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
BuildRequest withCreatedDate = request.withCreatedDate(createDate.toString());
assertThat(withCreatedDate.getCreatedDate()).isEqualTo(createDate);
}
@Test
void withCreatedDateNowSetsCreatedDate() throws Exception {
OffsetDateTime now = OffsetDateTime.now();
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
BuildRequest withCreatedDate = request.withCreatedDate("now");
OffsetDateTime createdDate = OffsetDateTime.ofInstant(withCreatedDate.getCreatedDate(), ZoneId.of("UTC"));
assertThat(createdDate.getYear()).isEqualTo(now.getYear());
assertThat(createdDate.getMonth()).isEqualTo(now.getMonth());
assertThat(createdDate.getDayOfMonth()).isEqualTo(now.getDayOfMonth());
withCreatedDate = request.withCreatedDate("NOW");
createdDate = OffsetDateTime.ofInstant(withCreatedDate.getCreatedDate(), ZoneId.of("UTC"));
assertThat(createdDate.getYear()).isEqualTo(now.getYear());
assertThat(createdDate.getMonth()).isEqualTo(now.getMonth());
assertThat(createdDate.getDayOfMonth()).isEqualTo(now.getDayOfMonth());
}
@Test
void withCreatedDateAndInvalidDateThrowsException() throws Exception {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));
assertThatIllegalArgumentException().isThrownBy(() -> request.withCreatedDate("not a date"))
.withMessageContaining("'not a date'");
}
private void hasExpectedJarContent(TarArchive archive) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

@ -116,7 +116,7 @@ class EphemeralBuilderTests extends AbstractJsonTests {
}
@Test
void getArchiveHasFixedCreateDate() throws Exception {
void getArchiveHasFixedCreatedDate() throws Exception {
EphemeralBuilder builder = new EphemeralBuilder(this.owner, this.image, this.targetImage, this.metadata,
this.creator, this.env, this.buildpacks);
Instant createInstant = builder.getArchive().getCreateDate();

@ -218,6 +218,17 @@ class LifecycleTests {
assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
}
@Test
void executeWithCreatedDateExecutesPhases() throws Exception {
given(this.docker.container().create(any())).willAnswer(answerWithGeneratedContainerId());
given(this.docker.container().create(any(), any())).willAnswer(answerWithGeneratedContainerId());
given(this.docker.container().wait(any())).willReturn(ContainerStatus.of(0, null));
BuildRequest request = getTestRequest().withCreatedDate("2020-07-01T12:34:56Z");
createLifecycle(request).execute();
assertPhaseWasRun("creator", withExpectedConfig("lifecycle-creator-created-date.json"));
assertThat(this.out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
}
@Test
void executeWithDockerHostAndRemoteAddressExecutesPhases() throws Exception {
given(this.docker.container().create(any())).willAnswer(answerWithGeneratedContainerId());

@ -67,6 +67,12 @@ class ImageTests extends AbstractJsonTests {
assertThat(image.getOs()).isEqualTo("linux");
}
@Test
void getCreatedReturnsDate() throws Exception {
Image image = getImage();
assertThat(image.getCreated()).isEqualTo("2019-10-30T19:34:56.296666503Z");
}
private Image getImage() throws IOException {
return Image.of(getContent("image.json"));
}

@ -0,0 +1,40 @@
{
"User": "root",
"Image": "pack.local/ephemeral-builder",
"Cmd": [
"/cnb/lifecycle/creator",
"-app",
"/workspace",
"-platform",
"/platform",
"-run-image",
"docker.io/cloudfoundry/run:latest",
"-layers",
"/layers",
"-cache-dir",
"/cache",
"-launch-cache",
"/launch-cache",
"-daemon",
"docker.io/library/my-application:latest"
],
"Env": [
"CNB_PLATFORM_API=0.8",
"SOURCE_DATE_EPOCH=1593606896"
],
"Labels": {
"author": "spring-boot"
},
"HostConfig": {
"Binds": [
"/var/run/docker.sock:/var/run/docker.sock",
"pack-layers-aaaaaaaaaa:/layers",
"pack-app-aaaaaaaaaa:/workspace",
"pack-cache-b35197ac41ea.build:/cache",
"pack-cache-b35197ac41ea.launch:/launch-cache"
],
"SecurityOpt" : [
"label=disable"
]
}
}

@ -193,6 +193,12 @@ The values provided to the `tags` option should be full image references in the
| A cache containing layers created by buildpacks and used by the image launching process.
| A named volume in the Docker daemon, with a name derived from the image name.
| `createdDate`
| `--createdDate`
| A date that will be used to set the `Created` field in the generated image's metadata.
The value must be a string in the ISO 8601 instant format, or `now` to use the current date and time.
| A fixed date that enables https://buildpacks.io/docs/features/reproducibility/[build reproducibility].
|===
NOTE: The plugin detects the target Java compatibility of the project using the JavaPlugin's `targetCompatibility` property.

@ -260,6 +260,16 @@ public abstract class BootBuildImage extends DefaultTask {
action.execute(this.launchCache);
}
/**
* Returns the date that will be used as the {@code Created} date of the image. When
* {@code null}, a fixed date that enables build reproducibility will be used.
* @return the created date
*/
@Input
@Optional
@Option(option = "createdDate", description = "The date to use as the created date of the image")
public abstract Property<String> getCreatedDate();
/**
* Returns the Docker configuration the builder will use.
* @return docker configuration.
@ -305,6 +315,7 @@ public abstract class BootBuildImage extends DefaultTask {
request = customizeTags(request);
request = customizeCaches(request);
request = request.withNetwork(getNetwork().getOrNull());
request = customizeCreatedDate(request);
return request;
}
@ -387,4 +398,12 @@ public abstract class BootBuildImage extends DefaultTask {
return request;
}
private BuildRequest customizeCreatedDate(BuildRequest request) {
String createdDate = getCreatedDate().getOrNull();
if (createdDate != null) {
return request.withCreatedDate(createdDate);
}
return request;
}
}

@ -26,6 +26,7 @@ import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.time.OffsetDateTime;
import java.util.Random;
import java.util.Set;
@ -42,6 +43,7 @@ import org.junit.jupiter.api.condition.OS;
import org.springframework.boot.buildpack.platform.docker.DockerApi;
import org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi;
import org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi;
import org.springframework.boot.buildpack.platform.docker.type.Image;
import org.springframework.boot.buildpack.platform.docker.type.ImageReference;
import org.springframework.boot.buildpack.platform.docker.type.VolumeName;
import org.springframework.boot.buildpack.platform.io.FilePermissions;
@ -140,12 +142,15 @@ class BootBuildImageIntegrationTests {
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT",
"--imageName=example/test-image-cmd",
"--builder=projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1",
"--runImage=projects.registry.vmware.com/springboot/run:tiny-cnb");
"--builder=projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2",
"--runImage=projects.registry.vmware.com/springboot/run:tiny-cnb",
"--createdDate=2020-07-01T12:34:56Z");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("example/test-image-cmd");
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
Image image = new DockerApi().image().inspect(ImageReference.of("example/test-image-cmd"));
assertThat(image.getCreated()).isEqualTo("2020-07-01T12:34:56Z");
removeImages("example/test-image-cmd");
}
@ -290,6 +295,49 @@ class BootBuildImageIntegrationTests {
deleteVolumes("cache-" + projectName + ".build", "cache-" + projectName + ".launch");
}
@TestTemplate
void buildsImageWithCreatedDate() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage");
String projectName = this.gradleBuild.getProjectDir().getName();
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
Image image = new DockerApi().image().inspect(ImageReference.of("docker.io/library/" + projectName));
assertThat(image.getCreated()).isEqualTo("2020-07-01T12:34:56Z");
removeImages(projectName);
}
@TestTemplate
void buildsImageWithCurrentCreatedDate() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage");
String projectName = this.gradleBuild.getProjectDir().getName();
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
Image image = new DockerApi().image().inspect(ImageReference.of("docker.io/library/" + projectName));
OffsetDateTime createdDateTime = OffsetDateTime.parse(image.getCreated());
OffsetDateTime current = OffsetDateTime.now();
assertThat(createdDateTime.getYear()).isEqualTo(current.getYear());
assertThat(createdDateTime.getMonth()).isEqualTo(current.getMonth());
assertThat(createdDateTime.getDayOfMonth()).isEqualTo(current.getDayOfMonth());
removeImages(projectName);
}
@TestTemplate
void failsWithInvalidCreatedDate() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.FAILED);
assertThat(result.getOutput()).contains("Error parsing 'invalid date' as an image created date");
}
@TestTemplate
void failsWithBuilderError() throws IOException {
writeMainClass();

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
bindings = [ "${projectDir}/bindings/ca-certificates:/platform/bindings/certificates" as String ]
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
buildpacks = [ "spring-boot/test-info" ]
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
buildpacks = [ "file://${projectDir}/buildpack/hello-world" as String ]
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
buildpacks = [ "file://${projectDir}/hello-world.tgz" as String ]
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
buildpacks = ["projects.registry.vmware.com/springboot/test-info:latest"]
}

@ -0,0 +1,10 @@
plugins {
id 'java'
id 'org.springframework.boot' version '{version}'
}
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
createdDate = "2020-07-01T12:34:56Z"
}

@ -0,0 +1,10 @@
plugins {
id 'java'
id 'org.springframework.boot' version '{version}'
}
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
createdDate = "now"
}

@ -8,7 +8,7 @@ targetCompatibility = '1.8'
bootBuildImage {
imageName = "example/test-image-custom"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
runImage = "projects.registry.vmware.com/springboot/run:tiny-cnb"
pullPolicy = "IF_NOT_PRESENT"
}

@ -8,6 +8,6 @@ targetCompatibility = '1.8'
bootBuildImage {
imageName = "example/test-image-name"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
}

@ -11,6 +11,6 @@ bootJar {
}
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
}

@ -11,7 +11,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
network = "none"
}

@ -13,6 +13,6 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = PullPolicy.ALWAYS
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
tags = [ "example.com/myapp:latest" ]
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
buildCache {
volume {

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
archiveFile = bootWar.archiveFile
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
buildCache {
volume {
name = "build-cache-volume1"

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
environment = ["FORCE_FAILURE": "true"]
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
buildpacks = [ "urn:cnb:builder:example/does-not-exist:0.0.1" ]
}

@ -0,0 +1,10 @@
plugins {
id 'java'
id 'org.springframework.boot' version '{version}'
}
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
createdDate = "invalid date"
}

@ -7,7 +7,7 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
tags = [ "example/Invalid-Tag-Name" ]
}

@ -11,6 +11,6 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
pullPolicy = "IF_NOT_PRESENT"
}

@ -7,6 +7,6 @@ sourceCompatibility = '1.8'
targetCompatibility = '1.8'
bootBuildImage {
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2"
publish = true
}

@ -203,6 +203,12 @@ The values provided to the `tags` option should be full image references in the
| A cache containing layers created by buildpacks and used by the image launching process.
| A named volume in the Docker daemon, with a name derived from the image name.
| `createdDate` +
(`spring-boot.build-image.createdDate`)
| A date that will be used to set the `Created` field in the generated image's metadata.
The value must be a string in the ISO 8601 instant format, or `now` to use the current date and time.
| A fixed date that enables https://buildpacks.io/docs/features/reproducibility/[build reproducibility].
|===
NOTE: The plugin detects the target Java compatibility of the project using the compiler's plugin configuration or the `maven.compiler.target` property.

@ -21,6 +21,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.OffsetDateTime;
import java.util.Random;
import java.util.stream.IntStream;
@ -29,6 +30,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.buildpack.platform.docker.DockerApi;
import org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi;
import org.springframework.boot.buildpack.platform.docker.type.Image;
import org.springframework.boot.buildpack.platform.docker.type.ImageName;
import org.springframework.boot.buildpack.platform.docker.type.ImageReference;
import org.springframework.boot.buildpack.platform.docker.type.VolumeName;
@ -240,14 +242,18 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("spring-boot.build-image.imageName", "example.com/test/cmd-property-name:v1")
.systemProperty("spring-boot.build-image.builder",
"projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1")
"projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2")
.systemProperty("spring-boot.build-image.runImage", "projects.registry.vmware.com/springboot/run:tiny-cnb")
.systemProperty("spring-boot.build-image.createdDate", "2020-07-01T12:34:56Z")
.execute((project) -> {
assertThat(buildLog(project)).contains("Building image")
.contains("example.com/test/cmd-property-name:v1")
.contains("---> Test Info buildpack building")
.contains("---> Test Info buildpack done")
.contains("Successfully built image");
Image image = new DockerApi().image()
.inspect(ImageReference.of("example.com/test/cmd-property-name:v1"));
assertThat(image.getCreated()).isEqualTo("2020-07-01T12:34:56Z");
removeImage("example.com/test/cmd-property-name", "v1");
});
}
@ -387,6 +393,47 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
});
}
@TestTemplate
void whenBuildImageIsInvokedWithCreatedDate(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-created-date")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId)
.execute((project) -> {
assertThat(buildLog(project)).contains("Building image")
.contains("docker.io/library/build-image-created-date:0.0.1.BUILD-SNAPSHOT")
.contains("Successfully built image");
Image image = new DockerApi().image()
.inspect(ImageReference.of("docker.io/library/build-image-created-date:0.0.1.BUILD-SNAPSHOT"));
assertThat(image.getCreated()).isEqualTo("2020-07-01T12:34:56Z");
removeImage("build-image-created-date", "0.0.1.BUILD-SNAPSHOT");
});
}
@TestTemplate
void whenBuildImageIsInvokedWithCurrentCreatedDate(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-current-created-date")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId)
.execute((project) -> {
assertThat(buildLog(project)).contains("Building image")
.contains("docker.io/library/build-image-current-created-date:0.0.1.BUILD-SNAPSHOT")
.contains("Successfully built image");
Image image = new DockerApi().image()
.inspect(ImageReference
.of("docker.io/library/build-image-current-created-date:0.0.1.BUILD-SNAPSHOT"));
OffsetDateTime createdDateTime = OffsetDateTime.parse(image.getCreated());
OffsetDateTime current = OffsetDateTime.now();
assertThat(createdDateTime.getYear()).isEqualTo(current.getYear());
assertThat(createdDateTime.getMonth()).isEqualTo(current.getMonth());
assertThat(createdDateTime.getDayOfMonth()).isEqualTo(current.getDayOfMonth());
removeImage("build-image-current-created-date", "0.0.1.BUILD-SNAPSHOT");
});
}
@TestTemplate
void failsWhenBuildImageIsInvokedOnMultiModuleProjectWithBuildImageGoal(MavenBuild mavenBuild) {
mavenBuild.project("build-image-multi-module")

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<buildpacks>
<buildpack>urn:cnb:builder:example/does-not-exist:0.0.1</buildpack>
</buildpacks>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<bindings>
<binding>${basedir}/bindings/ca-certificates:/platform/bindings/ca-certificates</binding>
</bindings>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<env>
<FORCE_FAILURE>true</FORCE_FAILURE>
</env>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<buildCache>
<volume>
<name>build-cache-volume1</name>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<buildCache>
<volume>
<name>cache-${test-build-id}.build</name>

@ -45,7 +45,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -39,7 +39,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -29,7 +29,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -19,7 +19,7 @@
<version>@project.version@</version>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</plugin>

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot.maven.it</groupId>
<artifactId>build-image-created-date</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>@java.version@</maven.compiler.source>
<maven.compiler.target>@java.version@</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>build-image-no-fork</goal>
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<createdDate>2020-07-01T12:34:56Z</createdDate>
</image>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,28 @@
/*
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.test;
public class SampleApplication {
public static void main(String[] args) throws Exception {
System.out.println("Launched");
synchronized(args) {
args.wait(); // Prevent exit"
}
}
}

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot.maven.it</groupId>
<artifactId>build-image-current-created-date</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>@java.version@</maven.compiler.source>
<maven.compiler.target>@java.version@</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>build-image-no-fork</goal>
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<createdDate>now</createdDate>
</image>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,28 @@
/*
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.test;
public class SampleApplication {
public static void main(String[] args) throws Exception {
System.out.println("Launched");
synchronized(args) {
args.wait(); // Prevent exit"
}
}
}

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<runImage>projects.registry.vmware.com/springboot/run:tiny-cnb</runImage>
</image>
</configuration>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<buildpacks>
<buildpack>urn:cnb:builder:spring-boot/test-info</buildpack>
</buildpacks>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<name>example.com/test/build-image:${project.version}</name>
</image>
</configuration>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<env>
<EMPTY_KEY></EMPTY_KEY>
</env>

@ -25,7 +25,7 @@
<configuration>
<finalName>final-name</finalName>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -31,7 +31,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<network>none</network>
</image>
</configuration>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<publish>true</publish>
</image>
</configuration>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
<tags>
<tag>${project.artifactId}:latest</tag>
</tags>

@ -24,7 +24,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -29,7 +29,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -26,7 +26,7 @@
<configuration>
<layout>ZIP</layout>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</plugin>

@ -23,7 +23,7 @@
</goals>
<configuration>
<image>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1</builder>
<builder>projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2</builder>
</image>
</configuration>
</execution>

@ -155,6 +155,14 @@ public abstract class BuildImageMojo extends AbstractPackagerMojo {
@Parameter(property = "spring-boot.build-image.network", readonly = true)
String network;
/**
* Alias for {@link Image#createdDate} to support configuration through command-line
* property.
* @since 3.1.0
*/
@Parameter(property = "spring-boot.build-image.createdDate", readonly = true)
String createdDate;
/**
* Docker configuration options.
* @since 2.4.0
@ -253,6 +261,9 @@ public abstract class BuildImageMojo extends AbstractPackagerMojo {
if (image.network == null && this.network != null) {
image.setNetwork(this.network);
}
if (image.createdDate == null && this.createdDate != null) {
image.setCreatedDate(this.createdDate);
}
return customize(image.getBuildRequest(this.project.getArtifact(), content));
}

@ -73,6 +73,8 @@ public class Image {
CacheInfo launchCache;
String createdDate;
/**
* The name of the created image.
* @return the image name
@ -173,6 +175,18 @@ public class Image {
this.network = network;
}
/**
* Returns the created date for the image.
* @return the created date
*/
public String getCreatedDate() {
return this.createdDate;
}
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
BuildRequest getBuildRequest(Artifact artifact, Function<Owner, TarArchive> applicationContent) {
return customize(BuildRequest.of(getOrDeduceName(artifact), applicationContent));
}
@ -221,6 +235,9 @@ public class Image {
if (this.launchCache != null) {
request = request.withLaunchCache(this.launchCache.asCache());
}
if (StringUtils.hasText(this.createdDate)) {
request = request.withCreatedDate(this.createdDate);
}
return request;
}

@ -185,6 +185,14 @@ class ImageTests {
assertThat(request.getLaunchCache()).isEqualTo(Cache.volume("launch-cache-vol"));
}
@Test
void getBuildRequestWhenHasCreatedDateUsesCreatedDate() {
Image image = new Image();
image.createdDate = "2020-07-01T12:34:56Z";
BuildRequest request = image.getBuildRequest(createArtifact(), mockApplicationContent());
assertThat(request.getCreatedDate()).isEqualTo("2020-07-01T12:34:56Z");
}
private Artifact createArtifact() {
return new DefaultArtifact("com.example", "my-app", VersionRange.createFromVersion("0.0.1-SNAPSHOT"), "compile",
"jar", null, new DefaultArtifactHandler());

@ -10,6 +10,6 @@ docker tag paketobuildpacks/run:tiny-cnb projects.registry.vmware.com/springboot
docker push projects.registry.vmware.com/springboot/run:tiny-cnb
cd builder
pack builder create projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1 --config builder.toml
docker push projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1
cd -
pack builder create projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2 --config builder.toml
docker push projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.2
cd -

@ -1,17 +1,21 @@
# Buildpacks to include in builder
[[buildpacks]]
id = "spring-boot/test-info"
version = "0.0.1"
version = "0.0.2"
uri = "../buildpacks/test-info"
# Order used for detection
[[order]]
[[order.group]]
id = "spring-boot/test-info"
version = "0.0.1"
version = "0.0.2"
# Stack that will be used by the builder
[stack]
id = "io.paketo.stacks.tiny"
build-image = "projects.registry.vmware.com/springboot/build:tiny-cnb"
run-image = "projects.registry.vmware.com/springboot/run:tiny-cnb"
# Lifecycle executable version that will be used by the builder
[lifecycle]
version = "0.15.3"

@ -1,10 +1,10 @@
# Buildpack API version
api = "0.2"
api = "0.8"
# Buildpack ID and metadata
[buildpack]
id = "spring-boot/test-info"
version = "0.0.1"
version = "0.0.2"
name = "Spring Boot Test Info Buildpack"
homepage = "https://github.com/spring-projects/spring-boot"

Loading…
Cancel
Save