Skip to content

Commit 4ae6396

Browse files
authored
Merge pull request #6899 from aeijdenberg/fixmanifesttimestamp
feat(manifest-push): add --timestamp parameter
2 parents 03d9619 + f26f64d commit 4ae6396

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

cmd/buildah/manifest.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ func manifestInit() {
268268
if err := flags.MarkHidden("insecure"); err != nil {
269269
panic(fmt.Sprintf("error marking insecure as hidden: %v", err))
270270
}
271+
flags.Int64Var(&manifestPushOpts.destTimestamp, "timestamp", 0, "set timestamps on new content to `seconds` after the epoch")
271272
flags.BoolVar(&manifestPushOpts.tlsVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry. TLS verification cannot be used when talking to an insecure registry.")
272273
flags.BoolVarP(&manifestPushOpts.quiet, "quiet", "q", false, "don't output progress information when pushing lists")
273274
flags.IntVar(&manifestPushOpts.retry, "retry", int(defaultContainerConfig.Engine.Retry), "number of times to retry in case of failure when performing push")
@@ -1148,6 +1149,9 @@ func manifestPushCmd(c *cobra.Command, args []string, opts pushOptions) error {
11481149
opts.forceCompressionFormat = true
11491150
}
11501151
}
1152+
if c.Flag("timestamp").Changed {
1153+
opts.timestampSet = true
1154+
}
11511155

11521156
return manifestPush(systemContext, store, listImageSpec, destSpec, opts)
11531157
}
@@ -1219,7 +1223,10 @@ func manifestPush(systemContext *types.SystemContext, store storage.Store, listI
12191223
if !opts.quiet {
12201224
options.ReportWriter = os.Stderr
12211225
}
1222-
1226+
if opts.timestampSet {
1227+
ts := time.Unix(int64(opts.destTimestamp), 0).UTC()
1228+
options.DestinationTimestamp = &ts
1229+
}
12231230
_, digest, err := list.Push(getContext(), dest, options)
12241231

12251232
if err == nil && opts.rm {

cmd/buildah/push.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type pushOptions struct {
4848
encryptLayers []int
4949
insecure bool
5050
addCompression []string
51+
destTimestamp int64
52+
timestampSet bool
5153
}
5254

5355
func pushInit() {

docs/buildah-manifest-push.1.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ Delete the manifest list or image index from local storage if pushing succeeds.
9999

100100
Sign the pushed images using the GPG key that matches the specified fingerprint.
101101

102+
**--timestamp** *seconds*
103+
104+
Set the "created" timestamp for outputs to this number of seconds since
105+
the epoch (Unix time 0, i.e., 00:00:00 UTC on 1 January 1970) (defaults to
106+
current time). For example, if an oci-archive output is used, the tar entries
107+
created times are set to this value.
108+
102109
**--tls-verify** *bool-value*
103110

104111
Require HTTPS and verification of certificates when talking to container registries (defaults to true). TLS verification cannot be used when talking to an insecure registry.

tests/lists.bats

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,26 @@ IMAGE_LIST_S390X_INSTANCE_DIGEST=sha256:882a20ee0df7399a445285361d38b711c299ca09
252252
expect_output --substring "foo1: image not known"
253253
}
254254

255+
@test "manifest-push-with-timestamp" {
256+
outpath=${TEST_SCRATCH_DIR}/out
257+
258+
run_buildah manifest create foo
259+
run_buildah manifest add --all foo ${IMAGE_LIST}
260+
261+
run_buildah manifest push --timestamp=1 foo oci-archive:${outpath}.a
262+
run_buildah manifest push --timestamp=0 foo oci-archive:${outpath}.b
263+
sleep 1.1
264+
run_buildah manifest push --timestamp=0 foo oci-archive:${outpath}.c
265+
266+
run_buildah manifest rm foo
267+
268+
# should be different ( || false is due to bats weirdness )
269+
! diff "${outpath}.a" "${outpath}.b" || false
270+
271+
# should be the same
272+
diff "${outpath}.b" "${outpath}.c"
273+
}
274+
255275
@test "manifest-push" {
256276
run_buildah manifest create foo
257277
run_buildah manifest add --all foo ${IMAGE_LIST}

0 commit comments

Comments
 (0)