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
- func CAPool(pem []byte) (*x509.CertPool, error)
- func CheckRef(ref string) error
- func CheckRepo(repo string) error
- type Client
- func (c *Client) ACRLogin(ctx context.Context, aadToken, tenant string) error
- func (c *Client) Catalog(ctx context.Context, limit int) ([]string, error)
- func (c *Client) CheckedTLS() bool
- func (c *Client) Delete(ctx context.Context, repo, digest string) error
- func (c *Client) Digest(ctx context.Context, repo, ref string) (string, error)
- func (c *Client) Do(ctx context.Context, method, path string, q url.Values, accept string) (*http.Response, error)
- func (c *Client) DockerHub() bool
- func (c *Client) Inspect(ctx context.Context, repo, ref string) (*Manifest, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Repo(repo string) string
- func (c *Client) Send(ctx context.Context, method string, u *url.URL, accept, contentType string, ...) (*http.Response, error)
- func (c *Client) Tags(ctx context.Context, repo string, limit int) ([]string, error)
- type CopyResult
- type Error
- type Manifest
- type PruneImage
- type PruneKeep
- type PrunePlan
- type PruneRule
- type TLS
- type TagInfo
Constants ¶
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.
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
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).
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
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) CheckedTLS ¶ added in v0.9.0
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) 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) Repo ¶ added in v0.13.0
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.
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.
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 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
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.
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.