Documentation
¶
Index ¶
- Constants
- Variables
- func CreateEmptyExt4Disk(diskPath string, sizeBytes int64) error
- func ExportRootfs(rootfsDir, outputPath string, format ExportFormat) (int64, error)
- func GetDiskPath(p *paths.Paths, imageName string, digest string) (string, error)
- func HostPlatformString() string
- func ImageNeedsHostEmulation(platform string) bool
- func IsSystemdImage(entrypoint, cmd []string) bool
- type BuildQueue
- func (q *BuildQueue) ActiveCount() int
- func (q *BuildQueue) Enqueue(imageName string, req CreateImageRequest, startFn func()) int
- func (q *BuildQueue) GetPosition(imageName string) *int
- func (q *BuildQueue) MarkComplete(imageName string)
- func (q *BuildQueue) PendingCount() int
- func (q *BuildQueue) QueueLength() int
- type CreateImageRequest
- type ExportFormat
- type Image
- type Manager
- type ManifestInspector
- type Metrics
- type MirrorRequest
- type MirrorResult
- type NormalizedRef
- func (r *NormalizedRef) Digest() string
- func (r *NormalizedRef) DigestHex() string
- func (r *NormalizedRef) IsDigest() bool
- func (r *NormalizedRef) Repository() string
- func (r *NormalizedRef) Resolve(ctx context.Context, inspector ManifestInspector) (*ResolvedRef, error)
- func (r *NormalizedRef) ResolveDigest(ctx context.Context, inspector ManifestInspector, platform gcr.Platform) (Platform, *ResolvedRef, error)
- func (r *NormalizedRef) ResolveForPlatform(ctx context.Context, inspector ManifestInspector, platform gcr.Platform) (*ResolvedRef, error)
- func (r *NormalizedRef) String() string
- func (r *NormalizedRef) Tag() string
- type OCIClient
- func (c *OCIClient) InspectManifest(ctx context.Context, imageRef string) (string, error)
- func (c *OCIClient) InspectManifestForLinux(ctx context.Context, imageRef string) (string, error)
- func (c *OCIClient) InspectManifestForPlatform(ctx context.Context, imageRef, platform string) (string, error)
- func (c *OCIClient) PullAndUnpack(ctx context.Context, imageRef, digest, exportDir string) error
- func (c *OCIClient) PullAndUnpackForLinux(ctx context.Context, imageRef, digest, exportDir string) error
- type Platform
- type QueuedBuild
- type ResolvedRef
- type StatusEvent
Constants ¶
const ( StatusPending = "pending" StatusPulling = "pulling" StatusConverting = "converting" StatusReady = "ready" StatusFailed = "failed" )
Variables ¶
var ( ErrNotFound = errors.New("image not found") ErrInvalidName = errors.New("invalid image name") ErrInvalidPlatform = errors.New("invalid platform") // ErrPlatformNotAvailable means the requested platform is well-formed but the // image's manifest index does not publish a matching variant. Unlike // ErrInvalidPlatform (bad user syntax), the platform itself is valid; the // image simply does not provide it. ErrPlatformNotAvailable = errors.New("platform not available for image") // ErrRateLimited means the registry rejected the request with a rate-limit // response (e.g. Docker Hub's unauthenticated pull limit). Transient and // caller-actionable (retry later or authenticate), not a server fault. ErrRateLimited = errors.New("registry rate limit exceeded") )
var DefaultImageFormat = func() ExportFormat { if runtime.GOOS == "darwin" { return FormatExt4 } return FormatErofs }()
DefaultImageFormat is the default export format for OCI images. On Linux, we use erofs (compressed, read-only) for smaller images. On Darwin, we use ext4 because the VZ kernel doesn't have erofs support.
Functions ¶
func CreateEmptyExt4Disk ¶
CreateEmptyExt4Disk creates a sparse disk file and formats it as ext4. Used for volumes and instance overlays that need empty writable filesystems.
func ExportRootfs ¶
func ExportRootfs(rootfsDir, outputPath string, format ExportFormat) (int64, error)
ExportRootfs exports rootfs directory in specified format (public for system manager)
func GetDiskPath ¶
GetDiskPath returns the filesystem path to an image's rootfs disk file (public for instances manager)
func HostPlatformString ¶ added in v0.1.1
func HostPlatformString() string
HostPlatformString renders the host platform as a canonical "os/arch" string. Exposed so the instances layer can resolve a no-platform create to the host variant explicitly rather than following a last-pull-wins tag pointer.
func ImageNeedsHostEmulation ¶ added in v0.1.1
ImageNeedsHostEmulation reports whether an image whose stored platform string is platform requires CPU emulation to run on this host (its architecture differs from the host architecture). An empty platform is treated as the host platform. Exposed for the instances layer's boot-time emulation derivation.
func IsSystemdImage ¶
IsSystemdImage checks if the image's CMD indicates it wants systemd as init. Detection is based on the effective command (entrypoint + cmd), not whether systemd is installed in the image.
Returns true if the image's command is:
- /sbin/init
- /lib/systemd/systemd
- /usr/lib/systemd/systemd
Types ¶
type BuildQueue ¶
type BuildQueue struct {
// contains filtered or unexported fields
}
BuildQueue manages concurrent image builds with a configurable limit
func NewBuildQueue ¶
func NewBuildQueue(maxConcurrent int) *BuildQueue
func (*BuildQueue) ActiveCount ¶
func (q *BuildQueue) ActiveCount() int
ActiveCount returns number of actively building images
func (*BuildQueue) Enqueue ¶
func (q *BuildQueue) Enqueue(imageName string, req CreateImageRequest, startFn func()) int
Enqueue adds a build to the queue. Returns queue position (0 if started immediately, >0 if queued). If the image is already building or queued, returns its current position without re-enqueueing.
func (*BuildQueue) GetPosition ¶
func (q *BuildQueue) GetPosition(imageName string) *int
func (*BuildQueue) MarkComplete ¶
func (q *BuildQueue) MarkComplete(imageName string)
func (*BuildQueue) PendingCount ¶
func (q *BuildQueue) PendingCount() int
PendingCount returns number of queued builds
func (*BuildQueue) QueueLength ¶
func (q *BuildQueue) QueueLength() int
QueueLength returns the total number of builds (active + pending)
type CreateImageRequest ¶
type CreateImageRequest struct {
Name string
Tags tags.Tags
// Platform selects which platform variant of a multi-arch image to pull as
// os/arch[/variant] (e.g., linux/amd64). Empty means the host platform.
Platform string
}
CreateImageRequest represents a request to create an image
type ExportFormat ¶
type ExportFormat string
ExportFormat defines supported rootfs export formats
const ( FormatExt4 ExportFormat = "ext4" // Read-only ext4 (legacy, used on Darwin) FormatErofs ExportFormat = "erofs" // Read-only compressed with LZ4 (default on Linux) FormatCpio ExportFormat = "cpio" // Uncompressed archive (initrd, fast boot) )
type Image ¶
type Image struct {
Name string // Normalized ref (e.g., docker.io/library/alpine:latest)
Digest string // Resolved manifest digest (sha256:...)
Platform string // Normalized platform (e.g., linux/amd64)
Status string
QueuePosition *int
Error *string
SizeBytes *int64
Entrypoint []string
Cmd []string
Env map[string]string
Labels map[string]string
Tags tags.Tags
WorkingDir string
CreatedAt time.Time
}
Image represents a container image converted to bootable disk
type Manager ¶
type Manager interface {
ListImages(ctx context.Context) ([]Image, error)
CreateImage(ctx context.Context, req CreateImageRequest) (*Image, error)
// ImportLocalImage imports an image that was pushed to the local OCI cache.
// Unlike CreateImage, it does not resolve from a remote registry.
ImportLocalImage(ctx context.Context, repo, reference, digest string) (*Image, error)
GetImage(ctx context.Context, name string) (*Image, error)
DeleteImage(ctx context.Context, name string) error
RecoverInterruptedBuilds()
// TotalImageBytes returns the total size of all ready images on disk.
// Used by the resource manager for disk capacity tracking.
TotalImageBytes(ctx context.Context) (int64, error)
// TotalOCICacheBytes returns the total size of the OCI layer cache.
// Used by the resource manager for disk capacity tracking.
TotalOCICacheBytes(ctx context.Context) (int64, error)
// WaitForReady blocks until the image identified by name reaches a terminal
// state (ready or failed) or the context is cancelled.
WaitForReady(ctx context.Context, name string) error
}
type ManifestInspector ¶
type ManifestInspector interface {
// contains filtered or unexported methods
}
Resolve inspects the manifest to get the digest and returns a ResolvedRef. This requires an ociClient interface for manifest inspection.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics holds the metrics instruments for image operations.
type MirrorRequest ¶ added in v0.0.6
type MirrorRequest struct {
// SourceImage is the full image reference to pull from (e.g., "docker.io/onkernel/nodejs22-base:0.1.1")
SourceImage string
// Platform selects which platform variant to mirror as os/arch[/variant]
// (e.g., linux/amd64). Empty means the host platform.
Platform string
}
MirrorRequest contains the parameters for mirroring a base image
type MirrorResult ¶ added in v0.0.6
type MirrorResult struct {
// SourceImage is the original image reference
SourceImage string `json:"source_image"`
// LocalRef is the local registry reference (e.g., "onkernel/nodejs22-base:0.1.1")
LocalRef string `json:"local_ref"`
// Digest is the image digest
Digest string `json:"digest"`
}
MirrorResult contains the result of a mirror operation
func MirrorBaseImage ¶ added in v0.0.6
func MirrorBaseImage(ctx context.Context, registryURL string, req MirrorRequest, authConfig *authn.AuthConfig) (*MirrorResult, error)
MirrorBaseImage pulls an image from an external registry and pushes it to the local registry with the same normalized name. This enables Dockerfile FROM rewriting to use locally mirrored base images instead of pulling from Docker Hub.
For example, mirroring "docker.io/onkernel/nodejs22-base:0.1.1" will create "onkernel/nodejs22-base:0.1.1" in the local registry.
type NormalizedRef ¶
type NormalizedRef struct {
// contains filtered or unexported fields
}
NormalizedRef is a validated and normalized OCI image reference. It can be either a tagged reference (e.g., "docker.io/library/alpine:latest") or a digest reference (e.g., "docker.io/library/alpine@sha256:abc123...").
func ParseNormalizedRef ¶
func ParseNormalizedRef(s string) (*NormalizedRef, error)
ParseNormalizedRef validates and normalizes a user-provided image reference. Examples:
- "alpine" -> "docker.io/library/alpine:latest"
- "alpine:3.18" -> "docker.io/library/alpine:3.18"
- "alpine@sha256:abc..." -> "docker.io/library/alpine@sha256:abc..."
func (*NormalizedRef) Digest ¶
func (r *NormalizedRef) Digest() string
Digest returns the digest if present (e.g., "sha256:abc123..."). Returns empty string if this is a tagged reference.
func (*NormalizedRef) DigestHex ¶
func (r *NormalizedRef) DigestHex() string
DigestHex returns just the hex portion of the digest (without "sha256:" prefix). Returns empty string if this is a tagged reference.
func (*NormalizedRef) IsDigest ¶
func (r *NormalizedRef) IsDigest() bool
IsDigest returns true if this reference contains a digest (@sha256:...).
func (*NormalizedRef) Repository ¶
func (r *NormalizedRef) Repository() string
Repository returns the repository path without tag or digest. Example: "docker.io/library/alpine"
func (*NormalizedRef) Resolve ¶
func (r *NormalizedRef) Resolve(ctx context.Context, inspector ManifestInspector) (*ResolvedRef, error)
Resolve returns a ResolvedRef by inspecting the manifest to get the authoritative digest.
TODO(followup) kernel/hypeman#283: Resolve and ResolveForPlatform are near-duplicates (platform-less vs platform-aware manifest inspection); consider unifying them behind one path.
func (*NormalizedRef) ResolveDigest ¶ added in v0.1.1
func (r *NormalizedRef) ResolveDigest(ctx context.Context, inspector ManifestInspector, platform gcr.Platform) (Platform, *ResolvedRef, error)
ResolveDigest resolves a digest-pinned reference for the requested platform. It returns the platform the resolved image declares (for --platform validation) and a ResolvedRef carrying the resolved child digest (so an index pin dedups and is addressable by the same child digest as the equivalent tag pull, rather than by the index digest). r must be a digest ref.
func (*NormalizedRef) ResolveForPlatform ¶ added in v0.1.1
func (r *NormalizedRef) ResolveForPlatform(ctx context.Context, inspector ManifestInspector, platform gcr.Platform) (*ResolvedRef, error)
ResolveForPlatform returns a ResolvedRef for the manifest matching platform.
func (*NormalizedRef) String ¶
func (r *NormalizedRef) String() string
String returns the full normalized reference.
func (*NormalizedRef) Tag ¶
func (r *NormalizedRef) Tag() string
Tag returns the tag if this is a tagged reference (e.g., "latest"). Returns empty string if this is a digest reference.
type OCIClient ¶
type OCIClient struct {
// contains filtered or unexported fields
}
OCIClient is a public wrapper for system manager to use OCI operations
func NewOCIClient ¶
NewOCIClient creates a new OCI client (public for system manager)
func (*OCIClient) InspectManifest ¶
InspectManifest inspects a remote image to get its digest (public for system manager). Always targets Linux platform since hypeman VMs are Linux guests.
func (*OCIClient) InspectManifestForLinux ¶ added in v0.0.6
InspectManifestForLinux is an alias for InspectManifest (all images target Linux)
func (*OCIClient) InspectManifestForPlatform ¶ added in v0.1.1
func (c *OCIClient) InspectManifestForPlatform(ctx context.Context, imageRef, platform string) (string, error)
InspectManifestForPlatform inspects a remote image to get the digest for a specific platform variant. Empty platform uses the host platform.
func (*OCIClient) PullAndUnpack ¶
PullAndUnpack pulls an OCI image and unpacks it to a directory (public for system manager). Always targets Linux platform since hypeman VMs are Linux guests.
type Platform ¶ added in v0.1.1
Platform identifies the OS/architecture variant of an image, modeled on Docker's --platform (os/arch[/variant]). Hypeman guests are always Linux, so OS is currently constrained to "linux", but the field exists for parity with Docker references and future non-Linux support.
func ParsePlatform ¶ added in v0.1.1
ParsePlatform parses a Docker-style platform string of the form "os/arch[/variant]". A bare architecture ("amd64") defaults OS to "linux". The result is normalized (lowercased, common aliases mapped).
func (Platform) Matches ¶ added in v0.1.1
Matches reports whether two platforms identify the same guest OS and CPU architecture. Variant is intentionally ignored because Hypeman currently supports amd64 and arm64 only, where variant does not affect boot/emulation.
func (Platform) Normalize ¶ added in v0.1.1
Normalize lowercases the fields and maps common architecture aliases (x86_64 -> amd64, aarch64 -> arm64) so equality checks are reliable.
type QueuedBuild ¶
type QueuedBuild struct {
ImageName string
Request CreateImageRequest
StartFn func()
}
type ResolvedRef ¶
type ResolvedRef struct {
// contains filtered or unexported fields
}
ResolvedRef is a NormalizedRef that has been resolved to include the actual manifest digest from the registry. The digest is always present.
func NewResolvedRef ¶
func NewResolvedRef(normalized *NormalizedRef, digest string) *ResolvedRef
NewResolvedRef creates a ResolvedRef from a NormalizedRef and digest.
func (*ResolvedRef) Digest ¶
func (r *ResolvedRef) Digest() string
Digest returns the resolved manifest digest (e.g., "sha256:abc123..."). This is always populated after resolution.
func (*ResolvedRef) DigestHex ¶
func (r *ResolvedRef) DigestHex() string
DigestHex returns just the hex portion of the digest (without "sha256:" prefix).
func (*ResolvedRef) Repository ¶
func (r *ResolvedRef) Repository() string
Repository returns the repository path without tag or digest. Example: "docker.io/library/alpine"
func (*ResolvedRef) String ¶
func (r *ResolvedRef) String() string
String returns the full normalized reference (the original user input format).
func (*ResolvedRef) Tag ¶
func (r *ResolvedRef) Tag() string
Tag returns the tag if this was originally a tagged reference (e.g., "latest"). Returns empty string if this was originally a digest reference.
type StatusEvent ¶ added in v0.0.7
StatusEvent represents a terminal status change for image readiness notifications.