From 9b41f3c9b5f51ff27cb70ab5aa293a4cfd9af7bd Mon Sep 17 00:00:00 2001 From: Adam Eijdenberg Date: Wed, 5 Mar 2025 06:21:33 +0000 Subject: [PATCH] feat: use HistoryTimestamp, if set, for oci-archive entries Signed-off-by: Adam Eijdenberg --- commit.go | 2 +- common.go | 3 ++- tests/bud.bats | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/commit.go b/commit.go index a3f04ca6e..efe96f1ce 100644 --- a/commit.go +++ b/commit.go @@ -415,7 +415,7 @@ func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options } var manifestBytes []byte - if manifestBytes, err = retryCopyImage(ctx, policyContext, maybeCachedDest, maybeCachedSrc, dest, getCopyOptions(b.store, options.ReportWriter, nil, systemContext, "", false, options.SignBy, options.OciEncryptLayers, options.OciEncryptConfig, nil), options.MaxRetries, options.RetryDelay); err != nil { + if manifestBytes, err = retryCopyImage(ctx, policyContext, maybeCachedDest, maybeCachedSrc, dest, getCopyOptions(b.store, options.ReportWriter, nil, systemContext, "", false, options.SignBy, options.OciEncryptLayers, options.OciEncryptConfig, nil, options.HistoryTimestamp), options.MaxRetries, options.RetryDelay); err != nil { return imgID, nil, "", fmt.Errorf("copying layers and metadata for container %q: %w", b.ContainerID, err) } // If we've got more names to attach, and we know how to do that for diff --git a/common.go b/common.go index 92a7cffff..ed8fc17ed 100644 --- a/common.go +++ b/common.go @@ -27,7 +27,7 @@ const ( DOCKER = define.DOCKER ) -func getCopyOptions(store storage.Store, reportWriter io.Writer, sourceSystemContext *types.SystemContext, destinationSystemContext *types.SystemContext, manifestType string, removeSignatures bool, addSigner string, ociEncryptLayers *[]int, ociEncryptConfig *encconfig.EncryptConfig, ociDecryptConfig *encconfig.DecryptConfig) *cp.Options { +func getCopyOptions(store storage.Store, reportWriter io.Writer, sourceSystemContext *types.SystemContext, destinationSystemContext *types.SystemContext, manifestType string, removeSignatures bool, addSigner string, ociEncryptLayers *[]int, ociEncryptConfig *encconfig.EncryptConfig, ociDecryptConfig *encconfig.DecryptConfig, destinationTimestamp *time.Time) *cp.Options { sourceCtx := getSystemContext(store, nil, "") if sourceSystemContext != nil { *sourceCtx = *sourceSystemContext @@ -47,6 +47,7 @@ func getCopyOptions(store storage.Store, reportWriter io.Writer, sourceSystemCon OciEncryptConfig: ociEncryptConfig, OciDecryptConfig: ociDecryptConfig, OciEncryptLayers: ociEncryptLayers, + DestinationTimestamp: destinationTimestamp, } } diff --git a/tests/bud.bats b/tests/bud.bats index e141328a8..6f6a36414 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -7427,3 +7427,18 @@ EOF find ${TEST_SCRATCH_DIR}/buildcontext -ls expect_output "" "build should not be able to write to build context" } + +@test "build-with-timestamp-applies-to-oci-archive" { + local outpath="${TEST_SCRATCH_DIR}/timestamp-oci.tar" + + run_buildah build -f <(echo 'FROM scratch') --tag=oci-archive:${outpath}.a --timestamp 0 + run_buildah build -f <(echo 'FROM scratch') --tag=oci-archive:${outpath}.b --timestamp 1 + sleep 1.1 # sleep at least 1 second, so that timestamps are incremented + run_buildah build -f <(echo 'FROM scratch') --tag=oci-archive:${outpath}.c --timestamp 1 + + # should be different + ! diff "${outpath}.a" "${outpath}.b" + + # should be the same + diff "${outpath}.b" "${outpath}.c" +}