Help us shape the future of Go! Take the 2026 Go Developer Survey

oci

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package oci is a small read-only OCI Distribution v2 client. It pulls manifests and blobs anonymously or with the registry credentials of the Docker client configuration, through Basic or Bearer-token challenges, which is sufficient for fetching devcontainer features published as OCI artifacts (the "ghcr.io/devcontainers/features/*" namespace, for instance).

This client does not do content verification beyond digest matching, and is intentionally minimal — it's not a substitute for go-containerregistry or oras-go in production-grade tooling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP *http.Client
	// Auth supplies registry credentials. When nil, every registry is
	// accessed anonymously.
	Auth CredentialSource
	// contains filtered or unexported fields
}

Client performs read operations against an OCI distribution registry.

func NewClient

func NewClient() *Client

NewClient constructs a Client using sensible defaults. It reads registry credentials from the Docker client configuration.

func (*Client) FetchBlob

func (c *Client) FetchBlob(ref Reference, digest string, w io.Writer) error

FetchBlob streams a blob to the supplied writer. It verifies the digest before returning success. Errors name ref, not the digest, which can come from a manifest.

func (*Client) FetchImageConfig

func (c *Client) FetchImageConfig(ref Reference, p Platform) (*ImageConfig, error)

FetchImageConfig returns the configuration of the image ref for platform p, following a multi-platform index to p's manifest.

func (*Client) FetchManifest

func (c *Client) FetchManifest(ref Reference) (*Manifest, []byte, error)

FetchManifest fetches a manifest by reference, following indexes if needed by selecting the first child manifest. (For features, indexes are rare; when present we just take whatever is first.)

func (*Client) WithAuth

func (c *Client) WithAuth(auth CredentialSource) *Client

WithAuth returns a client that reads registry credentials from auth and shares c's HTTP client. Its authorizations start empty, so that a token c obtained with its own credentials is never sent for auth. A nil c gives NewClient's HTTP client.

type CredentialSource

type CredentialSource interface {
	Credentials(host string) (registryauth.Credentials, error)
}

CredentialSource supplies the credentials for a registry host.

type Descriptor

type Descriptor struct {
	MediaType   string            `json:"mediaType"`
	Digest      string            `json:"digest"`
	Size        int64             `json:"size"`
	Annotations map[string]string `json:"annotations,omitempty"`
	Platform    *Platform         `json:"platform,omitempty"`
}

Descriptor is the OCI content descriptor used by manifests.

type ImageConfig

type ImageConfig struct {
	Config struct {
		Labels     map[string]string `json:"Labels,omitempty"`
		Entrypoint []string          `json:"Entrypoint,omitempty"`
		Cmd        []string          `json:"Cmd,omitempty"`
		User       string            `json:"User,omitempty"`
		Env        []string          `json:"Env,omitempty"`
	} `json:"config"`
}

ImageConfig is the subset of an OCI image configuration this package reads.

type Index

type Index struct {
	SchemaVersion int          `json:"schemaVersion"`
	MediaType     string       `json:"mediaType"`
	Manifests     []Descriptor `json:"manifests"`
}

Index is a thin model of an OCI index / Docker manifest list.

type Manifest

type Manifest struct {
	SchemaVersion int           `json:"schemaVersion"`
	MediaType     string        `json:"mediaType"`
	ArtifactType  string        `json:"artifactType,omitempty"`
	Config        Descriptor    `json:"config"`
	Layers        []Descriptor  `json:"layers"`
	Annotations   ManifestAnnot `json:"annotations,omitempty"`
}

Manifest is a thin model of an OCI image manifest.

type ManifestAnnot

type ManifestAnnot map[string]string

ManifestAnnot is the typed map for manifest-level annotations.

type Platform

type Platform struct {
	OS           string `json:"os,omitempty"`
	Architecture string `json:"architecture,omitempty"`
	Variant      string `json:"variant,omitempty"`
}

Platform is the OCI platform object found on index descriptors.

type Reference

type Reference struct {
	Registry   string
	Repository string
	Tag        string
	Digest     string
}

Reference is a parsed image reference of the form registry/repository:tag (or @digest).

func ParseReference

func ParseReference(ref string) (Reference, error)

ParseReference parses an OCI reference. If no registry is specified, docker.io is assumed (with an "library/" prefix for single-segment names, matching docker conventions).

func (Reference) String

func (r Reference) String() string

Jump to

Keyboard shortcuts

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