(ctx context.Context, dockerCli command.Cli, options importOptions)
| 58 | } |
| 59 | |
| 60 | func runImport(ctx context.Context, dockerCli command.Cli, options importOptions) error { |
| 61 | var source client.ImageImportSource |
| 62 | switch { |
| 63 | case options.source == "-": |
| 64 | // import from STDIN |
| 65 | source = client.ImageImportSource{ |
| 66 | Source: dockerCli.In(), |
| 67 | SourceName: options.source, |
| 68 | } |
| 69 | case strings.HasPrefix(options.source, "https://"), strings.HasPrefix(options.source, "http://"): |
| 70 | // import from a remote source (handled by the daemon) |
| 71 | source = client.ImageImportSource{ |
| 72 | SourceName: options.source, |
| 73 | } |
| 74 | default: |
| 75 | // import from a local file |
| 76 | file, err := os.Open(options.source) |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | defer file.Close() |
| 81 | source = client.ImageImportSource{ |
| 82 | Source: file, |
| 83 | SourceName: "-", |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // TODO(thaJeztah): add a platform option-type / flag-type. |
| 88 | var ociPlatform ocispec.Platform |
| 89 | if options.platform != "" { |
| 90 | var err error |
| 91 | ociPlatform, err = platforms.Parse(options.platform) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | responseBody, err := dockerCli.Client().ImageImport(ctx, source, options.reference, client.ImageImportOptions{ |
| 98 | Message: options.message, |
| 99 | Changes: options.changes.GetSlice(), |
| 100 | Platform: ociPlatform, |
| 101 | }) |
| 102 | if err != nil { |
| 103 | return err |
| 104 | } |
| 105 | defer responseBody.Close() |
| 106 | |
| 107 | return jsonstream.Display(ctx, responseBody, dockerCli.Out()) |
| 108 | } |
no test coverage detected
searching dependent graphs…