github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/image_import.go (about) 1 package client 2 3 import ( 4 "io" 5 "net/url" 6 "strings" 7 8 "golang.org/x/net/context" 9 10 "github.com/docker/distribution/reference" 11 "github.com/docker/docker/api/types" 12 ) 13 14 // ImageImport creates a new image based in the source options. 15 // It returns the JSON content in the response body. 16 func (cli *Client) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) { 17 if ref != "" { 18 //Check if the given image name can be resolved 19 if _, err := reference.ParseNormalizedNamed(ref); err != nil { 20 return nil, err 21 } 22 } 23 24 query := url.Values{} 25 query.Set("fromSrc", source.SourceName) 26 query.Set("repo", ref) 27 query.Set("tag", options.Tag) 28 query.Set("message", options.Message) 29 if options.Platform != "" { 30 query.Set("platform", strings.ToLower(options.Platform)) 31 } 32 for _, change := range options.Changes { 33 query.Add("changes", change) 34 } 35 36 resp, err := cli.postRaw(ctx, "/images/create", query, source.Source, nil) 37 if err != nil { 38 return nil, err 39 } 40 return resp.body, nil 41 }