Skip to content

Commit 243d897

Browse files
Merge pull request #6023 from aeijdenberg/usehistorytimestampinociarchive
feat: use HistoryTimestamp, if set, for oci-archive entries
2 parents a682693 + 42e63dc commit 243d897

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options
415415
}
416416

417417
var manifestBytes []byte
418-
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 {
418+
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 {
419419
return imgID, nil, "", fmt.Errorf("copying layers and metadata for container %q: %w", b.ContainerID, err)
420420
}
421421
// If we've got more names to attach, and we know how to do that for

common.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
DOCKER = define.DOCKER
2828
)
2929

30-
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 {
30+
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 {
3131
sourceCtx := getSystemContext(store, nil, "")
3232
if sourceSystemContext != nil {
3333
*sourceCtx = *sourceSystemContext
@@ -47,6 +47,7 @@ func getCopyOptions(store storage.Store, reportWriter io.Writer, sourceSystemCon
4747
OciEncryptConfig: ociEncryptConfig,
4848
OciDecryptConfig: ociDecryptConfig,
4949
OciEncryptLayers: ociEncryptLayers,
50+
DestinationTimestamp: destinationTimestamp,
5051
}
5152
}
5253

tests/bud.bats

+15
Original file line numberDiff line numberDiff line change
@@ -7427,3 +7427,18 @@ EOF
74277427
find ${TEST_SCRATCH_DIR}/buildcontext -ls
74287428
expect_output "" "build should not be able to write to build context"
74297429
}
7430+
7431+
@test "build-with-timestamp-applies-to-oci-archive" {
7432+
local outpath="${TEST_SCRATCH_DIR}/timestamp-oci.tar"
7433+
7434+
run_buildah build -f <(echo 'FROM scratch') --tag=oci-archive:${outpath}.a --timestamp 0
7435+
run_buildah build -f <(echo 'FROM scratch') --tag=oci-archive:${outpath}.b --timestamp 1
7436+
sleep 1.1 # sleep at least 1 second, so that timestamps are incremented
7437+
run_buildah build -f <(echo 'FROM scratch') --tag=oci-archive:${outpath}.c --timestamp 1
7438+
7439+
# should be different ( || false is due to bats weirdness )
7440+
! diff "${outpath}.a" "${outpath}.b" || false
7441+
7442+
# should be the same
7443+
diff "${outpath}.b" "${outpath}.c"
7444+
}

0 commit comments

Comments
 (0)