Documentation
¶
Overview ¶
Package ar emulates Artifact Registry (SRS 5.3): the artifactregistry v1 control plane over gRPC and REST on the gateway, and an OCI Distribution v1.1 registry on its own port (default 5000).
Control plane ¶
Repositories (FR-AR-001) of format DOCKER can be created, read, listed, patched and deleted in every Artifact Registry location; create and delete return google.longrunning operations (internal/lro). Besides STANDARD_REPOSITORY, the REMOTE_REPOSITORY (Docker Hub or a custom registry, pulled through a cache) and VIRTUAL_REPOSITORY (members by upstream policy priority) modes are served (FR-AR-006, remote.go). Other formats return UNIMPLEMENTED. Packages, versions, tags and dockerImages (FR-AR-004) are views derived from the registry contents. REST is served by transcoding the google.api.http annotations of the generated descriptors onto the same gRPC implementation, so both surfaces behave identically.
Registry image names ¶
The registry accepts three spellings of an image name, so that docker, crane, ko and containerd work with nothing but a host change:
- Host mode: the request Host is "LOCATION-docker.pkg.dev" and the path is /v2/PROJECT/REPO/IMAGE[/...]. The location comes from the host.
- Location in the path: /v2/LOCATION-docker.pkg.dev/PROJECT/REPO/IMAGE, e.g. "localhost:5000/us-docker.pkg.dev/p/r/app". This keeps the real image reference intact after a registry-host prefix and is unambiguous.
- Plain port: /v2/PROJECT/REPO/IMAGE, e.g. "localhost:5000/p/r/app". The repository is found by project and repository ID across locations; if the same ID exists in several locations the request fails with NAME_INVALID naming them, and the caller must use one of the forms above.
In every form the OCI repository name used for blob links, uploads, mounts and tags is PROJECT/REPO/IMAGE within the resolved repository, and the AR API reports image URIs as LOCATION-docker.pkg.dev/PROJECT/REPO/IMAGE.
Public registry mirror (FR-GKE-006) ¶
The registry also mirrors public registries for GKE nodes: containerd mirror requests (?ns=docker.io) and the path form REGISTRY/docker.io/library/busybox are pulled through a persistent, digest-verified cache that keeps working offline (mirror.go, pullthrough.go, upstream.go). RegistriesYAML renders the k3s node configuration (registries.go).
Registry auth (FR-AR-003) ¶
Clients are challenged with "WWW-Authenticate: Bearer realm=<host>/v2/token" like the real service. The token endpoint and every registry request accept Basic credentials "oauth2accesstoken:<emulator access token>" (also the "_token" and "_dcgcloud_token" user names) and "_json_key:<service account key JSON>" (verified against the iam service's public keys), and Bearer emulator tokens. Anonymous access is allowed when IAM is off or in audit mode; in enforce mode credentials are required and artifactregistry.repositories.downloadArtifacts / uploadArtifacts / deleteArtifacts are checked on the repository. The --ar-bind listeners (lan.go) serve TLS and always require credentials.
Index ¶
- Variables
- func New(env *emu.Env) emu.Service
- func RegistriesYAML(registryAddr string, locations []string, auth ...RegistryAuth) []byte
- type RegistryAuth
- type Service
- func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error
- func (s *Service) EnvVars(gw string, endpoints map[string]string) map[string]string
- func (s *Service) ExportSeed(ctx context.Context) (any, error)
- func (s *Service) IsStoreCache(ns, key string) bool
- func (s *Service) LANHandler() http.Handler
- func (s *Service) MirrorHosts() []string
- func (s *Service) Name() string
- func (s *Service) Operations() []emu.OperationInfo
- func (s *Service) Ready() error
- func (s *Service) Register(r emu.Router) error
- func (s *Service) RegistryAddr() string
- func (s *Service) Reset(ctx context.Context) error
- func (s *Service) ResourceCounts() map[string]int
- func (s *Service) Restore(ctx context.Context, dir string) error
- func (s *Service) SetMirrorTagTTL(d time.Duration)
- func (s *Service) SetUpstream(host, baseURL string)
- func (s *Service) Snapshot(ctx context.Context, dir string) error
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var DefaultMirrorHosts = []string{
"docker.io",
"registry.k8s.io",
"ghcr.io",
"quay.io",
"gcr.io",
"mirror.gcr.io",
}
DefaultMirrorHosts are the public registries GKE nodes reach through the emulator, as real nodes do through Private Google Access.
Functions ¶
func RegistriesYAML ¶
func RegistriesYAML(registryAddr string, locations []string, auth ...RegistryAuth) []byte
RegistriesYAML returns a k3s registries.yaml routing pulls for every Artifact Registry location in locations (all locations when empty), the DefaultMirrorHosts and any other registry ("*") to the registry at registryAddr (host:port, plain HTTP). The first auth, if any, is configured for registryAddr.
Types ¶
type RegistryAuth ¶
RegistryAuth is the credential a node presents to the registry, e.g. Username "oauth2accesstoken" with an emulator access token, or "_json_key" with a service account key (FR-AR-003).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the Artifact Registry service module.
func (*Service) ApplySeed ¶
ApplySeed creates (or updates the description and labels of) the seeded repositories. It is idempotent.
func (*Service) ExportSeed ¶ added in v0.6.0
ExportSeed writes the repositories back as the "ar" section (FR-CORE-013), ordered by project, location and ID. Images and their manifests and blobs are not exported: the seed file cannot declare them. A remote repository with a common_repository upstream is written as remote.uri, which serves the same upstream.
func (*Service) IsStoreCache ¶ added in v0.7.0
IsStoreCache implements emu.StoreCacher: the containerd mirror's pull-through cache, written whenever a node pulls an image, is cache. Remote repositories cache too, but their images are packages users see.
func (*Service) LANHandler ¶ added in v0.9.0
LANHandler returns the registry as the --ar-bind listeners serve it, requiring credentials, or nil while the registry isn't running. The Google front end's --gfe-bind listeners serve LOCATION-docker.pkg.dev with it (ADR 0021).
func (*Service) MirrorHosts ¶
MirrorHosts returns the upstream registry hosts that nodes should configure as mirrored through the registry (see RegistriesYAML). Any other host also works through the "*" mirror entry.
func (*Service) Operations ¶ added in v0.2.0
func (s *Service) Operations() []emu.OperationInfo
Operations implements emu.OperationLister.
func (*Service) Register ¶
Register installs the artifactregistry gRPC and REST surfaces, the Locations mixin and google.longrunning Operations on the gateway.
func (*Service) RegistryAddr ¶
RegistryAddr returns the registry listener address (host:port), for peers such as GKE that configure image pulls (FR-AR-005).
func (*Service) Reset ¶
Reset drops pending operations, waiting for running ones (#301), stops upstream fetches (blob downloads and manifests) and waits for them, so none writes to the blob store while it is emptied (#397) or caches anything afterwards (#306), and removes every blob and upload; the store is reset by the Instance. Fetches after Reset run on a fresh background context.
func (*Service) ResourceCounts ¶ added in v0.2.0
ResourceCounts implements emu.ResourceCounter.
func (*Service) Restore ¶ added in v0.6.0
Restore implements emu.Snapshotter, after Reset emptied the blob store.
func (*Service) SetMirrorTagTTL ¶
SetMirrorTagTTL sets how long cached tags are served before they are revalidated with the upstream (default 5m; 0 revalidates every pull).
func (*Service) SetUpstream ¶
SetUpstream overrides the base URL used to reach an upstream registry host, e.g. SetUpstream("docker.io", "https://mirror.example.com") to use a corporate Docker Hub mirror, or an httptest server in tests. An empty baseURL removes the override.
func (*Service) Snapshot ¶ added in v0.6.0
Snapshot implements emu.Snapshotter: blobs are content-addressed and never modified, so they are linked into dir. Uploads in progress are not kept, as Reset does not keep them.