MCPcopy Create free account
hub / github.com/containerd/nerdctl / Push

Function Push

pkg/imgutil/push/push.go:43–115  ·  view source on GitHub ↗

Push pushes an image to a remote registry.

(ctx context.Context, client *containerd.Client, resolver remotes.Resolver, pushTracker docker.StatusTracker, stdout io.Writer,
	localRef, remoteRef string, platform platforms.MatchComparer, allowNonDist, quiet bool)

Source from the content-addressed store, hash-verified

41
42// Push pushes an image to a remote registry.
43func Push(ctx context.Context, client *containerd.Client, resolver remotes.Resolver, pushTracker docker.StatusTracker, stdout io.Writer,
44 localRef, remoteRef string, platform platforms.MatchComparer, allowNonDist, quiet bool) error {
45 img, err := client.ImageService().Get(ctx, localRef)
46 if err != nil {
47 return fmt.Errorf("unable to resolve image to manifest: %w", err)
48 }
49 desc := img.Target
50
51 ongoing := newPushJobs(pushTracker)
52
53 eg, ctx := errgroup.WithContext(ctx)
54
55 // used to notify the progress writer
56 doneCh := make(chan struct{})
57
58 eg.Go(func() error {
59 defer close(doneCh)
60
61 log.G(ctx).WithField("image", remoteRef).WithField("digest", desc.Digest).Debug("pushing")
62
63 jobHandler := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
64 if allowNonDist || !images.IsNonDistributable(desc.MediaType) {
65 ongoing.add(remotes.MakeRefKey(ctx, desc))
66 }
67 return nil, nil
68 })
69
70 if !allowNonDist {
71 jobHandler = remotes.SkipNonDistributableBlobs(jobHandler)
72 }
73
74 return client.Push(ctx, remoteRef, desc,
75 containerd.WithResolver(resolver),
76 containerd.WithImageHandler(jobHandler),
77 containerd.WithPlatformMatcher(platform),
78 )
79 })
80
81 if !quiet {
82 eg.Go(func() error {
83 var (
84 ticker = time.NewTicker(100 * time.Millisecond)
85 fw = progress.NewWriter(stdout)
86 start = time.Now()
87 done bool
88 )
89
90 defer ticker.Stop()
91
92 for {
93 select {
94 case <-ticker.C:
95 fw.Flush()
96
97 tw := tabwriter.NewWriter(fw, 1, 8, 1, ' ', 0)
98
99 jobs.Display(tw, ongoing.status(), start)
100 tw.Flush()

Callers 1

pushImageWithLocalFunction · 0.92

Calls 9

DisplayFunction · 0.92
newPushJobsFunction · 0.85
PushMethod · 0.80
StopMethod · 0.80
FlushMethod · 0.80
statusMethod · 0.80
GetMethod · 0.65
addMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…