registry

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package registry talks to OCI registries: resolving references, pulling manifests and layers, and exporting an unpacked root filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Username     string
	Password     string
	PasswordFile string

	// CredentialHelper names a docker-credential-<name> program on the
	// daemon's PATH, which gives the credentials each time they are needed.
	CredentialHelper string
}

Auth is how to log in to one registry: with a username and a password, given or read from a file, or through a credential helper.

type Client

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

Client resolves image references against their registries, and pulls images through a layer cache: an OCI layout on disk, in which each image is named by its manifest digest's hex. It is safe for concurrent use.

func NewClient

func NewClient(dataDir string, opts ...Option) (*Client, error)

NewClient returns a client whose layer cache is under dataDir.

func (*Client) CacheSize

func (c *Client) CacheSize() (int64, error)

CacheSize returns what the layer cache occupies on disk.

func (*Client) PruneCache

func (c *Client) PruneCache(keep []string) (int64, error)

PruneCache drops every image from the layer cache but those keep names, by their manifest digests' hex, with the blobs no image left uses, and returns the bytes reclaimed.

func (*Client) PullAndExport

func (c *Client) PullAndExport(
	ctx context.Context, imageRef, digest, exportDir string, onProgress ProgressFunc,
) (*Metadata, error)

PullAndExport pulls the image with the manifest digest from imageRef's repository into the layer cache, unless it is there already, and unpacks its root filesystem into exportDir. It reports progress to onProgress, which may be nil, and returns the image's metadata.

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, ref *reference.Ref) (string, error)

Resolve returns the manifest digest a reference currently points to. It implements reference.Resolver.

type CredentialsError

type CredentialsError struct {
	Registry string
	Err      error
}

CredentialsError reports that the credentials configured for a registry could not be had: a password file that cannot be read, or a credential helper that fails.

func (*CredentialsError) Error

func (e *CredentialsError) Error() string

Error implements error.

func (*CredentialsError) Unwrap

func (e *CredentialsError) Unwrap() error

Unwrap returns the cause.

type Keychain added in v0.4.0

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

Keychain gives each registry the credentials configured for it, by host, and every other registry none: an image there is pulled anonymously. The zero Keychain pulls every image anonymously. It implements authn.Keychain.

func NewKeychain

func NewKeychain(auths map[string]Auth) Keychain

NewKeychain returns a keychain of the credentials in auths, keyed by registry host. Docker Hub may be named docker.io.

func (Keychain) Resolve added in v0.4.0

func (k Keychain) Resolve(resource authn.Resource) (authn.Authenticator, error)

Resolve returns the credentials for a registry. A password file is read each time, so a rotated password is used without a restart.

type Metadata

type Metadata struct {
	Entrypoint []string
	Cmd        []string
	Env        map[string]string
	WorkingDir string

	// User is the image's USER: user, uid, user:group or uid:gid. Empty is
	// root.
	User string

	// HealthCheck is the image's HEALTHCHECK as Docker records it, or nil.
	HealthCheck *gcr.HealthConfig
}

Metadata is the part of an image's configuration an instance runs with.

type Option

type Option func(*Client)

Option configures a Client.

func WithKeychain

func WithKeychain(k authn.Keychain) Option

WithKeychain sets the credentials registries are logged in to with. Without it, every image is pulled anonymously.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger for the client.

type Phase

type Phase string

Phase is the part of a pull that is currently working.

const (
	// PhaseDownloading is fetching layers from the registry, the only part
	// with a byte count worth reporting.
	PhaseDownloading Phase = "downloading"

	// PhaseUnpacking is writing those layers out as a root filesystem.
	PhaseUnpacking Phase = "unpacking"
)

type Progress added in v0.4.0

type Progress struct {
	Phase      Phase
	Downloaded int64
	Total      int64
}

Progress reports how far a pull has got. Downloaded and Total are bytes of compressed layers, and are zero outside PhaseDownloading.

type ProgressFunc added in v0.4.0

type ProgressFunc func(Progress)

ProgressFunc receives a pull's progress. It may be nil, and is called from the goroutine doing the pull, so it should not block for long.

Jump to

Keyboard shortcuts

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