github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/client/image_import.go (about)

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