image_import.go 961 B

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