runPull performs a pull against the engine based on the specified options
(ctx context.Context, dockerCLI command.Cli, opts pullOptions)
| 67 | |
| 68 | // runPull performs a pull against the engine based on the specified options |
| 69 | func runPull(ctx context.Context, dockerCLI command.Cli, opts pullOptions) error { |
| 70 | distributionRef, err := reference.ParseNormalizedNamed(opts.remote) |
| 71 | switch { |
| 72 | case err != nil: |
| 73 | return err |
| 74 | case opts.all && !reference.IsNameOnly(distributionRef): |
| 75 | return errors.New("tag can't be used with --all-tags/-a") |
| 76 | case !opts.all && reference.IsNameOnly(distributionRef): |
| 77 | distributionRef = reference.TagNameOnly(distributionRef) |
| 78 | if tagged, ok := distributionRef.(reference.Tagged); ok && !opts.quiet { |
| 79 | _, _ = fmt.Fprintln(dockerCLI.Out(), "Using default tag:", tagged.Tag()) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | var ociPlatforms []ocispec.Platform |
| 84 | if opts.platform != "" { |
| 85 | // TODO(thaJeztah): add a platform option-type / flag-type. |
| 86 | p, err := platforms.Parse(opts.platform) |
| 87 | if err != nil { |
| 88 | return err |
| 89 | } |
| 90 | ociPlatforms = append(ociPlatforms, p) |
| 91 | } |
| 92 | |
| 93 | encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCLI.ConfigFile(), distributionRef.String()) |
| 94 | if err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | responseBody, err := dockerCLI.Client().ImagePull(ctx, reference.FamiliarString(distributionRef), client.ImagePullOptions{ |
| 99 | RegistryAuth: encodedAuth, |
| 100 | PrivilegeFunc: nil, |
| 101 | All: opts.all, |
| 102 | Platforms: ociPlatforms, |
| 103 | }) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | defer responseBody.Close() |
| 108 | |
| 109 | out := dockerCLI.Out() |
| 110 | if opts.quiet { |
| 111 | out = streams.NewOut(io.Discard) |
| 112 | } |
| 113 | if err := jsonstream.Display(ctx, responseBody, out); err != nil { |
| 114 | return err |
| 115 | } |
| 116 | _, _ = fmt.Fprintln(dockerCLI.Out(), distributionRef.String()) |
| 117 | return nil |
| 118 | } |
no test coverage detected
searching dependent graphs…