Merge pull request #7651 from AkihiroSuda/custom-image-createdat

images: support specifying SourceDateEpoch via ctx
This commit is contained in:
Phil Estes
2022-12-12 12:59:38 -05:00
committed by GitHub
13 changed files with 241 additions and 108 deletions

View File

@@ -20,7 +20,9 @@ import (
gocontext "context"
"github.com/containerd/containerd"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/epoch"
"github.com/urfave/cli"
)
@@ -42,6 +44,12 @@ func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc)
} else {
ctx, cancel = gocontext.WithCancel(ctx)
}
if tm, err := epoch.SourceDateEpoch(); err != nil {
log.L.WithError(err).Warn("Failed to read SOURCE_DATE_EPOCH")
} else if tm != nil {
log.L.Debugf("Using SOURCE_DATE_EPOCH: %v", tm)
ctx = epoch.WithSourceDateEpoch(ctx, tm)
}
return ctx, cancel
}

View File

@@ -31,7 +31,6 @@ import (
"github.com/containerd/containerd/diff"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/pkg/epoch"
"github.com/containerd/containerd/pkg/progress"
"github.com/containerd/containerd/rootfs"
"github.com/containerd/containerd/snapshots"
@@ -142,14 +141,7 @@ var diffCommand = cli.Command{
diff.WithReference(context.String("ref")),
diff.WithLabels(labels),
}
ep, err := epoch.SourceDateEpoch()
if err != nil {
return err
}
if ep != nil {
opts = append(opts, diff.WithSourceDateEpoch(ep))
}
// SOURCE_DATE_EPOCH is propagated via the ctx, so no need to specify diff.WithSourceDateEpoch here
if idB == "" {
desc, err = rootfs.CreateDiff(ctx, idA, snapshotter, client.DiffService(), opts...)