image_create.go 833 B

12345678910111213141516171819202122232425262728293031
  1. package lib
  2. import (
  3. "io"
  4. "net/url"
  5. )
  6. // CreateImageOptions holds information to create images
  7. type CreateImageOptions struct {
  8. // Parent is the image to create this image from
  9. Parent string
  10. // Tag is the name to tag this image
  11. Tag string
  12. // RegistryAuth is the base64 encoded credentials for this server
  13. RegistryAuth string
  14. }
  15. // CreateImage creates a new image based in the parent options.
  16. // It returns the JSON content in the response body.
  17. func (cli *Client) CreateImage(options CreateImageOptions) (io.ReadCloser, error) {
  18. var query url.Values
  19. query.Set("fromImage", options.Parent)
  20. query.Set("tag", options.Tag)
  21. headers := map[string][]string{"X-Registry-Auth": {options.RegistryAuth}}
  22. resp, err := cli.POST("/images/create", query, nil, headers)
  23. if err != nil {
  24. return nil, err
  25. }
  26. return resp.body, nil
  27. }