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

Function pushImageWithLocal

pkg/cmd/image/push.go:243–295  ·  view source on GitHub ↗
(ctx context.Context, client *containerd.Client, parsedReference *referenceutil.ImageReference, pushRef, rawRef string, options types.ImagePushOptions, platMC platforms.MatchComparer)

Source from the content-addressed store, hash-verified

241}
242
243func pushImageWithLocal(ctx context.Context, client *containerd.Client, parsedReference *referenceutil.ImageReference, pushRef, rawRef string, options types.ImagePushOptions, platMC platforms.MatchComparer) error {
244 ref := parsedReference.String()
245 refDomain := parsedReference.Domain
246
247 // In order to push images where most layers are the same but the
248 // repository name is different, it is necessary to refresh the
249 // PushTracker. Otherwise, the MANIFEST_BLOB_UNKNOWN error will occur due
250 // to the registry not creating the corresponding layer link file,
251 // resulting in the failure of the entire image push.
252 pushTracker := docker.NewInMemoryTracker()
253
254 pushFunc := func(r remotes.Resolver) error {
255 return push.Push(ctx, client, r, pushTracker, options.Stdout, pushRef, ref, platMC, options.AllowNondistributableArtifacts, options.Quiet)
256 }
257
258 var dOpts []dockerconfigresolver.Opt
259 if options.GOptions.InsecureRegistry {
260 log.G(ctx).Warnf("skipping verifying HTTPS certs for %q", refDomain)
261 dOpts = append(dOpts, dockerconfigresolver.WithSkipVerifyCerts(true))
262 }
263 dOpts = append(dOpts, dockerconfigresolver.WithHostsDirs(options.GOptions.HostsDir))
264
265 ho, err := dockerconfigresolver.NewHostOptions(ctx, refDomain, dOpts...)
266 if err != nil {
267 return err
268 }
269
270 resolverOpts := docker.ResolverOptions{
271 Tracker: pushTracker,
272 Hosts: dockerconfig.ConfigureHosts(ctx, *ho),
273 }
274
275 resolver := docker.NewResolver(resolverOpts)
276 if err = pushFunc(resolver); err != nil {
277 // In some circumstance (e.g. people just use 80 port to support pure http), the error will contain message like "dial tcp <port>: connection refused"
278 if !errors.Is(err, http.ErrSchemeMismatch) && !errutil.IsErrConnectionRefused(err) {
279 return err
280 }
281 if options.GOptions.InsecureRegistry {
282 log.G(ctx).WithError(err).Warnf("server %q does not seem to support HTTPS, falling back to plain HTTP", refDomain)
283 dOpts = append(dOpts, dockerconfigresolver.WithPlainHTTP(true))
284 resolver, err = dockerconfigresolver.New(ctx, refDomain, dOpts...)
285 if err != nil {
286 return err
287 }
288 return pushFunc(resolver)
289 }
290 log.G(ctx).WithError(err).Errorf("server %q does not seem to support HTTPS", refDomain)
291 log.G(ctx).Info("Hint: you may want to try --insecure-registry to allow plain HTTP (if you are in a trusted network)")
292 return err
293 }
294 return nil
295}

Callers 1

PushFunction · 0.85

Calls 9

PushFunction · 0.92
WithSkipVerifyCertsFunction · 0.92
WithHostsDirsFunction · 0.92
NewHostOptionsFunction · 0.92
IsErrConnectionRefusedFunction · 0.92
WithPlainHTTPFunction · 0.92
NewFunction · 0.92
InfoMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…