github.com/opsramp/moby@v1.13.1/client/image_import.go (about)

     1  package client
     2  
     3  import (
     4  	"io"
     5  	"net/url"
     6  
     7  	"golang.org/x/net/context"
     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.ParseNamed(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  	for _, change := range options.Changes {
    29  		query.Add("changes", change)
    30  	}
    31  
    32  	resp, err := cli.postRaw(ctx, "/images/create", query, source.Source, nil)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  	return resp.body, nil
    37  }