oci

package
v0.75.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 9 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 oci provides unified OCI reference parsing, validation, and local-build tagging helpers shared by the skills and plugins services.

Index

Constants

View Source
const DefaultTag = "latest"

DefaultTag is the tag appended to tag-less repository references and used when a build does not specify --tag.

View Source
const LocalBuildAnnotation = "dev.stacklok.toolhive.local-build"

LocalBuildAnnotation marks a tag in a local OCI store as produced by a local build (`thv skill build` or `thv ai-plugin build`) rather than an OCI pull (install, content preview). The value is always "true" when set; absence means "not a local build".

The annotation is stamped at the descriptor level inside the store's root index.json, not on the manifest content. Two properties follow from that:

  1. Push resolves the artifact by digest, which returns a plain descriptor (oras-go's oci.Store strips annotations when the reference is a digest), so the marker never crosses the wire.
  2. Pull calls Store.Tag with the pulled digest, which also resolves by digest before tagging, so pulled tags inherit no annotations and stay invisible to ListBuilds.

The key is reverse-DNS namespaced so it composes with other locally-built artifact types (containers, MCP server images) in the future.

Variables

This section is empty.

Functions

func IsLocalBuild

func IsLocalBuild(ctx context.Context, store TargetStore, tag string) (bool, error)

IsLocalBuild reports whether the given tag in the local OCI store carries the local-build marker. Tags created by OCI pulls do not carry it, so this is the filter used by ListBuilds and local-store installs to exclude cached remote artifacts.

func IsRegistryReference

func IsRegistryReference(raw string) bool

IsRegistryReference reports whether raw parses as a valid registry-qualified OCI reference. Used by lockfile recording to distinguish remotely restorable references from local-store-only tags.

func ResolveBuildTag

func ResolveBuildTag(raw, artifactName string) (string, error)

ResolveBuildTag resolves the final local OCI store tag for a build given the caller's raw --tag flag and the artifact's declared name (from SKILL.md or plugin.json).

Rules:

  • Empty raw tag + empty artifactName -> "" (untagged; caller returns digest).
  • Empty raw tag + non-empty artifactName -> "<artifactName>:latest".
  • Bare tag (e.g. "v1.0.0") -> "<artifactName>:<tag>" (400 if artifactName is empty).
  • Local or registry-qualified tag ref -> normalized "<repo>:<tag>" or "<registry>/<repo>:<tag>" (defaulting tag-less refs with '/' to ":latest").
  • Digest references are rejected with HTTP 400.

func TagAsLocalBuild

func TagAsLocalBuild(ctx context.Context, store TargetStore, d digest.Digest, tag string) error

TagAsLocalBuild tags digest d with the given tag and stamps the local-build marker on the root-index descriptor entry. Callers must only invoke it from code paths that genuinely produced the artifact locally (Build).

func ValidateBuildTagInput

func ValidateBuildTagInput(raw string) error

ValidateBuildTagInput validates the raw --tag flag before packaging runs so invalid syntax or digest references fail fast without writing orphaned blobs to the local OCI store. An empty raw string is valid (the build will default to <artifactName>:latest).

Types

type RefKind

type RefKind int

RefKind classifies the syntactic form of an OCI tag or reference.

const (
	// RefKindBareTag is a single-token tag with no '/', ':', or '@'
	// (e.g. "v1.0.0", "latest", "my-skill").
	RefKindBareTag RefKind = iota
	// RefKindLocal is a registry-less OCI reference whose first segment is a
	// repository or namespace rather than a registry host
	// (e.g. "my-skill:v1.0.0", "org/my-skill:v1.0.0", "org/my-skill").
	RefKindLocal
	// RefKindRegistry is an OCI reference with an explicit registry host
	// (e.g. "ghcr.io/org/my-skill:v1.0.0", "localhost:5000/my-skill:v1").
	RefKindRegistry
)

type Reference

type Reference struct {
	// Raw is the original input string passed to ParseRef.
	Raw string
	// Kind classifies whether the input is a bare tag, a registry-less local
	// reference, or a registry-qualified reference.
	Kind RefKind
	// Registry is the explicit registry host for RefKindRegistry references,
	// preserving the host spelling from Raw (e.g. "ghcr.io", "localhost:5000",
	// "docker.io"). Empty for RefKindBareTag and RefKindLocal.
	Registry string
	// Repository is the repository path without the registry host or tag/digest
	// (e.g. "my-skill", "org/my-skill"). Empty for RefKindBareTag.
	Repository string
	// Tag is the OCI tag portion (defaulted to DefaultTag for tag-less
	// non-digest references). Empty for digest-only references.
	Tag string
	// Digest is the digest identifier (e.g. "sha256:...") when the input is a
	// digest reference. Empty otherwise.
	Digest string
	// HasExplicitTag reports whether the input explicitly specified a tag
	// (always true for RefKindBareTag, false for tag-less "org/name" or
	// "ghcr.io/org/name", and false for digest references).
	HasExplicitTag bool
	// contains filtered or unexported fields
}

Reference is the parsed, validated representation of an OCI tag or reference.

func ParseRef

func ParseRef(raw string) (Reference, error)

ParseRef parses and validates raw as a bare tag, a registry-less local OCI reference, or a registry-qualified OCI reference.

Classification rules:

  • No '/', ':', or '@' -> RefKindBareTag (validated as an OCI tag).
  • Contains '/', ':', or '@' and the first '/'-segment is "localhost" or contains '.' or ':' -> RefKindRegistry.
  • Contains '/', ':', or '@' otherwise -> RefKindLocal.

Tag-less non-digest references with '/' (e.g. "org/my-skill", "ghcr.io/org/my-skill", "localhost:5000/my-skill") are normalized by appending ":latest" while keeping HasExplicitTag == false. Registry-less references are never implicitly expanded to Docker Hub.

func ValidatePushReference

func ValidatePushReference(raw string) (Reference, error)

ValidatePushReference validates that raw is a registry-qualified OCI reference suitable for pushing to a remote registry. Registry-less local references and bare tags are rejected with HTTP 400 so push never implicitly targets Docker Hub.

func (Reference) HasRegistry

func (r Reference) HasRegistry() bool

HasRegistry reports whether the reference carries an explicit registry host.

func (Reference) IsBareTag

func (r Reference) IsBareTag() bool

IsBareTag reports whether the reference is a single-token bare tag with no '/', ':', or '@'.

func (Reference) IsDigest

func (r Reference) IsDigest() bool

IsDigest reports whether the reference is pinned by content digest.

func (Reference) IsLocal

func (r Reference) IsLocal() bool

IsLocal reports whether the reference is a registry-less structured reference (name:tag, org/name, org/name:tag, etc.).

func (Reference) NameRef

func (r Reference) NameRef() nameref.Reference

NameRef returns the underlying go-containerregistry Reference for RefKindRegistry values, or nil for bare tags and local references.

func (Reference) RepoBasename

func (r Reference) RepoBasename() string

RepoBasename returns the final path segment of Repository (e.g. "my-skill" for "org/my-skill" or "my-skill"), or empty string for RefKindBareTag.

func (Reference) String

func (r Reference) String() string

String returns the normalized reference string. For RefKindBareTag it is the bare tag; for RefKindLocal and RefKindRegistry it preserves the user's host and repository verbatim and includes the explicit or defaulted ":latest" tag (or "@digest" for digest references).

type TargetStore

type TargetStore interface {
	Target() oras.Target
}

TargetStore is the minimal interface satisfied by both *ociskills.Store and *ociplugins.Store for descriptor-level local-build tagging.

Jump to

Keyboard shortcuts

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