(ctx context.Context, client *containerd.Client, parsedReference *referenceutil.ImageReference, pushRef, rawRef string, options types.ImagePushOptions)
| 182 | } |
| 183 | |
| 184 | func PushImageWithTransfer(ctx context.Context, client *containerd.Client, parsedReference *referenceutil.ImageReference, pushRef, rawRef string, options types.ImagePushOptions) error { |
| 185 | source, err := preparePushStore(pushRef, options) |
| 186 | if err != nil { |
| 187 | return err |
| 188 | } |
| 189 | |
| 190 | progressWriter := io.Discard |
| 191 | if options.Stdout != nil { |
| 192 | progressWriter = options.Stdout |
| 193 | } |
| 194 | |
| 195 | pusher, cleanup, err := createOCIRegistry(ctx, parsedReference, options.GOptions, false) |
| 196 | if err != nil { |
| 197 | return err |
| 198 | } |
| 199 | defer cleanup() |
| 200 | |
| 201 | transferErr := doTransfer(ctx, client, source, pusher, options.Quiet, progressWriter) |
| 202 | |
| 203 | if transferErr != nil && (errors.Is(transferErr, http.ErrSchemeMismatch) || errutil.IsErrConnectionRefused(transferErr) || errutil.IsErrHTTPResponseToHTTPSClient(transferErr) || errutil.IsErrTLSHandshakeFailure(transferErr)) { |
| 204 | if options.GOptions.InsecureRegistry { |
| 205 | log.G(ctx).WithError(transferErr).Warnf("server %q does not seem to support HTTPS, falling back to plain HTTP", parsedReference.Domain) |
| 206 | pusher, cleanup2, err := createOCIRegistry(ctx, parsedReference, options.GOptions, true) |
| 207 | if err != nil { |
| 208 | return err |
| 209 | } |
| 210 | defer cleanup2() |
| 211 | transferErr = doTransfer(ctx, client, source, pusher, options.Quiet, progressWriter) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if transferErr != nil { |
| 216 | log.G(ctx).WithError(transferErr).Errorf("server %q does not seem to support HTTPS", parsedReference.Domain) |
| 217 | log.G(ctx).Info("Hint: you may want to try --insecure-registry to allow plain HTTP (if you are in a trusted network)") |
| 218 | return transferErr |
| 219 | } |
| 220 | |
| 221 | return nil |
| 222 | } |
| 223 | |
| 224 | func doTransfer(ctx context.Context, client *containerd.Client, src, dst interface{}, quiet bool, progressWriter io.Writer) error { |
| 225 | opts := make([]transfer.Opt, 0, 1) |
no test coverage detected
searching dependent graphs…