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:
@@ -65,6 +65,11 @@ func (s *walkingDiff) Compare(ctx context.Context, lower, upper []mount.Mount, o
|
||||
}
|
||||
}
|
||||
|
||||
var writeDiffOpts []archive.WriteDiffOpt
|
||||
if config.SourceDateEpoch != nil {
|
||||
writeDiffOpts = append(writeDiffOpts, archive.WithSourceDateEpoch(config.SourceDateEpoch))
|
||||
}
|
||||
|
||||
var isCompressed bool
|
||||
if config.Compressor != nil {
|
||||
if config.MediaType == "" {
|
||||
@@ -136,7 +141,7 @@ func (s *walkingDiff) Compare(ctx context.Context, lower, upper []mount.Mount, o
|
||||
return fmt.Errorf("failed to get compressed stream: %w", errOpen)
|
||||
}
|
||||
}
|
||||
errOpen = archive.WriteDiff(ctx, io.MultiWriter(compressed, dgstr.Hash()), lowerRoot, upperRoot)
|
||||
errOpen = archive.WriteDiff(ctx, io.MultiWriter(compressed, dgstr.Hash()), lowerRoot, upperRoot, writeDiffOpts...)
|
||||
compressed.Close()
|
||||
if errOpen != nil {
|
||||
return fmt.Errorf("failed to write compressed diff: %w", errOpen)
|
||||
@@ -147,7 +152,7 @@ func (s *walkingDiff) Compare(ctx context.Context, lower, upper []mount.Mount, o
|
||||
}
|
||||
config.Labels[uncompressed] = dgstr.Digest().String()
|
||||
} else {
|
||||
if errOpen = archive.WriteDiff(ctx, cw, lowerRoot, upperRoot); errOpen != nil {
|
||||
if errOpen = archive.WriteDiff(ctx, cw, lowerRoot, upperRoot, writeDiffOpts...); errOpen != nil {
|
||||
return fmt.Errorf("failed to write diff: %w", errOpen)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user