registry

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 31 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 issues tokens for the private Docker registry (§5.9) using the Docker registry token protocol: clients get a short-lived ES256 JWT from the controller, and the registry verifies it against the issuer certificate.

Index

Constants

View Source
const (
	// Service is the registry's token "service" name (aud claim).
	Service = "syncloud-registry"
	// IssuerName is the iss claim the registry expects.
	IssuerName = "syncloud"
	// TokenTTL keeps tokens short-lived; Docker fetches new ones as needed.
	TokenTTL = 5 * time.Minute

	CertFile = "registry-token.crt"
)
View Source
const BrowserSubject = "syncloud-controller"

BrowserSubject is the token subject the controller reads the registry as.

View Source
const CacheTag = "buildcache"

CacheTag is the tag builds keep their layer cache under.

View Source
const EventsRetention = 30 * 24 * time.Hour

EventsRetention is how long individual registry events are kept.

View Source
const SystemProject = "syncloud-system"

SystemProject holds the platform's own images in the built-in registry (the release's PostgreSQL images). No project may take the name, and its images are neither expired nor deleted by hand.

Variables

View Source
var ErrManifestNotFound = errors.New("not found")

ErrManifestNotFound means the registry has no such repository, tag or blob.

View Source
var ErrUnavailable = errors.New("registry unavailable")

ErrUnavailable means the registry could not be reached.

Functions

func CompressLayout

func CompressLayout(dir, ref string) error

CompressLayout rewrites a layout from `docker save` so its layers are gzip-compressed (registries and nodes then move a third of the bytes), and names the image ref. The config, and so the image ID, is unchanged.

func FreesBytes added in v0.3.1

func FreesBytes(ds []Decision) int64

FreesBytes estimates what deleting the expiring images frees: layers no kept image of the repository shares. Cache layers and other repositories are not considered, so the real figure can be a little higher.

func IsCacheTag added in v0.3.1

func IsCacheTag(tag string) bool

IsCacheTag reports the tag of the builders' layer cache.

func IsIDTag added in v0.3.1

func IsIDTag(tag string) bool

IsIDTag reports a commit-id tag such as the ones builds push.

func IsSystemRepo

func IsSystemRepo(repo string) bool

IsSystemRepo reports a repository of the platform's own images.

func Parse

func Parse(body []byte) ([]store.RegistryEvent, error)

Parse turns a notification envelope into the events worth keeping.

func ParseRef

func ParseRef(image string, hosts []string) (repo, tag, digest string, ok bool)

ParseRef splits a private-registry image reference into repository, tag and digest. Other images return ok=false.

func ValidateRules

func ValidateRules(rules []Rule) error

ValidateRules checks rules and sorts them by priority.

func Verify added in v0.1.9

func Verify(ctx context.Context, b *Browser, want []Repository) error

Verify checks that b lists every repository of want with at least as many tags.

func VerifyCopy added in v0.1.9

func VerifyCopy(ctx context.Context, src, dst *Browser) error

VerifyCopy checks that dst lists every repository of src with at least as many tags. dst's catalog is read the way the registry walks its storage, so an S3 provider that lists objects wrongly is caught here, before the registry switches to it.

Types

type Access

type Access struct {
	Type    string   `json:"type"`
	Name    string   `json:"name"`
	Actions []string `json:"actions"`
}

Access is one granted scope, e.g. {repository, shop/api, [pull push]}.

func ParseScope

func ParseScope(scope string) (Access, error)

ParseScope parses "repository:shop/api:pull,push" (names may contain ':' in the middle only for registry:catalog:*).

type Blob added in v0.3.1

type Blob struct {
	Digest string `json:"digest"`
	Size   int64  `json:"size"`
}

Blob is a content-addressed object of the registry.

type Browser

type Browser struct {
	URL    string // e.g. http://127.0.0.1:5000
	Issuer *Issuer
	HTTP   *http.Client
}

Browser reads the registry's contents for the dashboard (§5.10), with tokens the controller issues to itself.

func (*Browser) DeleteRepository added in v0.3.4

func (b *Browser) DeleteRepository(ctx context.Context, repo string) (int, error)

DeleteRepository removes every tag of a repository, the build cache included, and returns how many tags it removed. Tags sharing a digest go with the first one deleted, so a tag already gone is not an error. Layers stay on disk until registry garbage collection. A tag that cannot be deleted stops the run: the repository is only reported empty when it is.

func (*Browser) DeleteTag

func (b *Browser) DeleteTag(ctx context.Context, repo, tag string) error

DeleteTag removes a tag's manifest. Other tags pointing at the same digest go with it; disk space is reclaimed by registry garbage collection. The delete is checked: the image must be gone afterwards.

func (*Browser) Digest added in v0.1.7

func (b *Browser) Digest(ctx context.Context, repo, ref string) (string, error)

Digest is the manifest digest repo's ref (a tag) points to now.

func (*Browser) HasImage

func (b *Browser) HasImage(ctx context.Context, repo, ref string) (bool, error)

HasImage reports whether repo has a manifest for ref (a tag or digest).

func (*Browser) Images

func (b *Browser) Images(ctx context.Context, repo string) ([]Image, error)

Images lists a repository's tags, newest first.

func (*Browser) Inspect added in v0.3.1

func (b *Browser) Inspect(ctx context.Context, repo, tag string) (Inspection, error)

Inspect reads a tag's manifest, layers and image settings.

func (*Browser) PushLayout

func (b *Browser) PushLayout(ctx context.Context, repo, tag, dir string) error

PushLayout uploads a layout's image to repo:tag. Blobs the registry has already are skipped, so pushing again is cheap.

func (*Browser) Repositories

func (b *Browser) Repositories(ctx context.Context) ([]Repository, error)

Repositories lists repositories with their tag counts.

func (*Browser) Retag added in v0.3.1

func (b *Browser) Retag(ctx context.Context, repo, from, tag string) error

Retag points tag at the manifest from (a tag or digest) names: the same image under another name, nothing copied.

func (*Browser) Usage added in v0.3.1

func (b *Browser) Usage(ctx context.Context) (Usage, error)

Usage walks every tag of every repository.

type CopyProgress added in v0.1.9

type CopyProgress struct {
	Repositories     int    `json:"repositories"`
	RepositoriesDone int    `json:"repositoriesDone"`
	Images           int    `json:"images"`
	ImagesDone       int    `json:"imagesDone"`
	Blobs            int    `json:"blobs"`   // blobs uploaded or mounted
	Skipped          int    `json:"skipped"` // blobs the target had already
	Bytes            int64  `json:"bytes"`   // bytes uploaded
	Current          string `json:"current,omitempty"`
}

CopyProgress describes a copy between two registries (Phase 19).

func Copy added in v0.1.9

func Copy(ctx context.Context, src, dst *Browser, progress func(CopyProgress)) (CopyProgress, error)

Copy copies every tagged image of src into dst: manifests byte for byte (digests stay the same), index children before their index, blobs streamed. Blobs dst has are skipped and blobs already copied to another repository are cross-mounted, so a failed copy resumes when retried. Untagged manifests are not copied. progress is called after each image.

type Decision

type Decision struct {
	Image           // Tag is the primary tag; the others are in Tags
	Tags   []string `json:"tags"`
	Names  []string `json:"names"` // names the image answers to besides its tags (the branch a commit was built from)
	Expire bool     `json:"expire"`
	// InUse images are never expired (a service runs or can roll back to them).
	InUse bool `json:"inUse"`
	// WouldExpire marks an image the rules selected but something kept: in
	// use by a service.
	WouldExpire bool `json:"wouldExpire"`
	// Cache marks the builders' layer cache, which rules never touch.
	Cache  bool   `json:"cache"`
	Rule   int    `json:"rule"` // priority of the deciding rule; 0 = no rule matched
	Reason string `json:"reason"`
}

Decision says what a policy does with one image. An image is one manifest digest with every tag pointing at it: a build pushes a commit id and a branch tag to the same image, and the two are judged together.

func Evaluate

func Evaluate(images []Image, rules []Rule, opt Options, now time.Time) []Decision

Evaluate applies rules (validated) to a repository's images. Rules see whole images: an image is selected by the first rule whose prefix matches any of its names, counts once towards keepLast however many tags it has, and goes with all of them. Newest first; images without a time count as oldest for keepLast but are never expired by age.

type Descriptor

type Descriptor struct {
	MediaType   string            `json:"mediaType"`
	Digest      string            `json:"digest"`
	Size        int64             `json:"size"`
	Annotations map[string]string `json:"annotations,omitempty"`
	Platform    map[string]any    `json:"platform,omitempty"`
	URLs        []string          `json:"urls,omitempty"`
}

Descriptor points at a blob of a layout.

type Events

type Events struct {
	Store       *store.Store
	Token       string
	TokenHeader string
	Log         *slog.Logger
	// OnEvent is called after new events were stored (dashboard refresh).
	OnEvent func(repos []string)
}

Events receives the registry's notification webhooks (§5.9) and records manifest pushes, pulls and deletes, which distribution does not track itself: they give last-pulled times, pull counts and an activity feed.

func (*Events) Prune

func (h *Events) Prune(ctx context.Context)

Prune drops old events once an hour.

func (*Events) ServeHTTP

func (h *Events) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Image

type Image struct {
	Tag       string     `json:"tag"`
	Digest    string     `json:"digest"`
	MediaType string     `json:"mediaType"`
	SizeBytes int64      `json:"sizeBytes"` // compressed layers + config of the first platform
	Platforms []string   `json:"platforms"`
	Created   *time.Time `json:"created"`
	// PushedAt is when the registry last received the image (set by callers
	// from the push events; nil when unknown).
	PushedAt *time.Time `json:"pushedAt"`
	// UniqueBytes is what deleting the tag would free within the repository:
	// layers no other image of it uses.
	UniqueBytes int64 `json:"uniqueBytes"`
	// Cache marks the builders' layer cache, not a runnable image.
	Cache bool `json:"cache"`
	// contains filtered or unexported fields
}

Image is one tag with its manifest details.

func (Image) Stamp added in v0.3.1

func (i Image) Stamp() *time.Time

Stamp is the time an image's age counts from: when it was last pushed here, else when it was built. Pushing an old image into the registry must not make it look old.

type Inspection added in v0.3.1

type Inspection struct {
	Image
	Layers     []Layer           `json:"layers"`
	Platform   string            `json:"platform"` // the one Layers and the settings below describe
	Variants   []PlatformImage   `json:"variants"`
	Entrypoint []string          `json:"entrypoint"`
	Cmd        []string          `json:"cmd"`
	WorkingDir string            `json:"workingDir"`
	User       string            `json:"user"`
	Ports      []string          `json:"ports"`
	EnvNames   []string          `json:"envNames"` // names only: values may hold secrets
	Labels     map[string]string `json:"labels"`
	// TotalBytes covers every platform and attestation behind the tag.
	TotalBytes int64 `json:"totalBytes"`
}

Inspection describes an image in depth.

type Issuer

type Issuer struct {

	// CertPath is the issuer certificate mounted into the registry container.
	CertPath string
	// contains filtered or unexported fields
}

func LoadOrCreateIssuer

func LoadOrCreateIssuer(dir string) (*Issuer, error)

LoadOrCreateIssuer loads the token signing key from dir, creating it once.

func (*Issuer) Issue

func (is *Issuer) Issue(subject string, access []Access, now time.Time) (string, error)

Issue returns a signed token for subject with the given access.

func (*Issuer) IssueTTL

func (is *Issuer) IssueTTL(subject string, access []Access, now time.Time, ttl time.Duration) (string, error)

IssueTTL is Issue with a custom lifetime (node pull tokens outlive a docker login token because large pulls take a while).

type Layer added in v0.3.1

type Layer struct {
	Digest    string `json:"digest"`
	Size      int64  `json:"size"`
	MediaType string `json:"mediaType"`
	Command   string `json:"command,omitempty"`
}

Layer is one layer of an image, with the Dockerfile step that made it when the image's history records it.

type Options added in v0.3.1

type Options struct {
	// InUse reports digests that must be kept.
	InUse func(digest string) bool
	// Lineage returns extra names a tag answers to: an old image keeps only
	// its commit-id tag, which says nothing about the branch it came from.
	Lineage func(tag string) []string
}

Options tune an evaluation.

type PlatformImage added in v0.3.1

type PlatformImage struct {
	Platform string `json:"platform"`
	Digest   string `json:"digest"`
	Size     int64  `json:"sizeBytes"`
}

PlatformImage is one platform of a multi-platform image.

type RepoUsage added in v0.3.1

type RepoUsage struct {
	Name   string `json:"name"`
	System bool   `json:"system"` // the platform's own images
	Images int    `json:"images"` // distinct manifests behind the tags
	Tags   int    `json:"tags"`
	// Bytes counts each layer once, however many images use it.
	Bytes int64 `json:"bytes"`
	// UniqueBytes are layers no other repository uses; SharedBytes the rest.
	UniqueBytes int64 `json:"uniqueBytes"`
	SharedBytes int64 `json:"sharedBytes"`
	// CacheBytes is the part of Bytes only the builders' layer cache holds.
	CacheBytes int64 `json:"cacheBytes"`
}

RepoUsage is what one repository holds in the registry's storage.

type Repository

type Repository struct {
	Name string `json:"name"`
	Tags int    `json:"tags"`
}

Repository is one image repository.

type Rule

type Rule struct {
	Priority    int    `json:"priority"`
	Description string `json:"description,omitempty"`
	// TagPrefix selects images with a name starting with it ("" = every image).
	TagPrefix string `json:"tagPrefix"`
	// Exactly one of the two:
	KeepLast      int `json:"keepLast,omitempty"`      // keep the newest N, expire the rest
	OlderThanDays int `json:"olderThanDays,omitempty"` // expire images last pushed (else built) more than N days ago
}

Rule is one lifecycle rule (§5.10). Rules are applied in priority order (lowest first); an image belongs to the first rule whose tag prefix matches one of its names (any of its tags, or the branch it was built from), so a lower-priority rule never expires an image that a higher-priority rule kept. Untagged manifests are always removed by garbage collection.

type Usage added in v0.3.1

type Usage struct {
	Repositories []RepoUsage `json:"repositories"`
	// ReferencedBytes counts every layer reachable from a tag once; the
	// registry deduplicates layers across repositories.
	ReferencedBytes int64 `json:"referencedBytes"`
	CacheBytes      int64 `json:"cacheBytes"`
}

Usage is the registry's content measured through its API.

Jump to

Keyboard shortcuts

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