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
This commit is contained in:
Scott Frederick
2023-04-05 13:05:48 -05:00
parent cacc563fc0
commit 5817c8441d
68 changed files with 542 additions and 71 deletions

View File

@@ -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;
}
}