Module: Microsandbox::RootDisk

Defined in:
lib/microsandbox/root_disk.rb

Overview

Factory for an OCI sandbox's writable root disk spec (runtime v0.6.7), passed to Sandbox.create via root_disk:. Three kinds:

  • RootDisk.managed — the default: a sparse ext4 upper file created and resized by the runtime (4 GiB cap when no size is given). A bare Integer passed to root_disk: means the same thing.
  • RootDisk.tmpfs — RAM-backed upper, so the rootfs is pristine on every boot. Default size is half the sandbox memory; the size must not exceed sandbox memory (no swap in the guest). Cannot be snapshotted or patched.
  • RootDisk.disk — a user-supplied disk image attached writable as the upper. The file determines its own size; the runtime never creates, resizes, or deletes it. Cannot be snapshotted or patched.

Mirrors the RootDisk factory in the official Python/Node/Go SDKs.

Examples:

Sandbox.create("worker", image: "python", root_disk: 8192)
Sandbox.create("ci", image: "python", root_disk: Microsandbox::RootDisk.tmpfs(2048))
Sandbox.create("warm", image: "python",
  root_disk: Microsandbox::RootDisk.disk("./scratch.img", fstype: "ext4"))

Class Method Summary collapse

Class Method Details

.disk(path, format: nil, fstype: nil) ⇒ Hash

A user-supplied disk image attached writable as the upper.

Parameters:

  • path (String)

    path to the image file

  • format ("raw", "qcow2", nil) (defaults to: nil)

    image format (inferred from the .img/.raw/.qcow2 extension when omitted)

  • fstype (String, nil) (defaults to: nil)

    filesystem type inside the image, e.g. "ext4"

Returns:

  • (Hash)


51
52
53
54
55
56
# File 'lib/microsandbox/root_disk.rb', line 51

def disk(path, format: nil, fstype: nil)
  h = {"kind" => "disk", "path" => path.to_s}
  h["format"] = format.to_s if format
  h["fstype"] = fstype.to_s if fstype
  h
end

.managed(size_mib = nil) ⇒ Hash

The managed sparse-ext4 upper (the default kind).

Parameters:

  • size_mib (Integer, nil) (defaults to: nil)

    size cap in MiB (default 4096)

Returns:

  • (Hash)


30
31
32
33
34
# File 'lib/microsandbox/root_disk.rb', line 30

def managed(size_mib = nil)
  h = {"kind" => "managed"}
  h["size_mib"] = Integer(size_mib) if size_mib
  h
end

.tmpfs(size_mib = nil) ⇒ Hash

A RAM-backed tmpfs upper — pristine rootfs on every boot.

Parameters:

  • size_mib (Integer, nil) (defaults to: nil)

    size in MiB (default: half sandbox memory)

Returns:

  • (Hash)


39
40
41
42
43
# File 'lib/microsandbox/root_disk.rb', line 39

def tmpfs(size_mib = nil)
  h = {"kind" => "tmpfs"}
  h["size_mib"] = Integer(size_mib) if size_mib
  h
end