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.
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) MirrorHosts() []string
- func (s *Service) Name() string
- 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) SetMirrorTagTTL(d time.Duration)
- func (s *Service) SetUpstream(host, baseURL string)
- 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) 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) 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) 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.