2016-09-06 18:46:37 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/url"
|
2017-09-13 19:49:04 +00:00
|
|
|
"strings"
|
2016-09-06 18:46:37 +00:00
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-01-26 00:54:18 +00:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-09-06 18:46:37 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ImageCreate creates a new image based in the parent options.
|
|
|
|
// It returns the JSON content in the response body.
|
|
|
|
func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
|
2017-01-26 00:54:18 +00:00
|
|
|
ref, err := reference.ParseNormalizedNamed(parentReference)
|
2016-09-06 18:46:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
query := url.Values{}
|
2017-01-26 00:54:18 +00:00
|
|
|
query.Set("fromImage", reference.FamiliarName(ref))
|
|
|
|
query.Set("tag", getAPITagFromNamedRef(ref))
|
2017-09-13 19:49:04 +00:00
|
|
|
if options.Platform != "" {
|
|
|
|
query.Set("platform", strings.ToLower(options.Platform))
|
|
|
|
}
|
|
|
|
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
2016-09-06 18:46:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp.body, nil
|
|
|
|
}
|
|
|
|
|
2017-09-13 19:49:04 +00:00
|
|
|
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) {
|
2016-09-06 18:46:37 +00:00
|
|
|
headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
|
|
|
|
return cli.post(ctx, "/images/create", query, nil, headers)
|
|
|
|
}
|