MCPcopy Index your code
hub / github.com/docker/cli / runImport

Function runImport

cli/command/image/import.go:60–108  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, options importOptions)

Source from the content-addressed store, hash-verified

58}
59
60func 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}

Callers 1

newImportCommandFunction · 0.70

Calls 6

ImageImportMethod · 0.80
GetSliceMethod · 0.80
InMethod · 0.65
ClientMethod · 0.65
OutMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…