83477ce8d0
Use http.Header, which is more descriptive on intent, and we're already importing the package in the client. Removing the "header" type also fixes various locations where the type was shadowed by local variables named "headers". Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package client // import "github.com/docker/docker/client"
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/docker/distribution/reference"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/registry"
|
|
)
|
|
|
|
// ImageCreate creates a new image based on 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) {
|
|
ref, err := reference.ParseNormalizedNamed(parentReference)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
query := url.Values{}
|
|
query.Set("fromImage", reference.FamiliarName(ref))
|
|
query.Set("tag", getAPITagFromNamedRef(ref))
|
|
if options.Platform != "" {
|
|
query.Set("platform", strings.ToLower(options.Platform))
|
|
}
|
|
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) {
|
|
return cli.post(ctx, "/images/create", query, nil, http.Header{
|
|
registry.AuthHeader: {registryAuth},
|
|
})
|
|
}
|