Documentation
¶
Overview ¶
Package registry runs the Docker registry's storage (decision 0031): blob upload sessions, manifests and tags, referrers, promotion, multi-arch deletes and tag retention.
Role ¶
artifacts module, core layer: the Docker and OCI registry's writes, which the Docker, OCI and Helm OCI repositories share. A session spans requests and survives a restart: it is a row in the uploads table under Backend, naming the blob store upload it appends to, and its repository, image and user, which alone may continue it. A finished upload, whether chunked, monolithic or mounted from another image, becomes the item <image>/_uploads/sha256__<hex> through the item service (artifacts/core/item), where a manifest push finds it. It imports the Docker format package for the image layout, never an ecosystem http package or the module's adapters (decision 0044, dependency rule 8).
Inputs ¶
- Driving: the Docker registry protocol handlers (uploads, manifests, tags, referrers, deletes), the Docker REST endpoints (promotion and tag deletes), the item handlers, and the garbage collector, which the composition root gives Reap for stale sessions and ExpireUploads for finished uploads no manifest took in time.
- Driven: the metadata store, through Store (the item service's store, item.Store, for items and their properties, with the uploads table), the blob store (platform/blob.Store) whose uploads the sessions append to, and the item service with the format registry (Formats) and the work queue (Work), so every item it writes runs its format's hooks.
Outputs ¶
- Upload sessions (Begin, Status, Append, Finish, Cancel, Upload, Mount) and the upload items they finish; Reap and ExpireUploads for the collector.
- Manifests and tags written, promoted, renamed and removed (Push, Promotion, Rename, Removal), with their parents and platform tags (Parent, PlatformTag), and the referrers of a manifest.
- Errors: ErrUnknown, ErrSamePlace and the rest of the package's sentinels, BlobsUnknownError and SizeMismatchError, which the registry API answers as MANIFEST_BLOB_UNKNOWN and MANIFEST_INVALID.
Invariants ¶
- Backend ("docker") names the sessions' rows in the uploads table, so it is stored and never changes, as are the upload rows' contents and the _uploads item paths.
- One session's requests are serialised in this process; a manifest push is refused when a descriptor's size differs from the stored content's, which a client would otherwise trust (decision 0031).
- Error texts reach clients or logs and stay byte-identical.
References ¶
- Decision 0031: docs/research/decisions/0031-docker-oci-registry.md (protocol and storage layout; line 27, upload sessions and the items they finish).
- Research 23: docs/research/23-docker-oci-registry.md.
- Decision 0039: docs/research/decisions/0039-helm.md (Helm OCI through the Docker registry).
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Dependency rules".
- Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 206 to 207 (core/registry), line 1034 (the mapping row) and rule 2 at lines 35 to 36.
- Plan: docs/implementation/plan.md#p6-dockeroci, #p8-pypi-nuget-helm-terraform-locals and #p9d-modular-monolith-migration, epic ART (https://github.com/weaveplatform/artifactweave/issues/941).
- https://github.com/weaveplatform/artifactweave/issues/1011 and https://github.com/weaveplatform/artifactweave/issues/1088
Status ¶
Implemented P6 to P9c: the registry's uploads, manifests, tags, promotion and retention in P6, and Helm OCI through them in P8. Moved here in P9d.
Testing ¶
- registry_test.go: upload sessions across requests and restarts, mounts, reaping and expiry.
- manifests_test.go, sizes_test.go, index_test.go, indexes_test.go and platforms_test.go: manifest pushes, size checks, image indexes and their platforms.
- promote_test.go, deletes_test.go and retention_test.go: promotion, deletes and tag retention; helm_test.go: a Helm chart pushed as an OCI artifact (testdata/helm, kept byte for byte by its .gitattributes).
- format_test.go: every write through the format hooks; fault_test.go, retention_fault_test.go and twins_fault_test.go: store failures.
Index ¶
- Constants
- Variables
- type BlobsUnknownError
- type Owner
- type Parent
- type PlatformTag
- type Promotion
- type Push
- type Removal
- type Rename
- type Service
- func (s *Service) Append(ctx context.Context, o Owner, id string, offset int64, body io.Reader) (int64, error)
- func (s *Service) Begin(ctx context.Context, o Owner) (string, error)
- func (s *Service) Cancel(ctx context.Context, o Owner, id string) error
- func (s *Service) DeleteManifest(ctx context.Context, o Owner, hex string) error
- func (s *Service) DeleteMultiArch(ctx context.Context, o Owner, tag string) ([]string, error)
- func (s *Service) DeleteTag(ctx context.Context, o Owner, tag string) error
- func (s *Service) ExpireUploads(ctx context.Context, before time.Time) (int, error)
- func (s *Service) Finish(ctx context.Context, o Owner, id string, offset int64, body io.Reader, ...) (model.Item, error)
- func (s *Service) Mount(ctx context.Context, o Owner, src repo.Config, srcName, hex string) (model.Item, bool, error)
- func (s *Service) ParentManifests(ctx context.Context, o Owner, tag string) ([]Parent, error)
- func (s *Service) Promote(ctx context.Context, p Promotion) error
- func (s *Service) PromotedTags(ctx context.Context, o Owner, tag string) ([]string, error)
- func (s *Service) PutManifest(ctx context.Context, p Push) error
- func (s *Service) Reap(ctx context.Context, u session.Upload) error
- func (s *Service) Referrers(ctx context.Context, o Owner, subject, artifactType string) ([]layout.Descriptor, error)
- func (s *Service) RemoveTag(ctx context.Context, o Owner, tag string, r Removal) error
- func (s *Service) Replaces(ctx context.Context, o Owner, folder, hex string) (bool, error)
- func (s *Service) Status(ctx context.Context, o Owner, id string) (int64, error)
- func (s *Service) TagManifest(ctx context.Context, o Owner, tag string) (model.Item, error)
- func (s *Service) UnreferencedPlatforms(ctx context.Context, o Owner, folder string) ([]string, error)
- func (s *Service) Upload(ctx context.Context, o Owner, body io.Reader, hex string) (model.Item, error)
- type SizeMismatch
- type SizeMismatchError
- type Store
Constants ¶
const Backend = "docker"
Backend names registry sessions in the uploads table, so the garbage collector hands them to Reap rather than to the blob store.
Variables ¶
var ( // ErrUnknown is a session that never existed, has ended, or belongs to // another repository, image or user: BLOB_UPLOAD_UNKNOWN. ErrUnknown = errors.New("registry: unknown upload session") // ErrOffset is a chunk that does not start where the session ends. // Nothing was read; the client resumes from the session's size. ErrOffset = errors.New("registry: chunk out of order") // ErrDigest is content whose SHA-256 is not the declared digest. The // session, if any, is discarded. ErrDigest = errors.New("registry: digest mismatch") )
var ErrSamePlace = errors.New("registry: the source and the target are the same")
ErrSamePlace is a promotion onto itself: the same repository, image and tag.
Functions ¶
This section is empty.
Types ¶
type BlobsUnknownError ¶
type BlobsUnknownError struct {
Digests []string
}
BlobsUnknownError is a manifest that references blobs the image does not hold: MANIFEST_BLOB_UNKNOWN, once for each digest.
func (*BlobsUnknownError) Error ¶
func (e *BlobsUnknownError) Error() string
Error names every unknown digest, in the order the manifest lists them. The Docker registry API answers with one MANIFEST_BLOB_UNKNOWN for each of Digests rather than with this text.
type Owner ¶
type Owner struct {
Repo repo.Config
// Name is the image inside Repo.
Name string
// By is the user that opened it.
By string
}
Owner is who a session belongs to.
type Parent ¶
Parent is a manifest list or image index that names a given manifest, with the tags it is pushed under.
type PlatformTag ¶
PlatformTag is a descriptive tag a list push adds for one of its platforms (decision 0031), and the SHA-256 of the platform manifest it holds.
func PlatformTags ¶
func PlatformTags(m layout.Manifest, tag string) []PlatformTag
PlatformTags returns the descriptive tags that the list m adds when it is pushed to tag: <tag>-<os>-<architecture> for each entry that names a platform, as 7.x adds them from 7.21.2 (docker-repositories, "Multi-Architecture Tagging"; RTFACT-26257). A variant is not part of the name, which the documentation gives as the os and architecture alone, so entries that differ only in variant share one tag [I]. Each name is returned once, holding the last entry that gives it, as tagging the entries in order would leave it [I]; a name outside the tag grammar, as when tag is near the 128-character limit, is left out. An image manifest, and an entry with no platform or a digest under another algorithm, give none.
type Promotion ¶
Promotion is a JFrog Docker promote (decision 0031): tags of From's image copied or moved to To's image, which may be in another repository of the same package type, under another name. To.By is who promotes.
type Push ¶
type Push struct {
Owner
Manifest layout.Manifest
// Body is the manifest exactly as the client sent it, which jf reads
// back to take the config's digest (research 23, 5.1).
Body []byte
// Folders are where it is stored, each a direct child of the image: a
// tag, or the digest folder with any tags pushed alongside it.
Folders []string
}
Push is a manifest to store in an image.
type Removal ¶
type Removal struct {
// Platforms removes, with a manifest list or image index, its
// descriptive platform tags and the digest folders of its platform
// manifests that no list left in the image names (decision 0031).
Platforms bool
// Retained removes the tag's previous manifests that Tag Retention kept.
Retained bool
// Twin removes the tag's digest twin when nothing else keeps it
// (loneTwin).
Twin bool
}
Removal says what goes with a tag that RemoveTag removes.
type Service ¶
type Service struct {
Store Store
Blobs blob.Store
// Now supplies the time; nil means time.Now.
Now func() time.Time
// Formats and Work reach the item service's format hooks (decision
// 0032); nil means the generic handler and the store's queue.
Formats format.Registry
Work item.Enqueuer
// contains filtered or unexported fields
}
Service runs registry uploads over a metadata store and its blob store.
func (*Service) Append ¶
func (s *Service) Append( ctx context.Context, o Owner, id string, offset int64, body io.Reader, ) (int64, error)
Append adds body to session id and returns the session's size. offset is where the client says the chunk starts, or negative when it sent no range; a chunk that does not start at the session's end is refused with ErrOffset before any of it is read. The body streams through to the blob store, so a layer is never held in memory.
func (*Service) DeleteManifest ¶
DeleteManifest removes every folder of o's image that holds the manifest whose SHA-256 is hex, its tag folders and its digest folder, in one transaction, so that neither the digest nor a tag that named it answers afterwards. An index's platform manifests stay: they are manifests of their own. kernel.ErrNotFound when no folder holds it.
func (*Service) DeleteMultiArch ¶
DeleteMultiArch removes the tag folder of o's image together with its descriptive platform tags and the platform manifests UnreferencedPlatforms names, in one transaction, sending them to the trash can when it is on (decision 0010), by o.By: 7.x deletes the tag "with all of their sub-architectures". It returns the folders removed, the tag first; kernel.ErrNotFound when the image has no such tag. The caller has checked Delete on the image, which covers its digest folders. DELETE /artifactory/api/docker/<repo>/v2/delete (#226) calls it.
func (*Service) DeleteTag ¶
DeleteTag removes the tag folder of o's image with everything in it, as RemoveTag does with nothing else: its files go to the trash can when it is on and the package index follows (decisions 0018 and 0031). The manifest stays readable by digest from any other folder holding it. kernel.ErrNotFound when the folder holds no manifest.
func (*Service) ExpireUploads ¶
ExpireUploads removes the finished uploads last written before before from every repository that holds images, and returns how many it removed. A manifest push links the blobs it references into its own folder, so an upload no manifest took by then was abandoned (decision 0031). They bypass the trash can: nobody deployed them as files.
func (*Service) Finish ¶
func (s *Service) Finish( ctx context.Context, o Owner, id string, offset int64, body io.Reader, hex string, ) (model.Item, error)
Finish appends the last chunk, if body holds one, verifies the content against the SHA-256 hex, and stores it as the image's finished upload. A mismatch discards the session (ErrDigest).
func (*Service) Mount ¶
func (s *Service) Mount( ctx context.Context, o Owner, src repo.Config, srcName, hex string, ) (model.Item, bool, error)
Mount links the blob hex from the image srcName in src into o's image as a finished upload, by reference to the stored content: no bytes are copied. ok is false when the source image does not hold the blob, or its content went meanwhile, and the registry then opens a session instead. The caller checks that o may read the source.
func (*Service) ParentManifests ¶
ParentManifests returns the manifest lists and image indexes of o's image that name the manifest tag holds (decision 0031), each once with the tags it sits under, ordered by digest. A push stores a list only where its platforms already are, so the image is all there is to search. kernel.ErrNotFound when tag holds no manifest.
func (*Service) Promote ¶
Promote lands each of p's tags in p.To through the item service, so the trash can, the package index and events follow as for any copy or move; the caller has checked permissions. A tag folder lands with its blobs linked, never copied as bytes, and a manifest list takes its platform manifests' digest folders along. A target tag holding another manifest is replaced as a push replaces it, keeping it under Tag Retention, and the target image's tag limits apply afterwards. Without p.Copy each tag folder moves, keeping its history, and the platform manifests nothing left in the source image names go too. All of it is one transaction.
func (*Service) PromotedTags ¶
PromotedTags returns the tags a promotion of o's image takes: tag alone, or every tag of the image when tag is empty. kernel.ErrNotFound when the image holds no tag, or tag names no folder holding a manifest.
func (*Service) PutManifest ¶
PutManifest stores p's manifest in each of its folders (decision 0031): the exact bytes as manifest.json, or list.manifest.json for an index or manifest list, with the properties jf and Docker clients read, and an image's config and layers linked beside it by reference to their stored content, never copied. Every blob an image needs, and every manifest an index lists, must already be in the image (a *BlobsUnknownError otherwise); a subject need not be. A folder holding the same manifest is left as it is; one holding another manifest, or anything else, is replaced, keeping a tag's previous manifest under Tag Retention. A list pushed to a tag also gets its descriptive platform tags (PlatformTags). The repository's tag limits then apply to the image, all in one transaction.
func (*Service) Reap ¶
Reap discards a stale session for the garbage collector: its blob store upload, when that still exists, then its row.
func (*Service) Referrers ¶
func (s *Service) Referrers( ctx context.Context, o Owner, subject, artifactType string, ) ([]layout.Descriptor, error)
Referrers returns the descriptors of the manifests in o's image whose subject is the digest subject, of artifactType alone when it is set: what GET .../referrers/<digest> lists (decision 0031). Each manifest appears once whichever folders hold it, sorted by digest, with the media type it was pushed with, its size, its artifactType and its annotations. None is an empty list, never an error: the referrers API answers no 404.
func (*Service) RemoveTag ¶
RemoveTag removes the tag folder of o's image through the item service: its files go to the trash can when it is on, and the package index (decision 0018) drops the version in the same transaction, so a caller keeps nothing in step itself. A manifest DELETE by tag removes with no Removal, the multi-architecture delete with Platforms, and Max Unique Tags with all three. kernel.ErrNotFound when the image has no such tag.
func (*Service) Replaces ¶
Replaces reports whether storing the manifest whose SHA-256 is hex in folder of o's image would replace what the folder holds: a different manifest, or files of any kind. Replacing needs Delete as well as Deploy (DV-035); pushing the manifest a folder already holds changes nothing, so a client repeating a push needs no more than Deploy.
func (*Service) TagManifest ¶
TagManifest is the manifest file tag holds in o's image; kernel.ErrNotFound for a reserved name, a digest folder or a folder holding none.
func (*Service) UnreferencedPlatforms ¶
func (s *Service) UnreferencedPlatforms( ctx context.Context, o Owner, folder string, ) ([]string, error)
UnreferencedPlatforms returns the digest folders, below o's image, of the platform manifests that the list manifest in folder lists and that no other tag folder holds and no other index in the image lists: what deleting the multi-architecture tag also removes, as Artifactory does from 7.118.0 (decision 0031), and what tag retention removes with a list manifest. The list's own descriptive tags (PlatformTags) go with it, so they keep nothing. A folder holding an image manifest, or nothing, has none. The list's own digest folder, when it was pushed by digest too, is another index that lists them, so its platforms stay.
type SizeMismatch ¶
SizeMismatch is one descriptor whose size differs from the stored content.
type SizeMismatchError ¶
type SizeMismatchError struct {
Mismatches []SizeMismatch
}
SizeMismatchError is a manifest whose descriptors give sizes other than the stored content's: MANIFEST_INVALID, once for each. Docker's reference registry checks only that the content exists, but a client trusting the size reads past or stops short of it (the image specification: such content "SHOULD NOT be trusted"), so the push is refused (decision 0031).
func (*SizeMismatchError) Error ¶
func (e *SizeMismatchError) Error() string
Error names every mismatched descriptor with its declared and stored sizes, in the order the manifest lists them. The Docker registry API answers with one MANIFEST_INVALID for each of Mismatches rather than with this text.
type Store ¶
type Store interface {
item.Store
Uploads() session.UploadStore
}
Store is what registry uploads read and write: the item service's store, which every manifest and blob write goes through (item.Store), with the upload sessions a chunked upload keeps between requests. Each composite store in app is a Store.