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
- Variables
- func CompressLayout(dir, ref string) error
- func FreesBytes(ds []Decision) int64
- func IsCacheTag(tag string) bool
- func IsIDTag(tag string) bool
- func IsSystemRepo(repo string) bool
- func Parse(body []byte) ([]store.RegistryEvent, error)
- func ParseRef(image string, hosts []string) (repo, tag, digest string, ok bool)
- func ValidateRules(rules []Rule) error
- func Verify(ctx context.Context, b *Browser, want []Repository) error
- func VerifyCopy(ctx context.Context, src, dst *Browser) error
- type Access
- type Blob
- type Browser
- func (b *Browser) DeleteRepository(ctx context.Context, repo string) (int, error)
- func (b *Browser) DeleteTag(ctx context.Context, repo, tag string) error
- func (b *Browser) Digest(ctx context.Context, repo, ref string) (string, error)
- func (b *Browser) HasImage(ctx context.Context, repo, ref string) (bool, error)
- func (b *Browser) Images(ctx context.Context, repo string) ([]Image, error)
- func (b *Browser) Inspect(ctx context.Context, repo, tag string) (Inspection, error)
- func (b *Browser) PushLayout(ctx context.Context, repo, tag, dir string) error
- func (b *Browser) Repositories(ctx context.Context) ([]Repository, error)
- func (b *Browser) Retag(ctx context.Context, repo, from, tag string) error
- func (b *Browser) Usage(ctx context.Context) (Usage, error)
- type CopyProgress
- type Decision
- type Descriptor
- type Events
- type Image
- type Inspection
- type Issuer
- type Layer
- type Options
- type PlatformImage
- type RepoUsage
- type Repository
- type Rule
- type Usage
Constants ¶
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" )
const BrowserSubject = "syncloud-controller"
BrowserSubject is the token subject the controller reads the registry as.
const CacheTag = "buildcache"
CacheTag is the tag builds keep their layer cache under.
const EventsRetention = 30 * 24 * time.Hour
EventsRetention is how long individual registry events are kept.
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 ¶
var ErrManifestNotFound = errors.New("not found")
ErrManifestNotFound means the registry has no such repository, tag or blob.
ErrUnavailable means the registry could not be reached.
Functions ¶
func CompressLayout ¶
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
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
IsCacheTag reports the tag of the builders' layer cache.
func IsSystemRepo ¶
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 ¶
ParseRef splits a private-registry image reference into repository, tag and digest. Other images return ok=false.
func ValidateRules ¶
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
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 ¶
ParseScope parses "repository:shop/api:pull,push" (names may contain ':' in the middle only for registry:catalog:*).
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
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 ¶
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
Digest is the manifest digest repo's ref (a tag) points to now.
func (*Browser) Inspect ¶ added in v0.3.1
Inspect reads a tag's manifest, layers and image settings.
func (*Browser) PushLayout ¶
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.
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 ¶
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.
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.
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 ¶
LoadOrCreateIssuer loads the token signing key from dir, creating it once.
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"`
// 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 ¶
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.