MCPcopy
hub / github.com/containerd/containerd / push

Method push

core/remotes/docker/pusher.go:76–328  ·  view source on GitHub ↗
(ctx context.Context, desc ocispec.Descriptor, ref string, unavailableOnFail bool)

Source from the content-addressed store, hash-verified

74}
75
76func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref string, unavailableOnFail bool) (content.Writer, error) {
77 if l, ok := p.tracker.(StatusTrackLocker); ok {
78 l.Lock(ref)
79 defer l.Unlock(ref)
80 }
81 ctx, err := ContextWithRepositoryScope(ctx, p.refspec, true)
82 if err != nil {
83 return nil, err
84 }
85 status, err := p.tracker.GetStatus(ref)
86 if err == nil {
87 if status.Committed && status.Offset == status.Total {
88 return nil, fmt.Errorf("ref %v: %w", ref, errdefs.ErrAlreadyExists)
89 }
90 if unavailableOnFail && status.ErrClosed == nil {
91 // Another push of this ref is happening elsewhere. The rest of function
92 // will continue only when `errdefs.IsNotFound(err) == true` (i.e. there
93 // is no actively-tracked ref already).
94 return nil, fmt.Errorf("push is on-going: %w", errdefs.ErrUnavailable)
95 }
96 // TODO: Handle incomplete status
97 } else if !errdefs.IsNotFound(err) {
98 return nil, fmt.Errorf("failed to get status: %w", err)
99 }
100
101 hosts := p.filterHosts(HostCapabilityPush)
102 if len(hosts) == 0 {
103 return nil, fmt.Errorf("no push hosts: %w", errdefs.ErrNotFound)
104 }
105
106 var (
107 isManifest bool
108 existCheck []string
109 host = hosts[0]
110 )
111
112 if images.IsManifestType(desc.MediaType) || images.IsIndexType(desc.MediaType) {
113 isManifest = true
114 existCheck = getManifestPath(p.object, desc.Digest)
115 } else {
116 existCheck = []string{"blobs", desc.Digest.String()}
117 }
118
119 req := p.request(host, http.MethodHead, existCheck...)
120 if err := req.addNamespace(p.refspec.Hostname()); err != nil {
121 return nil, err
122 }
123 req.header.Set("Accept", strings.Join([]string{desc.MediaType, `*/*`}, ", "))
124
125 log.G(ctx).WithField("url", req.sanitizedURL()).Debugf("checking and pushing to")
126
127 resp, err := req.doWithRetries(ctx, true)
128 if err != nil {
129 if !errors.Is(err, ErrInvalidAuthorization) {
130 return nil, err
131 }
132 log.G(ctx).WithError(err).Debugf("Unable to check existence, continuing with push")
133 } else {

Callers 5

WriterMethod · 0.95
PushMethod · 0.95
TestPusherErrResetFunction · 0.45
Test_dockerPusher_pushFunction · 0.45

Calls 15

IsManifestTypeFunction · 0.92
IsIndexTypeFunction · 0.92
getManifestPathFunction · 0.85
unexpectedResponseErrFunction · 0.85
requestWithMountFromFunction · 0.85
newPushWriterFunction · 0.85
filterHostsMethod · 0.80
requestMethod · 0.80
addNamespaceMethod · 0.80

Tested by 3

TestPusherErrResetFunction · 0.36
Test_dockerPusher_pushFunction · 0.36