pkg

package
v0.51.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package package manages pre-built runtime packages for unikernel images.

A package is a named, versioned collection of files (typically a language runtime like Node.js or Python) that can be included in a unikernel image during "jerboa build --pkg". Packages are stored locally in ~/.jerboa/packages/<name>/<version>/ and are downloaded from a remote index.

Index

Constants

This section is empty.

Variables

View Source
var IndexURL = "https://github.com/AitorConS/jerboa/releases/download/pkg-index/packages.json"

IndexURL is the base URL for the package index. Can be overridden in tests to point to a local server.

View Source
var OpsPackageBaseURL = "https://repo.ops.city/v2/packages"

OpsPackageBaseURL is the base URL for downloading ops packages.

View Source
var OpsPackageManifestURL = "https://repo.ops.city/v2/manifest.json"

OpsPackageManifestURL stores info about all ops packages.

View Source
var OpsPkghubBaseURL = "https://repo.ops.city"

OpsPkghubBaseURL is the base URL of the ops package hub.

Functions

func ArchSlug

func ArchSlug() string

ArchSlug returns the architecture suffix used by ops packages.

func FromDocker

func FromDocker(image, containerPath string, extraLibs []string) ([]string, error)

FromDocker extracts a binary and its shared library dependencies from a Docker image, returning the local file paths. It uses "docker run --rm sh -c cat" to read files directly from the container filesystem, which follows symlinks automatically without creating them on the host — making it work on all platforms including Windows (where docker cp fails with symlinks).

func Ldd

func Ldd(binaryPath string) ([]string, error)

Ldd analyses a binary with ldd and returns its shared library dependencies. Returns the library paths as reported by ldd.

func ManifestNeedsUpdate

func ManifestNeedsUpdate(localPath string) bool

ManifestNeedsUpdate checks if the remote manifest has changed by comparing Content-Length via HTTP HEAD. Returns true if update is needed or if check fails (safe default: refresh on error).

func MissingFiles

func MissingFiles(binaryPath string) ([]string, error)

MissingFiles analyses a binary with ldd and returns library paths that are not present on the local filesystem. Useful for identifying which shared libraries need to be bundled in a package alongside the binary.

Types

type File

type File struct {
	HostPath  string
	GuestPath string
	// IsDir marks an empty directory to create inside the image (no host file).
	IsDir bool
}

File represents a file to be included in a unikernel image, with both its host path (on the build machine) and its guest path (inside the image).

type Index

type Index struct {
	// Packages maps package name to its available versions.
	Packages map[string][]Package `json:"packages"`
}

Index is the top-level package index structure.

func FetchIndex

func FetchIndex() (*Index, error)

FetchIndex downloads and parses the remote package index.

func (*Index) Latest

func (idx *Index) Latest(name string) *Package

Latest returns the latest version of a package by name, or nil if not found.

func (*Index) Search

func (idx *Index) Search(query string) []Package

Search returns packages matching the given query string. Matches against name, description, and runtime.

type OpsPackage

type OpsPackage struct {
	Version     string `json:"version"`
	Language    string `json:"language"`
	Description string `json:"description,omitempty"`
	SHA256      string `json:"sha256"`
	Name        string `json:"name"`
	Namespace   string `json:"namespace"`
	Arch        string `json:"arch"`
}

OpsPackage mirrors the ops (nanovms/ops) Package struct from lepton/package.go.

type OpsPackageIdentifier

type OpsPackageIdentifier struct {
	Namespace string
	Name      string
	Version   string
}

OpsPackageIdentifier represents a parsed ops package identifier in the format <namespace>/<name>:<version>.

func ParseOpsIdentifier

func ParseOpsIdentifier(identifier string) (OpsPackageIdentifier, error)

ParseOpsIdentifier parses an ops package identifier of the form "<namespace>/<name>:<version>" or "<namespace>/<name>".

func (OpsPackageIdentifier) String

func (id OpsPackageIdentifier) String() string

String returns the canonical identifier string.

type OpsPackageList

type OpsPackageList struct {
	Version  int          `json:"Version"`
	Packages []OpsPackage `json:"Packages"`
}

OpsPackageList mirrors the ops PackageList struct — flat array with schema version.

func FetchOpsManifest

func FetchOpsManifest() (*OpsPackageList, error)

FetchOpsManifest downloads and parses the ops package manifest.

func SearchOpsPackages

func SearchOpsPackages(query string) (*OpsPackageList, error)

SearchOpsPackages performs a server-side search against the ops package hub.

func (*OpsPackageList) Lookup

func (l *OpsPackageList) Lookup(namespace, name, version string) *OpsPackage

Lookup finds a package in the manifest by namespace, name, and optional version. If version is empty or "latest", returns the first match for namespace+name. Version matching normalizes "v" prefixes and supports major/minor prefix matching (e.g., "11" matches "v11.5.0", "3.10" matches "3.10.6").

func (*OpsPackageList) Search

func (l *OpsPackageList) Search(query string) []OpsPackage

Search returns packages from the manifest matching the query.

type OpsPackageManifestConfig

type OpsPackageManifestConfig struct {
	Program string            `json:"Program"`
	Args    []string          `json:"Args"`
	Version string            `json:"Version"`
	Env     map[string]string `json:"Env"`
}

OpsPackageManifestConfig represents the package.manifest JSON from an ops package.

type OpsStore

type OpsStore struct {
	// contains filtered or unexported fields
}

OpsStore manages locally cached ops packages under a root directory. Ops packages preserve their native format: package.manifest + sysroot/ + top-level binary, stored at root/<namespace>/<name>_<version>/.

func DefaultOpsStore

func DefaultOpsStore() (*OpsStore, error)

DefaultOpsStore returns an OpsStore at the default path.

func NewOpsStore

func NewOpsStore(dir string) (*OpsStore, error)

NewOpsStore creates an OpsStore rooted at dir, creating it if needed.

func (*OpsStore) Download

func (s *OpsStore) Download(namespace, name, version string, expectedSHA256 string) error

Download fetches an ops package from repo.ops.city and stores it locally. The URL is constructed from OpsPackageBaseURL + /<namespace>/<name>/<version>.tar.gz.

func (*OpsStore) Extract

func (s *OpsStore) Extract(namespace, name, version string) error

Extract decompresses the ops package archive into its directory. Ops packages may contain:

  • package.manifest (JSON config for ops)
  • A top-level binary (the program itself)
  • sysroot/ (shared libraries and filesystem layout)

Symlinks are handled on Linux; silently skipped on other platforms.

func (*OpsStore) ExtractedFiles

func (s *OpsStore) ExtractedFiles(namespace, name, version string) ([]File, error)

ExtractedFiles returns the files inside an extracted ops package as File entries with proper guest paths. Files inside sysroot/ get their sysroot- relative path as the guest path; top-level files use their basename. Build-only subtrees (static libs, test suites, etc.) are excluded to keep the image lean — see opsRuntimeBloatDir for the full list.

func (*OpsStore) FetchManifestCached

func (s *OpsStore) FetchManifestCached() (*OpsPackageList, error)

FetchManifestCached downloads the ops manifest only if it has changed since the last fetch, using Content-Length comparison.

func (*OpsStore) FindBinary

func (s *OpsStore) FindBinary(namespace, name, version string) (string, error)

FindBinary attempts to find the main binary inside an extracted ops package. It checks the package.manifest for the Program field, then falls back to looking for ELF files at the top level.

func (*OpsStore) IsDownloaded

func (s *OpsStore) IsDownloaded(namespace, name, version string) bool

IsDownloaded returns true if the ops package archive exists locally.

func (*OpsStore) IsExtracted

func (s *OpsStore) IsExtracted(namespace, name, version string) bool

IsExtracted returns true if the ops package has been extracted and its main binary is present. Checking the binary guards against partial extractions where directory entries were created but the binary was removed (e.g. by AV quarantine) after extraction completed.

func (*OpsStore) List

func (s *OpsStore) List() ([]OpsPackage, error)

List returns all locally cached ops packages.

func (*OpsStore) LoadCachedManifest

func (s *OpsStore) LoadCachedManifest() (*OpsPackageList, error)

LoadCachedManifest reads the locally cached ops manifest.

func (*OpsStore) LoadPackageManifest

func (s *OpsStore) LoadPackageManifest(namespace, name, version string) (*OpsPackageManifestConfig, error)

LoadPackageManifest reads and parses the package.manifest from an extracted ops package directory.

func (*OpsStore) PackageDir

func (s *OpsStore) PackageDir(namespace, name, version string) string

PackageDir returns the local directory for an ops package.

func (*OpsStore) Remove

func (s *OpsStore) Remove(namespace, name, version string) error

Remove deletes a locally cached ops package.

func (*OpsStore) SaveManifest

func (s *OpsStore) SaveManifest(data []byte) error

SaveManifest caches the ops manifest locally.

type Package

type Package struct {
	// Name is the package name (e.g. "node", "python", "redis", "nginx").
	Name string `json:"name"`
	// Version is the semantic version (e.g. "20.11.0").
	Version string `json:"version"`
	// Description is a short human-readable summary.
	Description string `json:"description"`
	// Runtime is the runtime family (e.g. "node", "python").
	Runtime string `json:"runtime"`
	// SHA256 is the expected hex-encoded SHA-256 digest of the archive.
	SHA256 string `json:"sha256"`
	// Size is the archive size in bytes.
	Size int64 `json:"size"`
	// URL is the download URL for the package archive.
	URL string `json:"url"`
	// Created is the publication timestamp.
	Created time.Time `json:"created"`
}

Package describes a downloadable runtime package.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages locally cached packages under a root directory.

func NewStore

func NewStore(dir string) (*Store, error)

NewStore creates a Store rooted at dir, creating it if needed.

func (*Store) Create

func (s *Store) Create(name, version, binaryPath string, extraFiles []string, description, runtimeName string) error

Create builds a local package archive from the given binary and optional extra files. It produces files.tar.gz and meta.json in the package store.

func (*Store) Download

func (s *Store) Download(pkg Package) error

Download fetches the package archive from its URL and stores it locally. Verifies size and SHA-256 digest after download.

func (*Store) Extract

func (s *Store) Extract(pkg Package) error

Extract decompresses the package archive into a files subdirectory. After extraction the individual files can be listed with ExtractedFiles.

func (*Store) ExtractedFiles

func (s *Store) ExtractedFiles(name, version string) ([]string, error)

ExtractedFiles returns the absolute paths of all regular files inside the package's extracted files directory.

func (*Store) IsDownloaded

func (s *Store) IsDownloaded(name, version string) bool

IsDownloaded returns true if the package archive exists locally.

func (*Store) IsExtracted

func (s *Store) IsExtracted(name, version string) bool

IsExtracted returns true if the package has been extracted and its files directory is non-empty.

func (*Store) List

func (s *Store) List() ([]Package, error)

List returns all locally cached package versions.

func (*Store) PackageDir

func (s *Store) PackageDir(name, version string) string

PackageDir returns the local directory for a package version.

func (*Store) Push

func (s *Store) Push(name, version string, indexURL string) error

Push uploads a local package archive and metadata to a remote package index. The index must accept POST /packages with multipart form data (archive + metadata).

func (*Store) Remove

func (s *Store) Remove(name, version string) error

Remove deletes a specific version of a locally cached package.

func (*Store) RemoveAll

func (s *Store) RemoveAll(name string) error

RemoveAll deletes all locally cached versions of a package.

func (*Store) SaveMeta

func (s *Store) SaveMeta(pkg Package) error

SaveMeta writes the package metadata to the local cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL