gcr

package
v0.0.0-...-b95a7b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2024 License: BSD-3-Clause Imports: 11 Imported by: 1

Documentation

Overview

Client for interacting with the Google Container Registry.

The Docker v2 API is protected by OAuth2, but it doesn't look exactly like Google OAuth2, so we have to create our own token source.

Go implementation of the bash commands from:

https://stackoverflow.com/questions/34037256/does-google-container-registry-support-docker-remote-api-v2/34046435#34046435

I.e.:

$ export NAME=project-id/image
$ export BEARER=$(curl -u _token:$(gcloud auth print-access-token) https://gcr.io/v2/token?scope=repository:$NAME:pull | cut -d'"' -f 10)
$ curl -H "Authorization: Bearer $BEARER" https://gcr.io/v2/$NAME/tags/list

Index

Constants

View Source
const (
	Server = "gcr.io"
)

Variables

View Source
var (
	// DockerTagRegex is used to parse a Docker image tag as set by our
	// infrastructure, which uses the following format:
	//
	// ${datetime}-${user}-${git_hash:0:7}-${repo_state}
	//
	// Where datetime is a UTC timestamp following the format:
	//
	// +%Y-%m-%dT%H_%M_%SZ
	//
	// User is the username of the person who built the image, git_hash is the
	// abbreviated Git commit hash at which the image was built, and repo_state
	// is either "clean" or "dirty", depending on whether there were local
	// changes to the checkout at the time when the image was built.
	DockerTagRegex = regexp.MustCompile(`(\d{4}-\d{2}-\d{2}T\d{2}_\d{2}_\d{2}Z)-(\w+)-([a-f0-9]+)-(\w+)`)
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Google Cloud Registry that supports the v2 Docker API.

func NewClient

func NewClient(tokenSource oauth2.TokenSource, projectId, imageName string) *Client

NewClient creates a Client that retrieves information about the docker images store under 'projectID'/'image'.

tokenSource - An oauth2.TokenSource that Has read access to the bucket that the docker images are stored in. projectId - The Google Cloud project name, e.g. 'skia-public'. imageName - The name of the image, e.g. docserver.

func (*Client) Tags

func (c *Client) Tags(ctx context.Context) (*TagsResponse, error)

Tags returns all of the tags for all versions of the image.

type TagsResponse

type TagsResponse struct {
	Manifest map[string]struct {
		ImageSizeBytes string   `json:"imageSizeBytes"`
		LayerID        string   `json:"layerId"`
		Tags           []string `json:"tag"`
		TimeCreatedMs  string   `json:"timeCreatedMs"`
		TimeUploadedMs string   `json:"timeUploadedMs"`
	} `json:"manifest"`
	Name string   `json:"name"`
	Tags []string `json:"tags"`
}

TagsResponse is the response returned by Tags().

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL