Documentation
¶
Index ¶
- Constants
- Variables
- func IsDigestRef(reference string) bool
- func IsRelative(ref string) bool
- func JoinRef(repository, reference string) string
- func MirrorPopulated(storeDir string) (bool, error)
- func OpenArchive(ctx context.Context, c Client, ref string, platform Platform) (io.ReadCloser, int64, error)
- func OpenSource(ctx context.Context, c Client, ref string) (io.ReadCloser, int64, error)
- func ResolveRef(rawRef, kind, name, base string) (string, error)
- func SplitRef(ref string) (name, reference string)
- func ValidPackageName(name string) bool
- func ValidTag(tag string) bool
- func WithDefaultTag(ref string) string
- type Client
- type CredentialFunc
- type Mirror
- func (m *Mirror) LoadIndex(ctx context.Context, desc ocispec.Descriptor) ([]byte, error)
- func (m *Mirror) LoadLayer(ctx context.Context, manDesc ocispec.Descriptor, wantMediaType string) ([]byte, error)
- func (m *Mirror) Resolve(ctx context.Context) (ocispec.Descriptor, error)
- func (m *Mirror) Sync(ctx context.Context, catalogRef string) (ocispec.Descriptor, error)
- type MissingCatalogBaseError
- type NotAManifestError
- type NotAnImageIndexError
- type Option
- type PackageBlob
- type PackageDigest
- type Platform
- type PublishResult
- type Publisher
- func (p *Publisher) Plan(ctx context.Context, pkgs []PackageBlob) (PublishResult, error)
- func (p *Publisher) Publish(ctx context.Context, catalogRepo string, pkgs []PackageBlob, tags []string) (PublishResult, error)
- func (p *Publisher) PublishToTarget(ctx context.Context, target oras.Target, pkgs []PackageBlob, tags []string) (PublishResult, error)
- type UnsupportedPlatformError
Constants ¶
const ( // MediaTypePkgYAML is both the manifest artifactType and the media type of the // single layer carrying a package's raw pkg.yaml bytes. MediaTypePkgYAML = "application/vnd.nem.pkg.v1+yaml" // AnnotationTitle holds the package name on each index entry (required). AnnotationTitle = "org.opencontainers.image.title" // AnnotationDescription holds an optional one-line package description. AnnotationDescription = "org.opencontainers.image.description" // AnnotationSchemaVersion is the index-level catalog format signal. AnnotationSchemaVersion = "org.vi-dev.nem.catalog.schemaVersion" // CatalogSchemaVersion is the current catalog index format version. CatalogSchemaVersion = "1" )
OCI catalog wire-format identifiers shared by the producer (Publisher) and the consumer (internal/catalog), so the on-registry format cannot drift between them.
Variables ¶
var ErrMissingCatalogBase error = MissingCatalogBaseError{}
ErrMissingCatalogBase is the zero-value sentinel for errors.Is.
var ErrNotAManifest error = NotAManifestError{}
var ErrNotAnImageIndex error = NotAnImageIndexError{}
var ErrUnsupportedPlatform error = UnsupportedPlatformError{}
Functions ¶
func IsDigestRef ¶ added in v0.4.0
IsDigestRef reports whether reference is an OCI content digest (algorithm:hex) rather than a tag — i.e. a digest-pinned reference.
func IsRelative ¶
IsRelative reports whether ref lacks a registry/repository base — i.e. it is empty, or begins with ":" (tag) or "@" (digest).
func JoinRef ¶
JoinRef appends reference to a repository with the separator the reference implies: "@" for a digest, ":" for a tag.
func MirrorPopulated ¶ added in v0.6.0
MirrorPopulated reports whether the oras OCI-layout store at storeDir holds a mirrored catalog index — i.e. its index.json tags a manifest with the localCatalogTag reference. It reads the layout without creating it, so it is safe for read-only diagnostics (unlike NewMirror, which creates the store). A store that has never been synced (no index.json) returns (false, nil).
func OpenArchive ¶
func OpenArchive(ctx context.Context, c Client, ref string, platform Platform) (io.ReadCloser, int64, error)
OpenArchive pulls ref (which must be an OCI Image Index), selects the entry matching platform, fetches that per-platform manifest, and streams its single layer blob.
func OpenSource ¶
OpenSource pulls ref (which must be a plain image manifest) and streams its single layer blob. Source is platform-independent, so there is no selection.
func ResolveRef ¶
ResolveRef turns an authored oci.ref template into an absolute ref template (still containing any {{.Version}} placeholder). kind is "archives" or "sources"; base is the catalog base ("" when none is available). A relative ref with no base yields MissingCatalogBaseError.
func SplitRef ¶
SplitRef splits an absolute reference "<name>[:<tag>][@<digest>]" into the repository name and the reference (digest if present, else tag). A registry port colon (e.g. "localhost:5000/foo") is not mistaken for a tag.
func ValidPackageName ¶ added in v0.4.0
ValidPackageName reports whether name is a valid catalog package name — the constraint the catalog index enforces on every entry title.
func WithDefaultTag ¶
WithDefaultTag appends ":{{.Version}}" when ref carries neither a tag nor a digest. An empty ref becomes the bare default tag.
Types ¶
type Client ¶
type Client interface {
// PullManifest fetches the manifest addressed by ref (its tag or digest).
PullManifest(ctx context.Context, ref string) ([]byte, ocispec.Descriptor, error)
// PullManifestByDigest fetches a manifest by digest from ref's repository.
PullManifestByDigest(ctx context.Context, ref, digest string) ([]byte, error)
// PullBlob fetches a blob described by target from ref's repository.
PullBlob(ctx context.Context, ref string, target ocispec.Descriptor) (io.ReadCloser, int64, error)
}
Client is the minimal ORAS surface OpenArchive/OpenSource need. Every method is scoped to the repository named in ref.
func NewClient ¶
func NewClient(cred CredentialFunc, opts ...Option) Client
NewClient builds a Client that pulls from OCI registries using cred.
type CredentialFunc ¶
CredentialFunc returns registry credentials for a host, in oras-go's shape.
func Keychain ¶
func Keychain(resolver auth.Resolver) CredentialFunc
Keychain composes credentials: the Docker credential store first, then the nem resolver's per-registry fallback, then anonymous. The Docker store loads lazily and memoized; a load failure degrades to the nem/anonymous path.
type Mirror ¶ added in v0.4.0
type Mirror struct {
// contains filtered or unexported fields
}
Mirror caches an OCI catalog's metadata graph in a local oras OCI-layout store, mirroring the catalog image index at <base>. Archive/source blobs are not cached here.
func NewMirror ¶ added in v0.4.0
func NewMirror(storeDir string, cred CredentialFunc) (*Mirror, error)
NewMirror opens (or creates) the OCI-layout store at storeDir and builds a Mirror that authenticates remote pulls with cred. AutoGC is disabled so GC runs only inside Sync.
func NewMirrorWithSource ¶ added in v0.4.0
func NewMirrorWithSource(storeDir string, src oras.ReadOnlyTarget) (*Mirror, error)
NewMirrorWithSource builds a Mirror that copies from src instead of a remote registry, for tests in other packages.
func (*Mirror) LoadIndex ¶ added in v0.4.0
LoadIndex fetches and digest+size-verifies the image-index blob at desc. desc must carry an accurate Size (use the descriptor from Resolve or Sync).
func (*Mirror) LoadLayer ¶ added in v0.4.0
func (m *Mirror) LoadLayer(ctx context.Context, manDesc ocispec.Descriptor, wantMediaType string) ([]byte, error)
LoadLayer fetches the package manifest at manDesc, verifies it, then fetches and verifies its single layer, requiring that layer's media type to equal wantMediaType.
func (*Mirror) Resolve ¶ added in v0.4.0
Resolve returns the locally-mirrored catalog index descriptor. It returns errdef.ErrNotFound when the catalog has never been synced.
type MissingCatalogBaseError ¶
type MissingCatalogBaseError struct {
Package string
}
MissingCatalogBaseError reports a relative oci.ref used where no catalog base is available to resolve it (e.g. a git or local-dir catalog).
func (MissingCatalogBaseError) Error ¶
func (e MissingCatalogBaseError) Error() string
func (MissingCatalogBaseError) Is ¶
func (e MissingCatalogBaseError) Is(target error) bool
type NotAManifestError ¶
type NotAManifestError struct{ Ref, Got string }
NotAManifestError reports that a source ref resolved to an image index rather than a plain image manifest.
func (NotAManifestError) Error ¶
func (e NotAManifestError) Error() string
func (NotAManifestError) Is ¶
func (e NotAManifestError) Is(target error) bool
type NotAnImageIndexError ¶
type NotAnImageIndexError struct{ Ref, Got string }
NotAnImageIndexError reports that an archive ref resolved to a media type other than an OCI image index.
func (NotAnImageIndexError) Error ¶
func (e NotAnImageIndexError) Error() string
func (NotAnImageIndexError) Is ¶
func (e NotAnImageIndexError) Is(target error) bool
type Option ¶
type Option func(*realClient)
Option configures a Client built by NewClient.
func WithPlainHTTP ¶
func WithPlainHTTP() Option
WithPlainHTTP makes the client use http:// (for local registries / tests).
type PackageBlob ¶ added in v0.4.0
PackageBlob is one package to publish: its name/description (for the index entry annotations) and the raw pkg.yaml bytes (stored byte-exact as the layer).
type PackageDigest ¶ added in v0.4.0
PackageDigest reports what was published for one package.
type PublishResult ¶ added in v0.4.0
type PublishResult struct {
IndexDigest string
Packages []PackageDigest
}
PublishResult reports the published (or planned) catalog index and its packages.
type Publisher ¶ added in v0.4.0
type Publisher struct {
// contains filtered or unexported fields
}
Publisher writes catalog metadata (the image index and per-package pkg.yaml manifests) to an OCI registry. It is the write-path counterpart to Mirror.
func NewPublisher ¶ added in v0.4.0
func NewPublisher(cred CredentialFunc) *Publisher
NewPublisher builds a Publisher authenticating remote pushes with cred. cred may be nil when only PublishToTarget against a local target is used (e.g. tests).
func (*Publisher) Plan ¶ added in v0.4.0
func (p *Publisher) Plan(ctx context.Context, pkgs []PackageBlob) (PublishResult, error)
Plan packs the same content into an in-memory target and returns the digests Publish would produce, performing no registry writes.
func (*Publisher) Publish ¶ added in v0.4.0
func (p *Publisher) Publish(ctx context.Context, catalogRepo string, pkgs []PackageBlob, tags []string) (PublishResult, error)
Publish packs and pushes every package into <catalogRepo>, assembles the catalog image index, and tags it with each tag. Returns the resulting digests.
func (*Publisher) PublishToTarget ¶ added in v0.4.0
func (p *Publisher) PublishToTarget(ctx context.Context, target oras.Target, pkgs []PackageBlob, tags []string) (PublishResult, error)
PublishToTarget is the core: it packs each package into an image manifest, pushes the manifests and the assembled index into target, and tags the index with tags (none means push without tagging). Exported so other packages' tests can publish into a local store without a registry.
type UnsupportedPlatformError ¶
UnsupportedPlatformError reports that an image index contained no entry matching the requested platform.
func (UnsupportedPlatformError) Error ¶
func (e UnsupportedPlatformError) Error() string
func (UnsupportedPlatformError) Is ¶
func (e UnsupportedPlatformError) Is(target error) bool