registry

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package registry talks to container registries (Docker Hub, GHCR, GitLab, Harbor, ECR, ACR, Artifact Registry, registry:2) over the OCI Distribution API, with basic or bearer-token auth.

Index

Constants

View Source
const ACRUser = "00000000-0000-0000-0000-000000000000"

ACRUser is the user name that goes with an Azure Container Registry refresh token, as `az acr login` uses it.

View Source
const Accept = "application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, " +
	"application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json"

Accept lists the manifest types komando reads.

Variables

This section is empty.

Functions

func CAPool added in v0.3.0

func CAPool(pem []byte) (*x509.CertPool, error)

CAPool is the system's CAs plus the PEM certificates in pem, for a registry with a certificate from a private CA (mkcert, an internal CA).

func CheckRef added in v0.13.0

func CheckRef(ref string) error

CheckRef says what is wrong with a tag or digest, or nil.

func CheckRepo added in v0.13.0

func CheckRepo(repo string) error

CheckRepo says what is wrong with a repository name, or nil.

Types

type Client

type Client struct {
	Base     *url.URL
	User     string
	Password string
	// contains filtered or unexported fields
}

Client calls one registry.

func New

func New(host string, t TLS, user, password string, dial func(ctx context.Context, network, addr string) (net.Conn, error)) *Client

New makes a client. host is host[:port]. dial may be nil; it gets the host name, not an address, so a --via server resolves the name itself (its /etc/hosts applies), while the certificate check and the Host header keep using the name.

func (*Client) ACRLogin added in v0.9.0

func (c *Client) ACRLogin(ctx context.Context, aadToken, tenant string) error

ACRLogin trades an Azure AD access token for a refresh token of this Azure Container Registry (its POST /oauth2/exchange) and logs in with it from now on. tenant may be "". The exchange goes the client's way (its --via path and TLS settings), and only over https with the certificate checked: the Azure token is good for the whole subscription.

func (*Client) Catalog

func (c *Client) Catalog(ctx context.Context, limit int) ([]string, error)

Catalog lists repositories (registries like Docker Hub do not allow it).

func (*Client) CheckedTLS added in v0.9.0

func (c *Client) CheckedTLS() bool

CheckedTLS says whether the client talks HTTPS and checks the registry's certificate. A cloud login sends a token that is good for far more than the registry, so it goes only to a registry whose certificate is checked.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, repo, digest string) error

Delete removes a manifest by digest. Every tag pointing at it goes too.

func (*Client) Digest

func (c *Client) Digest(ctx context.Context, repo, ref string) (string, error)

Digest returns the digest a tag points at, with a HEAD request.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, q url.Values, accept string) (*http.Response, error)

Do sends a request with auth, retrying once with a token if the registry asks for one.

func (*Client) DockerHub added in v0.13.0

func (c *Client) DockerHub() bool

DockerHub says whether the client talks to Docker Hub.

func (*Client) Inspect

func (c *Client) Inspect(ctx context.Context, repo, ref string) (*Manifest, error)

Inspect reads a manifest (or index) and, for one image, its config.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks that the registry answers and accepts the login (GET /v2/).

func (*Client) Repo added in v0.13.0

func (c *Client) Repo(repo string) string

Repo is the name the registry knows a repository by: on Docker Hub an official image (nginx) lives under library/, as docker pull reads it.

func (*Client) Send

func (c *Client) Send(ctx context.Context, method string, u *url.URL, accept, contentType string, body io.Reader, size int64) (*http.Response, error)

Send is Do for any URL on the registry (upload locations are absolute) and with an optional body. A body cannot be sent twice, so callers get the token first with a body-less request in the same scope.

func (*Client) Tags

func (c *Client) Tags(ctx context.Context, repo string, limit int) ([]string, error)

Tags lists a repository's tags.

type CopyResult

type CopyResult struct {
	Digest       string `json:"digest"`             // of the top manifest (or index)
	Manifests    int    `json:"manifests"`          // manifests written (index + images)
	BlobsCopied  int    `json:"blobs_copied"`       // layers and configs uploaded
	BlobsSkipped int    `json:"blobs_skipped"`      // already in the destination
	BlobsMounted int    `json:"blobs_mounted"`      // linked without copying (same registry)
	Bytes        int64  `json:"bytes"`              // uploaded
	Replaced     bool   `json:"replaced,omitempty"` // the destination tag pointed elsewhere
}

CopyResult says what a Copy did.

func Copy

func Copy(ctx context.Context, src *Client, srcRepo, ref string, dst *Client, dstRepo, dstTag string) (*CopyResult, error)

Copy copies srcRepo:ref from src to dstRepo:dstTag on dst, with every platform of a multi-platform image. Blobs the destination already has are skipped; on the same registry they are mounted instead of downloaded. The manifest bytes are copied unchanged, so the digest stays the same.

type Error

type Error struct {
	Status     int
	Code       string
	Message    string
	RetryAfter string // the Retry-After header of a 429 or 503, as sent
	Manifest   bool   // the request was for a manifest or blob: a 404 means the tag is missing
}

Error is an error answer from the registry.

func (*Error) Error

func (e *Error) Error() string

type Manifest

type Manifest struct {
	Repo      string            `json:"repo"`
	Ref       string            `json:"ref"`
	Digest    string            `json:"digest"`
	MediaType string            `json:"media_type"`
	Size      int64             `json:"size,omitempty"` // layers, compressed
	Layers    int               `json:"layers,omitempty"`
	Platforms []string          `json:"platforms,omitempty"`
	Created   string            `json:"created,omitempty"`
	Labels    map[string]string `json:"labels,omitempty"`
}

Manifest is what `registry inspect` shows.

type PruneImage added in v0.3.0

type PruneImage struct {
	Digest  string    `json:"digest"`
	Tags    []string  `json:"tags"`
	Created time.Time `json:"created"`
}

PruneImage is one image (digest) to delete, with every tag on it.

type PruneKeep added in v0.3.0

type PruneKeep struct {
	Tag    string `json:"tag"`
	Reason string `json:"reason"`
}

PruneKeep is a tag that stays, and why.

type PrunePlan added in v0.3.0

type PrunePlan struct {
	Delete []PruneImage `json:"delete"`
	Keep   []PruneKeep  `json:"keep"`
}

PrunePlan is what a prune would do.

type PruneRule added in v0.3.0

type PruneRule struct {
	Keep      int
	OlderThan time.Time
	Match     *regexp.Regexp // nil: every tag
}

PruneRule says which tags may go: the newest Keep of the matching tags stay, and with OlderThan set only tags built before it go. "latest" and tags with no build date always stay.

func (PruneRule) Plan added in v0.3.0

func (r PruneRule) Plan(tags []TagInfo) PrunePlan

Plan decides what to delete. Deleting by digest removes every tag on that image, so an image any kept tag points at is never deleted.

type TLS added in v0.3.0

type TLS struct {
	Plain      bool           // plain HTTP (a local registry:2)
	SkipVerify bool           // HTTPS without checking the certificate
	RootCAs    *x509.CertPool // the CAs to trust in place of the system's (nil = system)
}

TLS says how a client talks to its registry. The zero value is HTTPS with the certificate checked against the system's CAs.

type TagInfo added in v0.3.0

type TagInfo struct {
	Tag     string
	Digest  string
	Created time.Time // zero: unknown (an index without one config)
}

TagInfo is one tag with the image it points at and when that was built.

Jump to

Keyboard shortcuts

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