archive: add WithSourceDateEpoch() for whiteouts

This makes diff archives to be reproducible.

The value is expected to be passed from CLI applications via the $SOUCE_DATE_EPOCH env var.

See https://reproducible-builds.org/docs/source-date-epoch/
for the $SOURCE_DATE_EPOCH specification.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2022-10-08 08:45:03 +09:00
parent 6fcfcf3a89
commit 70fbedc217
13 changed files with 390 additions and 104 deletions

View File

@@ -19,6 +19,7 @@ package diff
import (
"context"
"io"
"time"
"github.com/containerd/containerd/mount"
"github.com/containerd/typeurl"
@@ -44,6 +45,9 @@ type Config struct {
// the MediaType of the target diff content to the compressor.
// When using this config, MediaType must be specified as well.
Compressor func(dest io.Writer, mediaType string) (io.WriteCloser, error)
// SourceDateEpoch specifies the SOURCE_DATE_EPOCH without touching the env vars.
SourceDateEpoch *time.Time
}
// Opt is used to configure a diff operation
@@ -120,3 +124,12 @@ func WithPayloads(payloads map[string]typeurl.Any) ApplyOpt {
return nil
}
}
// WithSourceDateEpoch specifies the timestamp used for whiteouts to provide control for reproducibility.
// See also https://reproducible-builds.org/docs/source-date-epoch/ .
func WithSourceDateEpoch(tm *time.Time) Opt {
return func(c *Config) error {
c.SourceDateEpoch = tm
return nil
}
}