mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-10-31 11:13:22 +00:00 
			
		
		
		
	Generated largely from the specified config; small parts taken from `docker image inspect`, such as the command line. Renamed some of the yaml keys to match the OCI spec rather than Docker Compose as we decided they are more readable, no more underscores. Add some extra functionality - tmpfs specification - fully general mount specification - no new privileges can be specified now For nostalgic reasons, using engine-api to talk to the docker cli as we only need an old API version, and it is nice and easy to vendor... Signed-off-by: Justin Cormack <justin.cormack@docker.com>
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package client
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"io"
 | |
| 	"net/http"
 | |
| 	"net/url"
 | |
| 
 | |
| 	"golang.org/x/net/context"
 | |
| 
 | |
| 	distreference "github.com/docker/distribution/reference"
 | |
| 	"github.com/docker/engine-api/types"
 | |
| )
 | |
| 
 | |
| // ImagePush requests the docker host to push an image to a remote registry.
 | |
| // It executes the privileged function if the operation is unauthorized
 | |
| // and it tries one more time.
 | |
| // It's up to the caller to handle the io.ReadCloser and close it properly.
 | |
| func (cli *Client) ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error) {
 | |
| 	distributionRef, err := distreference.ParseNamed(ref)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	if _, isCanonical := distributionRef.(distreference.Canonical); isCanonical {
 | |
| 		return nil, errors.New("cannot push a digest reference")
 | |
| 	}
 | |
| 
 | |
| 	var tag = ""
 | |
| 	if nameTaggedRef, isNamedTagged := distributionRef.(distreference.NamedTagged); isNamedTagged {
 | |
| 		tag = nameTaggedRef.Tag()
 | |
| 	}
 | |
| 
 | |
| 	query := url.Values{}
 | |
| 	query.Set("tag", tag)
 | |
| 
 | |
| 	resp, err := cli.tryImagePush(ctx, distributionRef.Name(), query, options.RegistryAuth)
 | |
| 	if resp.statusCode == http.StatusUnauthorized && options.PrivilegeFunc != nil {
 | |
| 		newAuthHeader, privilegeErr := options.PrivilegeFunc()
 | |
| 		if privilegeErr != nil {
 | |
| 			return nil, privilegeErr
 | |
| 		}
 | |
| 		resp, err = cli.tryImagePush(ctx, distributionRef.Name(), query, newAuthHeader)
 | |
| 	}
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return resp.body, nil
 | |
| }
 | |
| 
 | |
| func (cli *Client) tryImagePush(ctx context.Context, imageID string, query url.Values, registryAuth string) (*serverResponse, error) {
 | |
| 	headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
 | |
| 	return cli.post(ctx, "/images/"+imageID+"/push", query, nil, headers)
 | |
| }
 |