From 4981d7297f5addde8c1d8c819fb316dbe1bc87a9 Mon Sep 17 00:00:00 2001 From: tobi6112 <22715034+tobi6112@users.noreply.github.com> Date: Sun, 6 Feb 2022 15:09:52 +0100 Subject: [PATCH] Add a `useCurrentTimestamp` flag to jib --- .../image/jib/deployment/JibConfig.java | 9 ++++++++ .../image/jib/deployment/JibProcessor.java | 23 ++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibConfig.java b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibConfig.java index 923f8b6de9581..dd85c5192c359 100644 --- a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibConfig.java +++ b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibConfig.java @@ -173,4 +173,13 @@ public class JibConfig { */ @ConfigItem public Optional dockerExecutableName; + + /** + * Whether to set the creation time to the actual build time. Otherwise, the creation time + * will be set to the Unix epoch (00:00:00, January 1st, 1970 in UTC). See Jib + * FAQ for more information + */ + @ConfigItem(defaultValue = "true") + public boolean useCurrentTimestamp; } diff --git a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java index 3f18c66689740..f8e39464328ea 100644 --- a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java +++ b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java @@ -463,8 +463,12 @@ private JibContainerBuilder createContainerBuilderFromFastJar(String baseJvmImag .setWorkingDirectory(workDirInContainer) .setEntrypoint(entrypoint) .setEnvironment(getEnvironmentVariables(jibConfig)) - .setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels)) - .setCreationTime(Instant.now()); + .setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels)); + + if (jibConfig.useCurrentTimestamp) { + jibContainerBuilder.setCreationTime(Instant.now()); + } + for (int port : jibConfig.ports) { jibContainerBuilder.addExposedPort(Port.tcp(port)); } @@ -539,8 +543,11 @@ private JibContainerBuilder createContainerBuilderFromLegacyJar(String baseJvmIm JibContainerBuilder jibContainerBuilder = javaContainerBuilder.toContainerBuilder() .setEnvironment(getEnvironmentVariables(jibConfig)) - .setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels)) - .setCreationTime(Instant.now()); + .setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels)); + + if (jibConfig.useCurrentTimestamp) { + jibContainerBuilder.setCreationTime(Instant.now()); + } if (jibConfig.jvmEntrypoint.isPresent()) { jibContainerBuilder.setEntrypoint(jibConfig.jvmEntrypoint.get()); @@ -578,8 +585,12 @@ private JibContainerBuilder createContainerBuilderFromNative(JibConfig jibConfig .setWorkingDirectory(workDirInContainer) .setEntrypoint(entrypoint) .setEnvironment(getEnvironmentVariables(jibConfig)) - .setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels)) - .setCreationTime(Instant.now()); + .setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels)); + + if (jibConfig.useCurrentTimestamp) { + jibContainerBuilder.setCreationTime(Instant.now()); + } + for (int port : jibConfig.ports) { jibContainerBuilder.addExposedPort(Port.tcp(port)); }