monolith

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

monolith

CI Release

Lightweight Linux VMs on macOS (Apple Silicon), built on Apple's Virtualization.framework: plain VMs, Colima-style Docker and containerd hosts, Kubernetes clusters, sandboxes for code you don't trust, and its own container engine that runs each container in its own VM.

  • monolith vm: Alpine (default) or Kata VMs that boot in seconds, with pause, suspend-to-disk and several network modes.
  • monolith docker: Docker Engine or containerd hosts for the CLI on your Mac, with docker contexts, localhost port forwarding (TCP and UDP), /Users bind mounts with file-change events, pause/resume to disk, and optional Rosetta for amd64 images. docker use switches between hosts.
  • monolith cluster: a single-node Kubernetes (k3s) cluster in a VM, merged into your kubeconfig, with LoadBalancer and NodePort services on localhost, pause/resume to disk, optional Rosetta for amd64 images, and cluster load for images without a registry (from registries, a monolith docker host or docker save). cluster use switches between clusters.
  • monolith sandbox: run a repo you don't trust in a lith, like a virtualenv: only the repo is visible (read-only, changes reviewed with diff/apply), and the code can reach the internet but not your Mac or local network.
  • monolith container: monolith's own container engine, in the style of Apple's container tool. It pulls OCI images from any registry and runs each container in its own small VM (Kata's kernel, monolith's own init), so every container has its own kernel. Docker-style commands (run -it/-d, ps, logs, stop, start, rm, prune, images), about 0.6s from run to exit, per-container --cpus/--memory/--disk, and live, coloured pull progress with a shared layer cache. Not yet: exec, -p and -v (docs/container.md).
  • monolith network: named networks shared between VMs.
Which one?
You want Use
A Linux machine to work in monolith vm
The Docker ecosystem: the docker CLI, Compose, buildx monolith docker
A Kubernetes cluster to point kubectl at monolith cluster
Quick runs of single images, each container isolated by its own VM monolith container
A safe place to try a repo you don't trust monolith sandbox

monolith container is a separate engine, not a Docker runtime: it runs standard OCI images with docker run semantics, but Docker tools can't talk to it. For those, use monolith docker.

Install

Requires macOS on Apple Silicon:

curl -fsSL https://raw.githubusercontent.com/bubunyo/monolith/master/install.sh | bash

The script downloads the latest release, checks it against the release's SHA-256 checksums and its code signature, and installs monolith to /usr/local/bin (using sudo if needed). Options, as environment variables for the bash side of the pipe:

curl -fsSL https://raw.githubusercontent.com/bubunyo/monolith/master/install.sh | MONOLITH_VERSION=v0.1.0 MONOLITH_INSTALL_DIR=~/.local/bin bash

To update later, run monolith update; it makes the same checks and replaces the binary in place. monolith --version tells you when a newer release is out.

To install by hand, download monolith_<version>_darwin_arm64.tar.gz and checksums.txt from Releases, run shasum -a 256 -c checksums.txt, and copy the binary onto your PATH. If macOS then refuses to run it ("cannot be opened because the developer cannot be verified"), the release wasn't notarized and a browser added the quarantine flag: xattr -d com.apple.quarantine /path/to/monolith.

Build from source

Needs Go (see go.mod) and Xcode command line tools:

make build    # ./bin/monolith, codesigned with entitlements.plist
make test     # unit tests

make build signs ad-hoc unless .codesign_identity names a certificate (see docs/codesigning.md). It also cross-compiles monolith-init, the PID 1 of container VMs, and embeds it. Don't use a bare go build: without the virtualization entitlement the binary is killed on launch, and without the init monolith container can't run anything.

Quick start

monolith vm run dev                 # boot a VM and attach to its console (Ctrl+] then q to detach)
monolith docker start               # a Docker host; the docker CLI's context switches to it
docker run --rm -it busybox sh
monolith cluster start              # a single-node Kubernetes (k3s) cluster; kubectl's context switches to it
kubectl get nodes

monolith container run --rm alpine echo hello      # a container in its own VM
monolith container run -it --rm alpine sh          # interactive (Ctrl+P Ctrl+Q detaches)
monolith container run -d --name db -e POSTGRES_PASSWORD=secret postgres
monolith container logs -f db

cd ~/Downloads/some-repo && monolith sandbox activate   # a shell in a sandbox for this repo

Flags for container run go before the image; anything after it is the command to run in the container, as with docker run.

Documentation

Documentation

Index

Constants

View Source
const (
	LvlTrace = iota
	LvlInfo
	LvlWarn
	LvlError
)

Log level constants — numeric for comparison, string labels for output.

View Source
const EntitlementHostNetworking = "com.apple.vm.networking"

EntitlementHostNetworking is the entitlement Apple requires for using VZBridgedNetworkDeviceAttachment (i.e. host/bridged network mode).

Variables

This section is empty.

Functions

func CachePath

func CachePath(elem ...string) (string, error)

CachePath returns a path under the monolith root, ~/.monolith. It does not create anything.

func EnsureLogReadable

func EnsureLogReadable(path, what, name string) error

EnsureLogReadable returns a friendly error if the log file is missing.

func HasEntitlement

func HasEntitlement(key string) bool

HasEntitlement reports whether the currently running binary has been codesigned with the given entitlement key set to true.

The result is cached for the lifetime of the process. On any error reading the signature (binary not signed, codesign missing, etc.) it returns false. This is intended for best-effort pre-flight checks; the authoritative enforcement happens inside Virtualization.framework at VM startup.

func OwnCodeRequirement

func OwnCodeRequirement() (string, error)

OwnCodeRequirement returns a code signing requirement that matches only the currently running binary (`cdhash H"<hash>"`). Network daemons and VM daemons run the same binary, so each side uses this to authenticate the other when sharing a vmnet network over XPC. Rebuilding or re-signing the binary changes the hash, so daemons from an older build won't match.

func PrivateSize

func PrivateSize(path string) (int64, error)

PrivateSize is the space a file takes that isn't shared with APFS clones of it: for a container's disk, what the container wrote on top of its image (what removing it gives back). du and stat count shared blocks too.

func ProcessAlive

func ProcessAlive(pid int) bool

ProcessAlive checks if a process with the given PID is still running. On Unix, sending signal 0 to a process checks for existence without actually sending a signal.

func StreamLogFile

func StreamLogFile(path string, out io.Writer, opts TailOptions) error

StreamLogFile prints the contents of the log file at path to out, with optional tail/follow semantics analogous to `tail -F`. When Follow is true, it keeps reading the file as the daemon appends to it. The function exits when out returns an error (e.g. the user closes stdout) or, if Follow is false, after the existing content has been written.

Types

type Logger

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

Logger writes structured log lines with timestamps and levels. It supports multiple output sinks, each with an independent minimum level. It is safe for concurrent use.

func NewLogger

func NewLogger(w io.Writer) *Logger

NewLogger creates a Logger that writes all levels to w.

func (*Logger) AddSink

func (l *Logger) AddSink(w io.Writer, minLevel int)

AddSink adds an additional output writer that receives messages at or above minLevel.

func (*Logger) Error

func (l *Logger) Error(format string, args ...any)

Error logs at ERR level.

func (*Logger) Info

func (l *Logger) Info(format string, args ...any)

Info logs at INF level.

func (*Logger) Trace

func (l *Logger) Trace(format string, args ...any)

Trace logs at TRC level. Used for verbose/diagnostic output such as packet monitors.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...any)

Warn logs at WRN level.

type TailOptions

type TailOptions struct {
	// Lines is the number of trailing lines to print before streaming.
	// Zero means "print everything from the start of the file".
	// A negative value means "skip the existing backlog entirely".
	Lines int
	// Follow keeps reading new content appended to the file until ctx
	// is cancelled or the writer to out returns an error.
	Follow bool
}

TailOptions controls how StreamLogFile reads a log file.

Directories

Path Synopsis
cli
cluster
Package cluster implements `monolith cluster`: a single-node Kubernetes (k3s) cluster in a VM.
Package cluster implements `monolith cluster`: a single-node Kubernetes (k3s) cluster in a VM.
container
Package container implements `monolith container`: each container runs in its own small VM (Kata's kernel, monolith-init as PID 1, the image's filesystem as root), in the style of Apple's container tool.
Package container implements `monolith container`: each container runs in its own small VM (Kata's kernel, monolith-init as PID 1, the image's filesystem as root), in the style of Apple's container tool.
docker
Package docker implements `monolith docker`: container host VMs for the docker CLI (docker engine) or nerdctl (containerd engine), in the style of Colima.
Package docker implements `monolith docker`: container host VMs for the docker CLI (docker engine) or nerdctl (containerd engine), in the style of Colima.
sandbox
Package sandbox implements `monolith sandbox`: run a repo's commands in a lith, isolated from the Mac, the way a virtualenv scopes a project.
Package sandbox implements `monolith sandbox`: run a repo's commands in a lith, isolated from the Mac, the way a virtualenv scopes a project.
vm
cmd
monolith command
monolith-init command
monolith-init is PID 1 of a container VM (`monolith container`).
monolith-init is PID 1 of a container VM (`monolith container`).
Package containerinit is shared by monolith-init, the PID 1 of container VMs (cmd/monolith-init), and the daemon that runs them: the container's process spec and the logic that turns an image's config into a process (command, user, environment, PATH lookup, signals).
Package containerinit is shared by monolith-init, the PID 1 of container VMs (cmd/monolith-init), and the daemon that runs them: the container's process spec and the logic that turns an image's config into a process (command, user, environment, PATH lookup, signals).
agentpb
Code generated by protoc-gen-go-ttrpc.
Code generated by protoc-gen-go-ttrpc.
internal
ansi
Package ansi has the terminal helpers shared by monolith's live views: whether to colour, SGR painting, the terminal's width, and turning raw console output into plain text.
Package ansi has the terminal helpers shared by monolith's live views: whether to colour, SGR painting, the terminal's width, and turning raw console output into plain text.
kubeconfig
Package kubeconfig reads the kubeconfig k3s writes in a cluster VM, rewrites it for the Mac, and merges it into (and removes it from) the user's own kubeconfig without disturbing anything else in that file.
Package kubeconfig reads the kubeconfig k3s writes in a cluster VM, rewrites it for the Mac, and merges it into (and removes it from) the user's own kubeconfig without disturbing anything else in that file.
steps
Package steps shows a task as a list of steps the way `docker buildx` does: the running step streams its output in a small scrolling window, and folds to one line with its duration when it finishes.
Package steps shows a task as a list of steps the way `docker buildx` does: the running step streams its output in a small scrolling window, and folds to one line with its duration when it finishes.
Package oci keeps container images for `monolith container`: it pulls them from registries and converts each into an ext4 disk image that a container VM boots as its root filesystem.
Package oci keeps container images for `monolith container`: it pulls them from registries and converts each into an ext4 disk image that a container VM boots as its root filesystem.
Package update finds monolith's latest GitHub release and installs a release over the running binary, with the checks install.sh makes: the archive's sha256 against the release's checksums.txt, then the binary's code signature and virtualization entitlement.
Package update finds monolith's latest GitHub release and installs a release over the running binary, with the checks install.sh makes: the archive's sha256 against the release's checksums.txt, then the binary's code signature and virtualization entitlement.
vm
guestinit
Package guestinit embeds monolith-init (cmd/monolith-init, built for linux/arm64 by `make build`) and packs it into the initrd container VMs boot from.
Package guestinit embeds monolith-init (cmd/monolith-init, built for linux/arm64 by `make build`) and packs it into the initrd container VMs boot from.

Jump to

Keyboard shortcuts

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