ar

package
v0.10.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 47 Imported by: ? 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 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

Constants

This section is empty.

Variables

View Source
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 Locations added in v0.10.0

func Locations() []string

Locations returns every Artifact Registry location, sorted; each has the Docker host LOCATION-docker.pkg.dev.

func New

func New(env *emu.Env) emu.Service

New returns the service.

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

type RegistryAuth struct {
	Username string
	Password string
}

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

func (s *Service) ApplySeed(ctx context.Context, section *yaml.Node, baseDir string) error

ApplySeed creates (or updates the description and labels of) the seeded repositories. It is idempotent.

func (*Service) EnvVars

func (s *Service) EnvVars(gw string, endpoints map[string]string) map[string]string

EnvVars implements emu.EnvVarer (FR-CORE-004).

func (*Service) ExportSeed added in v0.6.0

func (s *Service) ExportSeed(ctx context.Context) (any, error)

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

func (s *Service) IsStoreCache(ns, key string) bool

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

func (s *Service) LANHandler() http.Handler

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

func (s *Service) MirrorHosts() []string

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

func (s *Service) Name() string

func (*Service) Operations added in v0.2.0

func (s *Service) Operations() []emu.OperationInfo

Operations implements emu.OperationLister.

func (*Service) Ready

func (s *Service) Ready() error

Ready reports whether the registry is listening.

func (*Service) Register

func (s *Service) Register(r emu.Router) error

Register installs the artifactregistry gRPC and REST surfaces, the Locations mixin and google.longrunning Operations on the gateway.

func (*Service) RegistryAddr

func (s *Service) RegistryAddr() string

RegistryAddr returns the registry listener address (host:port), for peers such as GKE that configure image pulls (FR-AR-005).

func (*Service) Reset

func (s *Service) Reset(ctx context.Context) error

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

func (s *Service) ResourceCounts() map[string]int

ResourceCounts implements emu.ResourceCounter.

func (*Service) Restore added in v0.6.0

func (s *Service) Restore(ctx context.Context, dir string) error

Restore implements emu.Snapshotter, after Reset emptied the blob store.

func (*Service) SetMirrorTagTTL

func (s *Service) SetMirrorTagTTL(d time.Duration)

SetMirrorTagTTL sets how long cached tags are served before they are revalidated with the upstream (default 5m; 0 revalidates every pull).

func (*Service) SetUpstream

func (s *Service) SetUpstream(host, baseURL string)

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

func (s *Service) Snapshot(ctx context.Context, dir string) error

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.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start opens the registry listener (FR-AR-002).

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

Stop shuts the registry down and stops pending operations.

Jump to

Keyboard shortcuts

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