Documentation
¶
Index ¶
- Constants
- Variables
- func CheckMachineFiles(paths ...string) error
- func ClassifyRegistryError(err error) error
- func ConvertRawToASIF(ctx context.Context, src, dst string) error
- func CreateEmptyExt4Disk(diskPath string, sizeBytes int64) error
- func ExportRootfs(rootfsDir, outputPath string, format ExportFormat) (int64, error)
- func ExportRootfsWithContext(ctx context.Context, 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
- func MacOSDiskChain(p *paths.Paths, imageName, digest string) ([]string, error)
- func MacOSDiskLayerFile(i int) string
- func MacOSMachineLabels() map[string]string
- func OpenMacOSDiskChain(chain []string) (*diskimagekit.DiskImage, error)
- func RequireClosedFile(ctx context.Context, path string) error
- type CreateImageRequest
- type ExportFormat
- type Image
- type MacOSImage
- 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) 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 ResolvedRef
- type StatusEvent
Constants ¶
const ( MacOSMachineVersionLabel = "io.hypeman.machine-image.version" MacOSMachineKindLabel = "io.hypeman.machine-image.kind" MacOSMachineDiskLabel = "io.hypeman.machine-image.disk-path" MacOSMachineFormatLabel = "io.hypeman.machine-image.disk-format" MacOSMachineAuxLabel = "io.hypeman.machine-image.aux-path" MacOSMachinePlatformLabel = "io.hypeman.machine-image.platform-path" // MacOSMachineDiskDigestsLabel lists the sha256 of each layer's disk file, base // first, comma-separated. A publication over a base checks its layers against it. MacOSMachineDiskDigestsLabel = "io.hypeman.machine-image.disk-digests" )
const ( MacOSMachineVersion = "2" MacOSMachineKind = "macos-image" MacOSMachineFormat = "asif" MacOSMachineDiskFile = "disk.asif" MacOSMachineAuxFile = "aux.img" MacOSMachinePlatformFile = "config.json" )
The fixed label values of a macOS machine image, and the file names a published image uses in each layer.
const ( StatusPending = "pending" StatusPulling = "pulling" StatusConverting = "converting" StatusReady = "ready" StatusFailed = "failed" DefaultBorrowedCredentialsTimeout = 30 * time.Minute )
const RateLimitMessage = "registry rate limit exceeded; retry later or authenticate to the registry"
RateLimitMessage is the actionable response returned to API clients when a registry rejects an image request because its rate limit was exceeded.
Variables ¶
var ( ErrNotFound = errors.New("image not found") ErrInvalidName = errors.New("invalid image name") ErrInvalidPlatform = errors.New("invalid platform") ErrImageNotReady = errors.New("image is not ready") // 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") ErrBorrowedCredentialsExpired = errors.New("credentialed image pull expired or was interrupted; submit POST /images again with fresh credentials") ErrCredentialConflict = errors.New("image pull already in flight with different credentials") )
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 CheckMachineFiles ¶ added in v0.4.0
CheckMachineFiles requires each path to be a nonempty regular file, not a symlink, and no two to be the same file. Inodes are compared: different hardlink names do not establish distinctness.
func ClassifyRegistryError ¶ added in v0.4.0
ClassifyRegistryError classifies a raw registry/go-containerregistry error into a typed hypeman error so the API layer can map it to an appropriate 4xx/429 status instead of a blanket 500. Errors that don't match a known client- or registry-condition are returned unchanged (and surface as 500).
Transport errors are matched by their typed fields (HTTP status and registry error codes). Message text is only consulted for non-transport errors, so the request URL embedded in a transport error (host, port, tag, digest) can never influence the classification.
func ConvertRawToASIF ¶ added in v0.4.0
ConvertRawToASIF writes a raw disk into a new ASIF image at dst with the same logical size. All-zero chunks are skipped, so they stay unallocated.
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 ExportRootfsWithContext ¶ added in v0.4.0
func ExportRootfsWithContext(ctx context.Context, rootfsDir, outputPath string, format ExportFormat) (int64, error)
ExportRootfsWithContext exports rootfs directory and cancels external formatters with ctx.
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
func MacOSDiskChain ¶ added in v0.4.0
MacOSDiskChain returns the boot disk chain of a ready macOS image, base first.
func MacOSDiskLayerFile ¶ added in v0.4.0
MacOSDiskLayerFile names the ith file of a macOS boot disk chain, in an image or an instance. The chain is ASIF: disk.0.asif is the base and each later file is an overlay on the one before it. A pulled image has one file per OCI layer; an imported image has one.
func MacOSMachineLabels ¶ added in v0.4.0
MacOSMachineLabels returns the labels of a macOS machine image that uses the standard file names.
func OpenMacOSDiskChain ¶ added in v0.4.0
func OpenMacOSDiskChain(chain []string) (*diskimagekit.DiskImage, error)
OpenMacOSDiskChain opens an ASIF chain read-only, base first. Each layer must name the one below it as its parent.
Types ¶
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
// Credentials are borrowed for this request's registry operations only.
// They intentionally have no JSON representation and must never be persisted.
Credentials *authn.AuthConfig `json:"-"`
}
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)
MacOS *MacOSImage // Non-nil for locally imported macOS disk images
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 MacOSImage ¶ added in v0.4.0
type MacOSImage struct {
HardwareModel []byte `json:"hardware_model"`
MachineIdentifier []byte `json:"machine_identifier"`
MAC string `json:"mac"`
CPUs uint `json:"cpus"`
Memory uint64 `json:"memory"`
// GuestAgent declares a provisioned system GuestService on vsock 2222.
// Readiness is probed separately; old templates remain unmanaged.
GuestAgent bool `json:"guest_agent,omitempty"`
}
MacOSImage is a cold-boot template. Identity is preserved; until rekeying is validated, only one instance with this identifier may run at a time.
func (MacOSImage) Validate ¶ added in v0.4.0
func (m MacOSImage) Validate() error
Validate checks the platform fields every macOS bundle must carry, whether it arrives as a local import or as an OCI machine image.
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)
// TagImage creates or updates a local tag pointing at an existing ready
// image, without pulling or reconverting. Source and target may be in
// different repositories.
TagImage(ctx context.Context, source, target 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 and materialized layer caches.
// 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) 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]). Linux supports OCI container pulls; darwin/arm64 identifies locally imported macOS disk bundles.
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 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) DigestRef ¶ added in v0.4.0
func (r *ResolvedRef) DigestRef() string
DigestRef returns the repository pinned to the resolved manifest digest.
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.