Documentation
¶
Overview ¶
pkg/model/index.go
pkg/model/pusher.go
pkg/model/weights_lock.go
Index ¶
- Constants
- Variables
- func GetPushConcurrency() int
- func OCIIndexEnabled() bool
- func WeightTag(name, digest string) string
- type Artifact
- type ArtifactSpec
- type ArtifactType
- type BuildOptions
- type BuildRef
- type Builder
- type BundlePusher
- type DockerfileFactory
- type Factory
- type ImageArtifact
- func (a *ImageArtifact) CogVersion() string
- func (a *ImageArtifact) Config() string
- func (a *ImageArtifact) Descriptor() v1.Descriptor
- func (a *ImageArtifact) IsCogModel() bool
- func (a *ImageArtifact) Name() string
- func (a *ImageArtifact) OpenAPISchema() string
- func (a *ImageArtifact) ParsedConfig() (*config.Config, error)
- func (a *ImageArtifact) ParsedOpenAPISchema() (*openapi3.T, error)
- func (a *ImageArtifact) ToModel() (*Model, error)
- func (a *ImageArtifact) Type() ArtifactType
- type ImageBuilder
- type ImagePushOption
- type ImagePusher
- type ImageSource
- type ImageSpec
- type ImageSpecOption
- type Index
- type IndexBuilder
- type IndexManifest
- type LocalRef
- type ManifestType
- type Model
- func (m *Model) ArtifactsByType(t ArtifactType) []Artifact
- func (m *Model) GetImageArtifact() *ImageArtifact
- func (m *Model) HasGPU() bool
- func (m *Model) ImageRef() string
- func (m *Model) IsBundle() bool
- func (m *Model) SchemaJSON() ([]byte, error)
- func (m *Model) WeightArtifacts() []*WeightArtifact
- type Option
- type ParseOption
- type ParsedRef
- type Platform
- type PushOptions
- type PushProgress
- type Ref
- type RemoteRef
- type Resolver
- func (r *Resolver) Build(ctx context.Context, src *Source, opts BuildOptions) (*Model, error)
- func (r *Resolver) Inspect(ctx context.Context, ref *ParsedRef, opts ...Option) (*Model, error)
- func (r *Resolver) InspectByID(ctx context.Context, id string) (*Model, error)
- func (r *Resolver) Pull(ctx context.Context, ref *ParsedRef, opts ...Option) (*Model, error)
- func (r *Resolver) Push(ctx context.Context, m *Model, opts PushOptions) error
- func (r *Resolver) Resolve(ctx context.Context, ref Ref) (*Model, error)
- func (r *Resolver) WithFactory(f Factory) *Resolver
- type Source
- type TagRef
- type WeightArtifact
- type WeightBuilder
- type WeightConfig
- type WeightFile
- type WeightPushOptions
- type WeightPushResult
- type WeightPusher
- type WeightRetryEvent
- type WeightSpec
- type WeightsLock
Constants ¶
const ( // MediaTypeWeightArtifact is the artifactType for weight manifests. MediaTypeWeightArtifact = "application/vnd.cog.weight.v1" // MediaTypeWeightConfig is the media type for weight config blobs. MediaTypeWeightConfig = "application/vnd.cog.weight.config.v1+json" // MediaTypeWeightLayer is the media type for uncompressed weight layers. MediaTypeWeightLayer = "application/vnd.cog.weight.layer.v1" // MediaTypeWeightLayerGzip is the media type for gzip-compressed weight layers. MediaTypeWeightLayerGzip = "application/vnd.cog.weight.layer.v1+gzip" // MediaTypeWeightLayerZstd is the media type for zstd-compressed weight layers (future). MediaTypeWeightLayerZstd = "application/vnd.cog.weight.layer.v1+zstd" )
Media types for weight artifacts (OCI 1.1 conventions).
const ( AnnotationWeightName = "vnd.cog.weight.name" AnnotationWeightDest = "vnd.cog.weight.dest" AnnotationWeightDigestOriginal = "vnd.cog.weight.digest.original" AnnotationWeightSizeUncompressed = "vnd.cog.weight.size.uncompressed" )
Annotation keys for weight file layers in OCI manifests.
const ( AnnotationReferenceType = "vnd.cog.reference.type" AnnotationReferenceDigest = "vnd.cog.reference.digest" )
Annotation keys for weights manifests.
const (
// AnnotationValueWeights is the value for AnnotationReferenceType indicating a weights manifest.
AnnotationValueWeights = "weights"
)
Annotation values.
const ( // DefaultPushConcurrency is the default number of concurrent uploads // for both image layers and weight artifacts. // This matches Docker's default concurrency for layer uploads, which is a reasonable baseline for OCI pushes as well. DefaultPushConcurrency = 5 )
const (
// PlatformUnknown is used for artifacts that are not platform-specific (e.g., weights).
PlatformUnknown = "unknown"
)
Platform values for non-platform-specific artifacts.
const WeightsLockFilename = "weights.lock"
WeightsLockFilename is the default filename for the weights lock file.
Variables ¶
var ( LabelConfig = global.LabelNamespace + "config" LabelVersion = global.LabelNamespace + "version" LabelOpenAPISchema = global.LabelNamespace + "openapi_schema" LabelWeightsManifest = global.LabelNamespace + "r8_weights_manifest" )
Label keys for Cog-specific metadata stored in image labels.
var ( // ErrNotCogModel indicates the image exists but is not a valid Cog model. // This occurs when the image lacks the required run.cog.config label. ErrNotCogModel = errors.New("image is not a Cog model") // ErrNotFound indicates the image was not found in the requested location(s). ErrNotFound = errors.New("image not found") )
Sentinel errors for Resolver operations.
Functions ¶
func GetPushConcurrency ¶ added in v0.17.0
func GetPushConcurrency() int
GetPushConcurrency returns the push concurrency, checking the COG_PUSH_CONCURRENCY environment variable first, then falling back to DefaultPushConcurrency.
func OCIIndexEnabled ¶ added in v0.17.0
func OCIIndexEnabled() bool
TODO(md): OCIIndexEnabled is a temporary gate for the OCI Image Index push path. When COG_OCI_INDEX=1, builds produce weight artifacts and pushes create an OCI Image Index instead of a single image manifest. Remove this gate (and always use the index path) once we've validated index compatibility with all registries.
Types ¶
type Artifact ¶ added in v0.17.0
type Artifact interface {
Type() ArtifactType
Name() string
Descriptor() v1.Descriptor
}
Artifact is the immutable result of building a spec. It contains the OCI descriptor and enough information for a pusher to upload it.
type ArtifactSpec ¶ added in v0.17.0
type ArtifactSpec interface {
Type() ArtifactType
Name() string
}
ArtifactSpec declares what artifact will be produced. It contains all inputs needed to build that artifact. Specs are derived from analyzing the Source (cog.yaml + project directory).
type ArtifactType ¶ added in v0.17.0
type ArtifactType int
ArtifactType identifies the kind of artifact.
const ( // ArtifactTypeImage is a container image artifact. ArtifactTypeImage ArtifactType = iota + 1 // ArtifactTypeWeight is a model weight artifact. ArtifactTypeWeight )
func (ArtifactType) String ¶ added in v0.17.0
func (t ArtifactType) String() string
String returns the human-readable name of the artifact type.
type BuildOptions ¶ added in v0.17.0
type BuildOptions struct {
// ImageName is the output image name (required).
ImageName string
// NoCache disables build cache.
NoCache bool
// SeparateWeights builds weights as a separate layer.
SeparateWeights bool
// Strip removes debug symbols from binaries.
Strip bool
// Precompile precompiles Python bytecode.
Precompile bool
// UseCudaBaseImage controls CUDA base image usage: "auto", "true", or "false".
UseCudaBaseImage string
// UseCogBaseImage controls cog base image usage. nil means auto-detect.
UseCogBaseImage *bool
// Secrets are build-time secrets to pass to the build.
Secrets []string
// ProgressOutput controls build output format: "auto", "plain", or "tty".
ProgressOutput string
// Annotations are extra labels to add to the image.
Annotations map[string]string
// SchemaFile is a custom OpenAPI schema file path.
SchemaFile string
// DockerfileFile is a custom Dockerfile path.
DockerfileFile string
// WeightsLockPath is the path to weights.lock file.
// Default: weights.lock in project directory.
WeightsLockPath string
// TODO(md): OCIIndex is a temporary gate. When true, builds produce weight
// artifacts and pushes create an OCI Image Index. Set via COG_OCI_INDEX=1.
// Remove this field once index pushes are validated with all registries.
OCIIndex bool
// ExcludeSource skips the COPY . /src step in the generated Dockerfile.
// Used by `cog serve` to produce an image identical to `cog build` minus
// the source copy — the source directory is volume-mounted at runtime.
// All other layers (wheel installs, apt, etc.) are shared with `cog build`
// via Docker layer caching.
ExcludeSource bool
// SkipSchemaValidation skips OpenAPI schema generation and validation.
// Used by `cog run` which executes arbitrary commands and may not have
// a predictor or trainer defined in cog.yaml.
SkipSchemaValidation bool
// SkipLabels skips adding Cog metadata labels to the built image.
// Used by `cog run`, `cog predict`, `cog serve`, and `cog train` where
// the image is for local use only and not being distributed.
SkipLabels bool
}
BuildOptions contains all settings for building a Cog image. This consolidates the many parameters previously passed to image.Build().
func (BuildOptions) WithDefaults ¶ added in v0.17.0
func (o BuildOptions) WithDefaults(src *Source) BuildOptions
WithDefaults returns a copy of BuildOptions with defaults applied from Source. This fills in sensible defaults for any unset fields.
type BuildRef ¶ added in v0.17.0
type BuildRef struct {
Source *Source
Options BuildOptions
}
BuildRef resolves to a Model by building from source. This wraps a Source and BuildOptions for deferred building.
func FromBuild ¶ added in v0.17.0
func FromBuild(src *Source, opts BuildOptions) *BuildRef
FromBuild creates a BuildRef from source and options. Unlike the other From* functions, this does not validate eagerly - validation happens at build time.
type Builder ¶ added in v0.17.0
type Builder interface {
Build(ctx context.Context, spec ArtifactSpec) (Artifact, error)
}
Builder builds an artifact from a spec. Each builder handles one artifact type (image, weight, etc.).
type BundlePusher ¶ added in v0.17.0
type BundlePusher struct {
// contains filtered or unexported fields
}
BundlePusher pushes bundles (OCI Index with image + weight artifacts). It orchestrates ImagePusher and WeightPusher, then assembles the OCI index from the pushed manifest descriptors.
func NewBundlePusher ¶ added in v0.17.0
func NewBundlePusher(docker command.Command, reg registry.Client) *BundlePusher
NewBundlePusher creates a new BundlePusher from docker and registry clients. Both sub-pushers (image and weight) are created internally to keep construction unified — callers don't need to know about ImagePusher or WeightPusher directly.
func (*BundlePusher) Push ¶ added in v0.17.0
func (p *BundlePusher) Push(ctx context.Context, m *Model, opts PushOptions) error
Push pushes the model as an OCI Index with weight artifacts. It reads Model.Artifacts to find the image and weight artifacts to push.
type DockerfileFactory ¶ added in v0.17.0
type DockerfileFactory struct {
// contains filtered or unexported fields
}
DockerfileFactory wraps existing Dockerfile-based build.
func (*DockerfileFactory) Build ¶ added in v0.17.0
func (f *DockerfileFactory) Build(ctx context.Context, src *Source, opts BuildOptions) (*ImageArtifact, error)
Build delegates to the existing image.Build() function.
func (*DockerfileFactory) Name ¶ added in v0.17.0
func (f *DockerfileFactory) Name() string
Name returns the factory name.
type Factory ¶ added in v0.17.0
type Factory interface {
// Build creates a Docker image from source and returns ImageArtifact metadata.
// For dev mode (cog serve), set ExcludeSource=true in BuildOptions to skip
// COPY . /src — the source directory is volume-mounted at runtime instead.
Build(ctx context.Context, src *Source, opts BuildOptions) (*ImageArtifact, error)
// Name returns the factory name for logging/debugging.
Name() string
}
Factory is the build backend interface. Different implementations handle different build strategies.
type ImageArtifact ¶ added in v0.17.0
type ImageArtifact struct {
// Image metadata
Reference string // Full image reference (e.g., "r8.im/user/model:latest")
Digest string // Content-addressable digest (sha256:...)
Labels map[string]string // Docker/OCI image labels
Platform *Platform // OS/architecture
Source ImageSource // Where loaded from (local/remote/build)
// contains filtered or unexported fields
}
ImageArtifact represents an OCI container image. It serves as both the build artifact (in Model.Artifacts) and the general-purpose image metadata type throughout the codebase. It implements the Artifact interface.
func NewImageArtifact ¶ added in v0.17.0
func NewImageArtifact(name string, desc v1.Descriptor, reference string) *ImageArtifact
NewImageArtifact creates an ImageArtifact from a build result.
func (*ImageArtifact) CogVersion ¶ added in v0.17.0
func (a *ImageArtifact) CogVersion() string
CogVersion returns the Cog version that built this image, or empty string if not set.
func (*ImageArtifact) Config ¶ added in v0.17.0
func (a *ImageArtifact) Config() string
Config returns the raw cog.yaml config stored in image labels, or empty string if not set.
func (*ImageArtifact) Descriptor ¶ added in v0.17.0
func (a *ImageArtifact) Descriptor() v1.Descriptor
Descriptor returns the OCI descriptor for this image.
func (*ImageArtifact) IsCogModel ¶ added in v0.17.0
func (a *ImageArtifact) IsCogModel() bool
IsCogModel returns true if this image has Cog labels indicating it's a Cog model.
func (*ImageArtifact) Name ¶ added in v0.17.0
func (a *ImageArtifact) Name() string
Name returns the artifact's logical name.
func (*ImageArtifact) OpenAPISchema ¶ added in v0.17.0
func (a *ImageArtifact) OpenAPISchema() string
OpenAPISchema returns the OpenAPI schema stored in image labels, or empty string if not set.
func (*ImageArtifact) ParsedConfig ¶ added in v0.17.0
func (a *ImageArtifact) ParsedConfig() (*config.Config, error)
ParsedConfig returns the parsed cog.yaml config from image labels. Returns nil without error if no config label is present. Returns error if the label contains invalid JSON.
func (*ImageArtifact) ParsedOpenAPISchema ¶ added in v0.17.0
func (a *ImageArtifact) ParsedOpenAPISchema() (*openapi3.T, error)
ParsedOpenAPISchema returns the parsed OpenAPI schema from image labels. Returns nil without error if no schema label is present. Returns error if the label contains invalid JSON.
func (*ImageArtifact) ToModel ¶ added in v0.17.0
func (a *ImageArtifact) ToModel() (*Model, error)
ToModel converts the ImageArtifact to a Model by parsing its labels. Returns error if the image is not a valid Cog model or if labels contain invalid JSON.
func (*ImageArtifact) Type ¶ added in v0.17.0
func (a *ImageArtifact) Type() ArtifactType
Type returns ArtifactTypeImage.
type ImageBuilder ¶ added in v0.17.0
type ImageBuilder struct {
// contains filtered or unexported fields
}
ImageBuilder builds an ImageArtifact from an ImageSpec. It delegates to a Factory for the docker build, inspects the result to populate labels and the canonical digest, and returns a fully populated ImageArtifact.
func NewImageBuilder ¶ added in v0.17.0
func NewImageBuilder(factory Factory, docker command.Command, source *Source, opts BuildOptions) *ImageBuilder
NewImageBuilder creates an ImageBuilder.
func (*ImageBuilder) Build ¶ added in v0.17.0
func (b *ImageBuilder) Build(ctx context.Context, spec ArtifactSpec) (Artifact, error)
Build builds an ImageArtifact from an ImageSpec. It delegates to the Factory for the docker build, inspects the result to populate labels and the canonical digest, and returns a fully populated ImageArtifact.
type ImagePushOption ¶ added in v0.17.0
type ImagePushOption func(*imagePushOptions)
ImagePushOption is a functional option for configuring ImagePusher.Push.
func WithOnFallback ¶ added in v0.17.0
func WithOnFallback(fn func()) ImagePushOption
WithOnFallback sets a callback invoked when OCI push fails and the push is about to fall back to Docker push. This allows the caller to clean up any OCI-specific progress display before Docker push starts its own output.
func WithProgressFn ¶ added in v0.17.0
func WithProgressFn(fn func(PushProgress)) ImagePushOption
WithProgressFn sets a callback for reporting per-layer upload progress.
type ImagePusher ¶ added in v0.17.0
type ImagePusher struct {
// contains filtered or unexported fields
}
ImagePusher pushes container images to a registry.
It first attempts an OCI chunked push (export from Docker -> tarball -> push layers via registry client), then falls back to Docker's native push on any non-fatal error. This bypasses size limits on Docker's monolithic push path while maintaining backwards compatibility.
func (*ImagePusher) Push ¶ added in v0.17.0
func (p *ImagePusher) Push(ctx context.Context, artifact *ImageArtifact, opts ...ImagePushOption) error
Push pushes a container image to the registry.
Tries the OCI chunked push path first (if enabled and registry client is available), then falls back to Docker push on any non-fatal error. The artifact must have a valid Reference.
type ImageSource ¶ added in v0.17.0
type ImageSource string
ImageSource indicates where an image was loaded from.
const ( ImageSourceLocal ImageSource = "local" // Docker daemon ImageSourceRemote ImageSource = "remote" // Registry ImageSourceBuild ImageSource = "build" // Just built )
type ImageSpec ¶ added in v0.17.0
type ImageSpec struct {
ImageName string
Secrets []string
NoCache bool
// contains filtered or unexported fields
}
ImageSpec declares an image to be built. It implements ArtifactSpec.
TODO: ImageBuilder currently reads build options from BuildOptions (passed at construction) rather than from ImageSpec fields. When the build pipeline fully migrates to specs, ImageName/Secrets/NoCache should be the source of truth.
func NewImageSpec ¶ added in v0.17.0
func NewImageSpec(name, imageName string, opts ...ImageSpecOption) *ImageSpec
NewImageSpec creates an ImageSpec with the given name and image name. Optional configuration can be provided via ImageSpecOption functions.
func (*ImageSpec) Type ¶ added in v0.17.0
func (s *ImageSpec) Type() ArtifactType
Type returns ArtifactTypeImage.
type ImageSpecOption ¶ added in v0.17.0
type ImageSpecOption func(*ImageSpec)
ImageSpecOption configures optional fields on ImageSpec.
func WithImageNoCache ¶ added in v0.17.0
func WithImageNoCache(noCache bool) ImageSpecOption
WithImageNoCache disables build cache for the image build.
func WithImageSecrets ¶ added in v0.17.0
func WithImageSecrets(secrets []string) ImageSpecOption
WithImageSecrets sets build-time secrets for the image build.
type Index ¶ added in v0.17.0
type Index struct {
// Digest is the index digest (sha256:...).
Digest string
// Reference is the full image reference.
Reference string
// MediaType is typically application/vnd.oci.image.index.v1+json.
MediaType string
// Manifests are the child manifests in this index.
Manifests []IndexManifest
}
Index represents an OCI Image Index containing multiple manifests.
type IndexBuilder ¶ added in v0.17.0
type IndexBuilder struct {
// contains filtered or unexported fields
}
IndexBuilder builds an OCI Image Index from pre-pushed manifest descriptors.
func NewIndexBuilder ¶ added in v0.17.0
func NewIndexBuilder() *IndexBuilder
NewIndexBuilder creates a new index builder.
func (*IndexBuilder) AddWeightDescriptor ¶ added in v0.17.0
func (b *IndexBuilder) AddWeightDescriptor(desc v1.Descriptor, imageDigest, name, target string)
AddWeightDescriptor adds a weight manifest descriptor. imageDigest is the digest of the model image, used in the reference annotation. name and target are optional weight metadata for index annotations.
func (*IndexBuilder) BuildFromDescriptors ¶ added in v0.17.0
func (b *IndexBuilder) BuildFromDescriptors() (v1.ImageIndex, error)
BuildFromDescriptors creates an OCI Image Index from pre-pushed manifest descriptors. This works with bare descriptors returned from push operations, avoiding the need to fetch images back from the registry.
func (*IndexBuilder) SetImageDescriptor ¶ added in v0.17.0
func (b *IndexBuilder) SetImageDescriptor(desc v1.Descriptor, platform *v1.Platform)
SetImageDescriptor sets the image manifest descriptor.
type IndexManifest ¶ added in v0.17.0
type IndexManifest struct {
// Digest is the manifest digest.
Digest string
// MediaType is the manifest media type.
MediaType string
// Size is the manifest size in bytes.
Size int64
// Platform is the target platform (nil for artifacts).
Platform *Platform
// Annotations are OCI annotations on this manifest.
Annotations map[string]string
// Type is derived from platform/annotations (image or weights).
Type ManifestType
}
IndexManifest represents a single manifest within an index.
type LocalRef ¶ added in v0.17.0
type LocalRef struct {
Parsed *ParsedRef
}
LocalRef resolves an image from the local docker daemon only. It will not fall back to remote registry if the image is not found locally.
type ManifestType ¶ added in v0.17.0
type ManifestType string
ManifestType identifies the type of manifest in an index.
const ( // ManifestTypeImage is a runnable container image. ManifestTypeImage ManifestType = "image" // ManifestTypeWeights is a weights artifact. ManifestTypeWeights ManifestType = "weights" )
type Model ¶
type Model struct {
Image *ImageArtifact // Underlying OCI image
Config *config.Config // Parsed cog.yaml
Schema *openapi3.T // OpenAPI schema
CogVersion string // Version of cog used to build
// Index is the OCI Image Index (populated when inspecting a pushed model).
Index *Index
// TODO(md): OCIIndex is a temporary gate. When true, Push() creates an OCI
// Image Index with weight artifacts. When false, Push() does a plain docker push.
// Remove this field once index pushes are validated with all registries.
OCIIndex bool
// Artifacts is the collection of all artifacts produced by building this model.
// Populated by Resolver.Build(). Contains ImageArtifact and WeightArtifact instances.
Artifacts []Artifact
}
Model represents a Cog model extracted from an image.
func (*Model) ArtifactsByType ¶ added in v0.17.0
func (m *Model) ArtifactsByType(t ArtifactType) []Artifact
ArtifactsByType returns all artifacts matching the given type.
func (*Model) GetImageArtifact ¶ added in v0.17.0
func (m *Model) GetImageArtifact() *ImageArtifact
GetImageArtifact returns the first ImageArtifact from the artifacts collection, or nil if none exists.
func (*Model) ImageRef ¶ added in v0.17.0
ImageRef returns the image reference string, or empty string if no image.
func (*Model) SchemaJSON ¶ added in v0.17.0
SchemaJSON returns the OpenAPI schema as JSON bytes, or nil if no schema.
func (*Model) WeightArtifacts ¶ added in v0.17.0
func (m *Model) WeightArtifacts() []*WeightArtifact
WeightArtifacts returns all WeightArtifact instances from the artifacts collection.
type Option ¶ added in v0.17.0
type Option func(*options)
Option configures how Resolver methods behave.
func LocalOnly ¶ added in v0.17.0
func LocalOnly() Option
LocalOnly loads only from the local docker daemon. Returns an error if the image is not found locally.
func PreferLocal ¶ added in v0.17.0
func PreferLocal() Option
PreferLocal tries local docker daemon first, falls back to remote on not-found.
func PreferRemote ¶ added in v0.17.0
func PreferRemote() Option
PreferRemote tries remote registry first, falls back to local on not-found. This is the default behavior.
func RemoteOnly ¶ added in v0.17.0
func RemoteOnly() Option
RemoteOnly loads only from the remote registry. Does not check the local docker daemon.
func WithPlatform ¶ added in v0.17.0
WithPlatform sets the platform for remote registry queries.
type ParseOption ¶ added in v0.17.0
type ParseOption func(*parseOptions)
ParseOption configures how image references are parsed.
func Insecure ¶ added in v0.17.0
func Insecure() ParseOption
Insecure allows parsing references to registries that use HTTP or have invalid/self-signed certificates. Use this for local development registries like localhost:5000.
func WithDefaultRegistry ¶ added in v0.17.0
func WithDefaultRegistry(registry string) ParseOption
WithDefaultRegistry sets the registry to use when the reference doesn't include one. By default, Docker Hub (index.docker.io) is used.
func WithDefaultTag ¶ added in v0.17.0
func WithDefaultTag(tag string) ParseOption
WithDefaultTag sets the tag to use when the reference doesn't include one. By default, "latest" is used.
type ParsedRef ¶ added in v0.17.0
type ParsedRef struct {
// Original is the input string before parsing.
Original string
// Ref is the underlying parsed reference from go-containerregistry.
Ref name.Reference
}
ParsedRef wraps a validated and parsed image reference.
func ParseRef ¶ added in v0.17.0
func ParseRef(ref string, opts ...ParseOption) (*ParsedRef, error)
ParseRef validates and parses an image reference.
func (*ParsedRef) Digest ¶ added in v0.17.0
Digest returns the digest (e.g., "sha256:...") or empty string if this is a tag reference.
func (*ParsedRef) IsDigest ¶ added in v0.17.0
IsDigest returns true if the reference includes a digest.
func (*ParsedRef) IsReplicate ¶ added in v0.17.0
IsReplicate returns true if the registry is the Replicate registry (r8.im).
func (*ParsedRef) Registry ¶ added in v0.17.0
Registry returns the registry host (e.g., "r8.im", "index.docker.io").
func (*ParsedRef) Repository ¶ added in v0.17.0
Repository returns the repository path (e.g., "user/model", "library/nginx").
type PushOptions ¶ added in v0.17.0
type PushOptions struct {
// ProjectDir is the base directory for resolving weight file paths.
//
// Deprecated: Artifacts carry their own file paths.
ProjectDir string
// FilePaths maps weight name identifiers to their file paths.
//
// Deprecated: Use Model.Artifacts instead — WeightArtifact carries FilePath.
FilePaths map[string]string
// Platform specifies the target platform for bundle indexes.
// Default: linux/amd64
Platform *Platform
// ImageProgressFn is an optional callback for reporting per-layer upload progress
// during OCI chunked image push. Each call includes the layer digest, bytes
// completed, and total bytes.
ImageProgressFn func(PushProgress)
// OnFallback is called when OCI push fails and the push is about to fall
// back to Docker push. This allows the caller to clean up any OCI-specific
// progress display before Docker push starts its own output.
OnFallback func()
}
PushOptions configures push behavior.
type PushProgress ¶ added in v0.17.0
type PushProgress struct {
// LayerDigest identifies which layer this progress is for.
// Empty for single-layer pushes (e.g., weight uploads).
LayerDigest string
// Complete is the number of bytes uploaded so far.
Complete int64
// Total is the total number of bytes to upload.
Total int64
}
PushProgress reports progress for a layer or blob upload. Used by both ImagePusher (container image layers) and WeightPusher (weight blobs).
type Ref ¶ added in v0.17.0
type Ref interface {
// contains filtered or unexported methods
}
Ref represents something that can be resolved to a Model. This interface enables declarative model resolution - callers specify "what they have" (a tag, local image, or source to build) and the Resolver figures out how to produce a Model.
type RemoteRef ¶ added in v0.17.0
type RemoteRef struct {
Parsed *ParsedRef
}
RemoteRef resolves an image from a remote registry only. It will not check the local docker daemon.
func FromRemote ¶ added in v0.17.0
FromRemote parses and validates a reference for remote resolution. Returns an error immediately if the reference is invalid.
type Resolver ¶ added in v0.17.0
type Resolver struct {
// contains filtered or unexported fields
}
Resolver orchestrates building and loading Models.
func NewResolver ¶ added in v0.17.0
NewResolver creates a Resolver with the default factory.
func (*Resolver) Inspect ¶ added in v0.17.0
Inspect returns Model metadata for a parsed ref without pulling. By default (PreferLocal), tries local docker daemon first, then remote registry. Only falls back on "not found" errors; real errors (docker down, auth) are surfaced. Returns ErrNotCogModel if the image is not a valid Cog model.
func (*Resolver) InspectByID ¶ added in v0.17.0
InspectByID returns Model metadata from the local docker daemon by image ID. This supports both full IDs (sha256:...) and short IDs (e.g., "9056219a5fb2"). Use this when you have an image ID rather than a tagged reference. Returns ErrNotCogModel if the image is not a valid Cog model.
func (*Resolver) Pull ¶ added in v0.17.0
Pull ensures a Model is locally available for running. It first checks if the image exists locally. If not, it pulls from the registry. Returns ErrNotCogModel if the image is not a valid Cog model. Returns ErrNotFound if the image cannot be found locally or remotely.
func (*Resolver) Push ¶ added in v0.17.0
Push pushes a Model to a container registry.
Uses the OCI chunked push path (via ImagePusher) which bypasses Docker's monolithic push and supports layers of any size through chunked uploads. Falls back to legacy Docker push if OCI push is not available.
func (*Resolver) Resolve ¶ added in v0.17.0
Resolve resolves any Ref to a Model. This is the main entry point for declarative model resolution.
func (*Resolver) WithFactory ¶ added in v0.17.0
WithFactory sets a custom factory and returns the Resolver for chaining.
type Source ¶ added in v0.17.0
type Source struct {
Config *config.Config
ProjectDir string
ConfigFilename string // Base filename like "cog.yaml" or "my-config.yaml"
Warnings []config.DeprecationWarning
}
Source represents a Cog project ready to build. It combines the parsed configuration with the project directory location.
func NewSource ¶ added in v0.17.0
NewSource loads configuration from the given path and returns a Source. The configPath can be a filename (e.g., "cog.yaml") which will be searched for in the current directory and parent directories.
func NewSourceFromConfig ¶ added in v0.17.0
NewSourceFromConfig creates a Source from an existing Config. Use this when you already have a parsed config and know the project directory.
func (*Source) ArtifactSpecs ¶ added in v0.17.0
func (s *Source) ArtifactSpecs() []ArtifactSpec
ArtifactSpecs returns the artifact declarations derived from this source. Always produces at least one ImageSpec. Produces a WeightSpec for each weight declared in the config. Returns nil if Config is nil.
type TagRef ¶ added in v0.17.0
type TagRef struct {
Parsed *ParsedRef
}
TagRef resolves an image by tag or digest reference. It uses the default Load behavior: try remote registry first, then fall back to local docker daemon if not found remotely.
type WeightArtifact ¶ added in v0.17.0
type WeightArtifact struct {
// FilePath is the local file path to the weight data (for pushing layers).
FilePath string
// Target is the container mount path for this weight.
Target string
// Config is the weight metadata for the config blob.
Config WeightConfig
// contains filtered or unexported fields
}
WeightArtifact is a built weight artifact ready to push as an OCI artifact. It implements Artifact.
func NewWeightArtifact ¶ added in v0.17.0
func NewWeightArtifact(name string, desc v1.Descriptor, filePath, target string, cfg WeightConfig) *WeightArtifact
NewWeightArtifact creates a WeightArtifact from a build result.
func (*WeightArtifact) Descriptor ¶ added in v0.17.0
func (a *WeightArtifact) Descriptor() v1.Descriptor
Descriptor returns the OCI descriptor for this weight artifact.
func (*WeightArtifact) Name ¶ added in v0.17.0
func (a *WeightArtifact) Name() string
Name returns the artifact's logical name.
func (*WeightArtifact) Type ¶ added in v0.17.0
func (a *WeightArtifact) Type() ArtifactType
Type returns ArtifactTypeWeight.
type WeightBuilder ¶ added in v0.17.0
type WeightBuilder struct {
// contains filtered or unexported fields
}
WeightBuilder builds WeightArtifact from WeightSpec. It hashes the source file, creates a WeightConfig, and manages a lockfile as build cache.
func NewWeightBuilder ¶ added in v0.17.0
func NewWeightBuilder(source *Source, cogVersion, lockPath string) *WeightBuilder
NewWeightBuilder creates a WeightBuilder. lockPath is where the weights.lock file is read/written as a build cache.
func (*WeightBuilder) Build ¶ added in v0.17.0
func (b *WeightBuilder) Build(ctx context.Context, spec ArtifactSpec) (Artifact, error)
Build builds a WeightArtifact from a WeightSpec. It resolves the source file, computes its SHA256 digest, and creates the artifact with a versioned WeightConfig.
type WeightConfig ¶ added in v0.17.0
type WeightConfig struct {
SchemaVersion string `json:"schemaVersion"`
CogVersion string `json:"cogVersion"`
Name string `json:"name"`
Target string `json:"target"`
Created time.Time `json:"created"` // RFC 3339 format when serialized to JSON
}
WeightConfig contains metadata about a weight artifact. This is serialized as the config blob in the OCI manifest. The schema is versioned via SchemaVersion to allow evolution.
type WeightFile ¶ added in v0.17.0
type WeightFile struct {
// Name is the identifier/handle for this weight (e.g., "personaplex-7b-v1", "model-v42.5").
// This is a logical name that maps to deployment blob metadata, not a file path.
Name string `json:"name"`
// Dest is the mount path in the container (e.g., /cache/model.safetensors).
Dest string `json:"dest"`
// DigestOriginal is the SHA256 of the uncompressed file (canonical ID).
DigestOriginal string `json:"digestOriginal"`
// Digest is the SHA256 of the compressed blob (OCI layer ID).
Digest string `json:"digest"`
// Size is the compressed size in bytes.
Size int64 `json:"size"`
// SizeUncompressed is the original size in bytes.
SizeUncompressed int64 `json:"sizeUncompressed"`
// MediaType is the OCI layer media type (e.g., application/vnd.cog.weight.layer.v1+gzip).
MediaType string `json:"mediaType"`
// ContentType is the file's MIME type (e.g., application/octet-stream).
ContentType string `json:"contentType,omitempty"`
}
WeightFile represents a single weight file entry in a weights lockfile or manifest. The Name field is an identifier/handle (like a Docker volume name), not a filename.
type WeightPushOptions ¶ added in v0.17.0
type WeightPushOptions struct {
// ProgressFn is an optional callback for reporting upload progress.
ProgressFn func(PushProgress)
// RetryFn is an optional callback for reporting retry attempts.
// Return false to abort the retry.
RetryFn func(WeightRetryEvent) bool
}
WeightPushOptions configures optional behavior for WeightPusher.Push.
type WeightPushResult ¶ added in v0.17.0
type WeightPushResult struct {
// Ref is the full image reference for the pushed weight manifest (e.g., "registry/repo:weights-name-abc123").
Ref string
// Descriptor is the OCI descriptor for the pushed weight manifest.
Descriptor v1.Descriptor
}
WeightPushResult contains the result of pushing a single weight artifact.
type WeightPusher ¶ added in v0.17.0
type WeightPusher struct {
// contains filtered or unexported fields
}
WeightPusher pushes a WeightArtifact as a proper OCI artifact manifest with config blob and tarball layers. The layer blob is pushed via registry.WriteLayer (which supports multipart uploads, progress, and retry), followed by the manifest via PushImage.
func NewWeightPusher ¶ added in v0.17.0
func NewWeightPusher(reg registry.Client) *WeightPusher
NewWeightPusher creates a new WeightPusher.
func (*WeightPusher) Push ¶ added in v0.17.0
func (p *WeightPusher) Push(ctx context.Context, repo string, artifact *WeightArtifact, opts ...WeightPushOptions) (*WeightPushResult, error)
Push pushes a WeightArtifact to the registry as an OCI artifact manifest. The layer blob is pushed first via WriteLayer (multipart uploads, progress, retry), then the manifest is pushed via PushImage. Returns the descriptor of the pushed manifest.
type WeightRetryEvent ¶ added in v0.17.0
type WeightRetryEvent struct {
// Name identifies which file is being retried.
Name string
// Attempt is the current retry attempt number (1-indexed).
Attempt int
// MaxAttempts is the maximum number of retry attempts.
MaxAttempts int
// Err is the error that caused the retry.
Err error
// NextRetryIn is the duration until the next retry attempt.
NextRetryIn time.Duration
}
WeightRetryEvent reports a retry attempt for a weight file upload.
type WeightSpec ¶ added in v0.17.0
type WeightSpec struct {
// Source is the local file path to the weight file.
Source string
// Target is the container mount path for this weight.
Target string
// contains filtered or unexported fields
}
WeightSpec declares a weight artifact to be built. It implements ArtifactSpec.
func NewWeightSpec ¶ added in v0.17.0
func NewWeightSpec(name, source, target string) *WeightSpec
NewWeightSpec creates a WeightSpec with the given name, source path, and target mount path.
func (*WeightSpec) Name ¶ added in v0.17.0
func (s *WeightSpec) Name() string
Name returns the spec's logical name.
func (*WeightSpec) Type ¶ added in v0.17.0
func (s *WeightSpec) Type() ArtifactType
Type returns ArtifactTypeWeight.
type WeightsLock ¶ added in v0.17.0
type WeightsLock struct {
// Version is the lockfile format version.
Version string `json:"version"`
// Created is when the lockfile was generated.
Created time.Time `json:"created"`
// Files are the weight file entries.
Files []WeightFile `json:"files"`
}
WeightsLock represents a weights.lock file that pins weight file metadata. This is a placeholder format that will be replaced by the declarative weights implementation.
func LoadWeightsLock ¶ added in v0.17.0
func LoadWeightsLock(path string) (*WeightsLock, error)
LoadWeightsLock loads a weights.lock file from disk.
func ParseWeightsLock ¶ added in v0.17.0
func ParseWeightsLock(data []byte) (*WeightsLock, error)
ParseWeightsLock parses a weights.lock JSON document.
func (*WeightsLock) Save ¶ added in v0.17.0
func (wl *WeightsLock) Save(path string) error
Save writes the weights.lock to disk.