2016-09-06 14:46:37 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-09-06 14:46:37 -04: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-25 19:54:18 -05:00
|
|
|
ref, err := reference.ParseNormalizedNamed(parentReference)
|
2016-09-06 14:46:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
query := url.Values{}
|
2017-01-25 19:54:18 -05:00
|
|
|
query.Set("fromImage", reference.FamiliarName(ref))
|
|
|
|
query.Set("tag", getAPITagFromNamedRef(ref))
|
2016-09-06 14:46:37 -04:00
|
|
|
resp, err := cli.tryImageCreate(ctx, query, options.RegistryAuth)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return resp.body, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) {
|
|
|
|
headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
|
|
|
|
return cli.post(ctx, "/images/create", query, nil, headers)
|
|
|
|
}
|