Documentation
¶
Overview ¶
pkg/model/index.go
pkg/model/pusher.go
pkg/model/weights_lock.go
Index ¶
- Constants
- Variables
- func OCIIndexEnabled() bool
- func WeightTag(name, digest string) string
- type Artifact
- type ArtifactSpec
- type ArtifactType
- type BuildBaseOptions
- 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 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 Pusher
- type Ref
- type RemoteRef
- type Resolver
- func (r *Resolver) Build(ctx context.Context, src *Source, opts BuildOptions) (*Model, error)
- func (r *Resolver) BuildBase(ctx context.Context, src *Source, opts BuildBaseOptions) (*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 WeightPushProgress
- 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 (
// 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 OCIIndexEnabled ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (t ArtifactType) String() string
String returns the human-readable name of the artifact type.
type BuildBaseOptions ¶
type BuildBaseOptions struct {
// UseCudaBaseImage controls CUDA base image usage: "auto", "true", or "false".
UseCudaBaseImage string
// UseCogBaseImage controls cog base image usage. nil means auto-detect.
UseCogBaseImage *bool
// ProgressOutput controls build output format: "auto", "plain", or "tty".
ProgressOutput string
// RequiresCog indicates whether the build requires cog to be installed.
RequiresCog bool
}
BuildBaseOptions contains settings for building a base image (dev mode). Base images don't copy /src - the source is mounted as a volume at runtime.
func (BuildBaseOptions) WithDefaults ¶
func (o BuildBaseOptions) WithDefaults() BuildBaseOptions
WithDefaults returns a copy of BuildBaseOptions with defaults applied.
type BuildOptions ¶
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
}
BuildOptions contains all settings for building a Cog image. This consolidates the many parameters previously passed to image.Build().
func (BuildOptions) WithDefaults ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func NewBundlePusher(docker command.Command, reg registry.Client) *BundlePusher
NewBundlePusher creates a new BundlePusher.
func (*BundlePusher) Push ¶
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 ¶
type DockerfileFactory struct {
// contains filtered or unexported fields
}
DockerfileFactory wraps existing Dockerfile-based build.
func (*DockerfileFactory) Build ¶
func (f *DockerfileFactory) Build(ctx context.Context, src *Source, opts BuildOptions) (*ImageArtifact, error)
Build delegates to the existing image.Build() function.
func (*DockerfileFactory) BuildBase ¶
func (f *DockerfileFactory) BuildBase(ctx context.Context, src *Source, opts BuildBaseOptions) (*ImageArtifact, error)
BuildBase delegates to the existing image.BuildBase() function.
func (*DockerfileFactory) Name ¶
func (f *DockerfileFactory) Name() string
Name returns the factory name.
type Factory ¶
type Factory interface {
// Build creates a Docker image from source and returns ImageArtifact metadata.
Build(ctx context.Context, src *Source, opts BuildOptions) (*ImageArtifact, error)
// BuildBase creates a base image for dev mode (without /src copied).
// The source directory is expected to be mounted as a volume at runtime.
BuildBase(ctx context.Context, src *Source, opts BuildBaseOptions) (*ImageArtifact, error)
// Name returns the factory name for logging/debugging.
Name() string
}
Factory is the build backend interface. Different implementations handle different build strategies.
func DefaultFactory ¶
DefaultFactory returns a Factory based on environment variables. It checks COG_BUILDER and COGPACK to select the appropriate backend.
TODO: When FrontendFactory is implemented, check COG_BUILDER env var. TODO: When CogpacksFactory is implemented, check COGPACK env var.
type ImageArtifact ¶
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 ¶
func NewImageArtifact(name string, desc v1.Descriptor, reference string) *ImageArtifact
NewImageArtifact creates an ImageArtifact from a build result.
func (*ImageArtifact) CogVersion ¶
func (a *ImageArtifact) CogVersion() string
CogVersion returns the Cog version that built this image, or empty string if not set.
func (*ImageArtifact) Config ¶
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 ¶
func (a *ImageArtifact) Descriptor() v1.Descriptor
Descriptor returns the OCI descriptor for this image.
func (*ImageArtifact) IsCogModel ¶
func (a *ImageArtifact) IsCogModel() bool
IsCogModel returns true if this image has Cog labels indicating it's a Cog model.
func (*ImageArtifact) Name ¶
func (a *ImageArtifact) Name() string
Name returns the artifact's logical name.
func (*ImageArtifact) OpenAPISchema ¶
func (a *ImageArtifact) OpenAPISchema() string
OpenAPISchema returns the OpenAPI schema stored in image labels, or empty string if not set.
func (*ImageArtifact) ParsedConfig ¶
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 ¶
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 ¶
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 ¶
func (a *ImageArtifact) Type() ArtifactType
Type returns ArtifactTypeImage.
type ImageBuilder ¶
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 ¶
func NewImageBuilder(factory Factory, docker command.Command, source *Source, opts BuildOptions) *ImageBuilder
NewImageBuilder creates an ImageBuilder.
func (*ImageBuilder) Build ¶
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 ImagePusher ¶
type ImagePusher struct {
// contains filtered or unexported fields
}
ImagePusher pushes container images using docker push.
func NewImagePusher ¶
func NewImagePusher(docker command.Command) *ImagePusher
NewImagePusher creates a new ImagePusher.
func (*ImagePusher) Push ¶
func (p *ImagePusher) Push(ctx context.Context, m *Model, opts PushOptions) error
Push pushes the model image to a registry. This implements the Pusher interface for backwards compatibility with Resolver.Push().
func (*ImagePusher) PushArtifact ¶
func (p *ImagePusher) PushArtifact(ctx context.Context, artifact *ImageArtifact) error
PushArtifact pushes a single image artifact by reference. This is the artifact-aware method used by BundlePusher in Phase 4.
type ImageSource ¶
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 ¶
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 ¶
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.
type ImageSpecOption ¶
type ImageSpecOption func(*ImageSpec)
ImageSpecOption configures optional fields on ImageSpec.
func WithImageNoCache ¶
func WithImageNoCache(noCache bool) ImageSpecOption
WithImageNoCache disables build cache for the image build.
func WithImageSecrets ¶
func WithImageSecrets(secrets []string) ImageSpecOption
WithImageSecrets sets build-time secrets for the image build.
type Index ¶
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 ¶
type IndexBuilder struct {
// contains filtered or unexported fields
}
IndexBuilder builds an OCI Image Index from pre-pushed manifest descriptors.
func NewIndexBuilder ¶
func NewIndexBuilder() *IndexBuilder
NewIndexBuilder creates a new index builder.
func (*IndexBuilder) AddWeightDescriptor ¶
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 ¶
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 ¶
func (b *IndexBuilder) SetImageDescriptor(desc v1.Descriptor, platform *v1.Platform)
SetImageDescriptor sets the image manifest descriptor.
type IndexManifest ¶
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 ¶
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 ¶
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 ¶
func (m *Model) ArtifactsByType(t ArtifactType) []Artifact
ArtifactsByType returns all artifacts matching the given type.
func (*Model) GetImageArtifact ¶
func (m *Model) GetImageArtifact() *ImageArtifact
GetImageArtifact returns the first ImageArtifact from the artifacts collection, or nil if none exists.
func (*Model) SchemaJSON ¶
SchemaJSON returns the OpenAPI schema as JSON bytes, or nil if no schema.
func (*Model) WeightArtifacts ¶
func (m *Model) WeightArtifacts() []*WeightArtifact
WeightArtifacts returns all WeightArtifact instances from the artifacts collection.
type Option ¶
type Option func(*options)
Option configures how Resolver methods behave.
func LocalOnly ¶
func LocalOnly() Option
LocalOnly loads only from the local docker daemon. Returns an error if the image is not found locally.
func PreferLocal ¶
func PreferLocal() Option
PreferLocal tries local docker daemon first, falls back to remote on not-found.
func PreferRemote ¶
func PreferRemote() Option
PreferRemote tries remote registry first, falls back to local on not-found. This is the default behavior.
func RemoteOnly ¶
func RemoteOnly() Option
RemoteOnly loads only from the remote registry. Does not check the local docker daemon.
func WithPlatform ¶
WithPlatform sets the platform for remote registry queries.
type ParseOption ¶
type ParseOption func(*parseOptions)
ParseOption configures how image references are parsed.
func Insecure ¶
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 ¶
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 ¶
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 ¶
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 ¶
func ParseRef(ref string, opts ...ParseOption) (*ParsedRef, error)
ParseRef validates and parses an image reference.
func (*ParsedRef) Digest ¶
Digest returns the digest (e.g., "sha256:...") or empty string if this is a tag reference.
func (*ParsedRef) IsReplicate ¶
IsReplicate returns true if the registry is the Replicate registry (r8.im).
func (*ParsedRef) Repository ¶
Repository returns the repository path (e.g., "user/model", "library/nginx").
type PushOptions ¶
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
}
PushOptions configures push behavior.
type Pusher ¶
type Pusher interface {
Push(ctx context.Context, m *Model, opts PushOptions) error
}
Pusher handles pushing a model to a registry.
type Ref ¶
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 ¶
type RemoteRef struct {
Parsed *ParsedRef
}
RemoteRef resolves an image from a remote registry only. It will not check the local docker daemon.
func FromRemote ¶
FromRemote parses and validates a reference for remote resolution. Returns an error immediately if the reference is invalid.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver orchestrates building and loading Models.
func NewResolver ¶
NewResolver creates a Resolver with the default factory.
func (*Resolver) BuildBase ¶
func (r *Resolver) BuildBase(ctx context.Context, src *Source, opts BuildBaseOptions) (*Model, error)
BuildBase creates a base image for dev mode (without /src copied). The source directory is expected to be mounted as a volume at runtime. Returns a Model with the built image info and the source config.
NOTE: Unlike Build(), this does not use ImageBuilder because base images don't have labels yet (they're added during full builds). The returned ImageArtifact has no labels, no descriptor, and no inspect results.
func (*Resolver) Inspect ¶
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 ¶
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 ¶
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 ¶
Push pushes a Model to a container registry. TODO(md): The OCIIndex gate is temporary. When true, pushes an OCI Image Index with weight artifacts. When false, does a plain docker push. Remove the gate once index pushes are validated with all registries.
func (*Resolver) Resolve ¶
Resolve resolves any Ref to a Model. This is the main entry point for declarative model resolution.
func (*Resolver) WithFactory ¶
WithFactory sets a custom factory and returns the Resolver for chaining.
type Source ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func NewWeightArtifact(name string, desc v1.Descriptor, filePath, target string, cfg WeightConfig) *WeightArtifact
NewWeightArtifact creates a WeightArtifact from a build result.
func (*WeightArtifact) Descriptor ¶
func (a *WeightArtifact) Descriptor() v1.Descriptor
Descriptor returns the OCI descriptor for this weight artifact.
func (*WeightArtifact) Name ¶
func (a *WeightArtifact) Name() string
Name returns the artifact's logical name.
func (*WeightArtifact) Type ¶
func (a *WeightArtifact) Type() ArtifactType
Type returns ArtifactTypeWeight.
type WeightBuilder ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
type WeightPushOptions struct {
// ProgressFn is an optional callback for reporting upload progress.
ProgressFn func(WeightPushProgress)
// 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 WeightPushProgress ¶
type WeightPushProgress struct {
// Complete is the number of bytes uploaded so far.
Complete int64
// Total is the total number of bytes to upload.
Total int64
}
WeightPushProgress reports progress for a weight artifact upload.
type WeightPushResult ¶
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 ¶
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 ¶
func NewWeightPusher(reg registry.Client) *WeightPusher
NewWeightPusher creates a new WeightPusher.
func (*WeightPusher) Push ¶
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 ¶
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 ¶
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 ¶
func NewWeightSpec(name, source, target string) *WeightSpec
NewWeightSpec creates a WeightSpec with the given name, source path, and target mount path.
type WeightsLock ¶
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 ¶
func LoadWeightsLock(path string) (*WeightsLock, error)
LoadWeightsLock loads a weights.lock file from disk.
func ParseWeightsLock ¶
func ParseWeightsLock(data []byte) (*WeightsLock, error)
ParseWeightsLock parses a weights.lock JSON document.
func (*WeightsLock) Save ¶
func (wl *WeightsLock) Save(path string) error
Save writes the weights.lock to disk.