registry

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 29 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 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 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.

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 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) 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.

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) 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.

type Decision

type Decision struct {
	Image
	Expire bool `json:"expire"`
	// InUse images are never expired (a service runs or can roll back to them).
	InUse  bool   `json:"inUse"`
	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.

func Evaluate

func Evaluate(images []Image, rules []Rule, inUse func(digest string) bool, now time.Time) []Decision

Evaluate applies rules (validated) to a repository's images. inUse reports digests that must be kept. Deleting a manifest removes every tag pointing at it, so an image is only expired when all its tags expire.

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"`
}

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"`
}

Image is one tag with its manifest details.

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 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 tags starting with it ("" = every tag).
	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 created 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 it, so a lower-priority rule never expires an image that a higher-priority rule kept. Untagged manifests are always removed by garbage collection.

Jump to

Keyboard shortcuts

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