image_import.go 1.1 KB

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