diff --git a/imagebuildah/stage_executor.go b/imagebuildah/stage_executor.go index fcab73c778..3928457f59 100644 --- a/imagebuildah/stage_executor.go +++ b/imagebuildah/stage_executor.go @@ -2113,12 +2113,19 @@ func (s *StageExecutor) tagExistingImage(ctx context.Context, cacheID, output st return "", nil, fmt.Errorf("getting source imageReference for %q: %w", cacheID, err) } options := cp.Options{ - RemoveSignatures: true, // more like "ignore signatures", since they don't get removed when src and dest are the same image + RemoveSignatures: true, // more like "ignore signatures", since they don't get removed when src and dest are the same image + DestinationTimestamp: s.executor.timestamp, } manifestBytes, err := cp.Image(ctx, policyContext, dest, src, &options) if err != nil { return "", nil, fmt.Errorf("copying image %q: %w", cacheID, err) } + + // If the destination isn't container storage, then we're done and can return early + if dest.Transport().Name() != is.Transport.Name() { + return cacheID, nil, nil + } + manifestDigest, err := manifest.Digest(manifestBytes) if err != nil { return "", nil, fmt.Errorf("computing digest of manifest for image %q: %w", cacheID, err) diff --git a/tests/bud.bats b/tests/bud.bats index c67b4fc8ab..3d2a27319f 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -7856,6 +7856,17 @@ _EOF diff "${outpath}.b" "${outpath}.c" } +@test "build-with-timestamp-applies-to-oci-archive-with-base" { + local outpath="${TEST_SCRATCH_DIR}/timestamp-oci.tar" + + run_buildah build -f <(echo 'FROM busybox') --tag=oci-archive:${outpath}.a --timestamp 0 + sleep 1.1 # sleep at least 1 second, so that timestamps are incremented + run_buildah build -f <(echo 'FROM busybox') --tag=oci-archive:${outpath}.b --timestamp 0 + + # should be the same + diff "${outpath}.a" "${outpath}.b" +} + @test "bud-source-date-epoch-arg" { _prefetch busybox local timestamp=60