Documentation
¶
Index ¶
Constants ¶
const SchemaVersion = 1
Variables ¶
This section is empty.
Functions ¶
func BuildManifest ¶
func BuildManifest(cfg BuildConfig) string
BuildManifest constructs a Nanos manifest that includes the main program and any additional package files. Guest paths with directory separators (e.g. "lib/x86_64-linux-gnu/libc.so.6" from ops sysroot packages) are serialized as nested nodes — the Nanos manifest parser treats '/' as an unknown discriminator and rejects flat slash-separated keys. cfg.Entrypoint, if non-empty, is emitted as arguments:(0:/program 1:/<entrypoint> ...) so that the runtime interpreter (e.g. node, python) receives its own path as argv[0] and the script path as argv[1] on startup. cfg.Args, if non-empty, is appended after the entrypoint (or starting at argv[1] if cfg.Entrypoint is empty) — used by lang="raw" builds to pass arguments such as ["-jar", "/app.jar"] to the resolved program. The Nanos tuple parser reads '(' as a tuple of name:value pairs — not a bare value list — so arguments must use integer-string keys rather than e.g. ("/<entrypoint>"). cfg.Env entries are emitted as environment:(KEY:val ...) sorted by key. Static network config is not baked into the manifest: the daemon injects the assigned TAP IP at run time (QEMU fw_cfg or Firecracker boot args).
func DigestSHA256 ¶
DigestSHA256 returns the sha256 digest string for data in "sha256:<hex>" form.
Types ¶
type BuildConfig ¶
type BuildConfig struct {
// Name is the image name (e.g. "hello").
Name string
// Tag is the image tag (default "latest" if empty).
Tag string
// BinaryPath is the path to the static ELF binary to package.
BinaryPath string
// ProgramPath, when non-empty, is the in-image guest path at which the
// program is placed and from which it is executed (e.g.
// "usr/local/postgresql/bin/postgres"). The Nanos manifest's program field,
// argv[0], and /proc/self/exe all resolve to this path, so binaries that
// locate their installation prefix relative to their own executable (e.g.
// postgres) and binaries with $ORIGIN-relative RPATHs resolve correctly.
// Empty places the program flat at /program (the default for compiled and
// interpreted-runtime builds, where the layout is irrelevant).
ProgramPath string
// MkfsRun invokes mkfs to produce the disk image.
// Use internal/tools.ResolveMkfs to obtain a platform-appropriate func.
MkfsRun MkfsFunc
// Memory is the default VM memory string (e.g. "256M").
Memory string
// CPUs is the default number of virtual CPUs.
CPUs int
// PkgFiles is a list of package files to include in the image.
// Each entry carries both the host path (on the build machine) and the
// guest path (inside the Nanos image). For jerboa packages, GuestPath is
// typically filepath.Base(HostPath). For ops packages, GuestPath
// preserves the sysroot/ hierarchy (e.g. "lib/x86_64-linux-gnu/libc.so").
PkgFiles []pkg.File
// Entrypoint is the script or file to pass as the first argument to the
// runtime binary (e.g. "hi.js" for Node.js). Empty for compiled languages.
// Emitted with a leading "/" (image-root-relative).
Entrypoint string
// Args holds additional argv elements appended after Entrypoint (if set).
// Used by lang="raw" builds to pass arguments to the resolved program
// (e.g. ["-jar", "/app.jar"]). Each element is emitted as-is — use
// absolute in-image paths for file arguments.
Args []string
// Env holds runtime environment variables to bake into the image manifest.
// Sourced from ops package.manifest Env fields and language driver output.
Env map[string]string
// Port is the service port declared for the image. It is metadata only:
// network config is injected at run time (fw_cfg / boot args), not baked
// into the manifest.
Port int
// Ports holds default host:guest port-publish specs (from [run] ports).
// Stored in the image manifest and applied at run time when the VM joins a
// network and no -p flag is given.
Ports []string
// DiskSize is the minimum image file size passed to mkfs (e.g. "512M", "1G").
// When non-empty, emitted as imagesize in the Nanos manifest so mkfs pads
// the image to at least that size, leaving free space for runtime writes.
DiskSize string
// Output is where mkfs subprocess output is written. Nil defaults to os.Stderr.
Output io.Writer
}
BuildConfig holds the parameters for building a unikernel image.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder produces unikernel images from ELF binaries and stores them.
func NewBuilder ¶
NewBuilder returns a Builder that stores images in store.
type Config ¶
type Config struct {
// Memory is the default QEMU memory string (e.g. "256M").
Memory string `json:"memory"`
// CPUs is the default number of virtual CPUs.
CPUs int `json:"cpus"`
// Env is the list of environment variables passed to the application.
Env []string `json:"env,omitempty"`
// Ports holds default host:guest port-publish specs (from [run] ports in
// unikernel.toml). They are applied at run time when the VM joins a network
// and no -p flag is given, so an image can declare the ports it serves.
Ports []string `json:"ports,omitempty"`
}
Config holds default VM launch parameters for an image.
type Manifest ¶
type Manifest struct {
// SchemaVersion must equal SchemaVersion (1).
SchemaVersion int `json:"schemaVersion"`
// Name is the image name (e.g. "hello").
Name string `json:"name"`
// Tag is the image tag (e.g. "latest").
Tag string `json:"tag"`
// Created is the build timestamp.
Created time.Time `json:"created"`
// Config holds default VM parameters.
Config Config `json:"config"`
// DiskDigest is the sha256 digest of the raw disk image ("sha256:<hex>").
DiskDigest string `json:"diskDigest"`
// DiskSize is the byte size of the raw disk image.
DiskSize int64 `json:"diskSize"`
}
Manifest describes a unikernel disk image.
type MkfsFunc ¶
MkfsFunc creates an exec.Cmd that runs mkfs to package binaryPath into imgPath. manifest is the Nanos manifest string to pass on stdin. Defined here so callers can satisfy it without importing internal/tools.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a content-addressable local image store.
Layout on disk:
<root>/
<sha256>/
manifest.json
disk.img
refs.json (name:tag → sha256)
func (*Store) Get ¶
Get returns the manifest and disk image path for ref (name:tag or sha256:<hex>).