Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog.d/sandbox-setup-work-disks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Sandbox setup can put the VM images and jobs on an external drive

- `darkbloom sandbox setup --disk <volume>` (repeatable) passes each drive to the add-on's installer, for its plan and its install. The VM images and the jobs go on those drives; the add-on, its settings and logs stay in `~/DarkbloomSandbox`. Add `--disk ~` to keep using the internal disk too.
- Without `--disk`, a first setup at a prompt lists the external APFS drives with room for jobs and asks where the VM images and jobs go. Enter keeps the internal disk.
- Setup checks each drive before it installs anything: mounted, APFS, ownership on. With ownership off it prints the exact command, such as `sudo diskutil enableOwnership /Volumes/FastSSD`, and offers to run it; sudo asks for your password. With `--yes` or without a terminal it prints the command and stops. Setup never formats a drive.
- The plan shows each drive, its free space and the jobs it gets. When the installer refuses a drive, setup shows the installer's fix and stops.
- `darkbloom sandbox status` shows each work disk, its free space and slots, and what to do when one is not connected.
- `--disk` needs an add-on release with work disks (1.2.0 or later). With an earlier release, setup says so and changes nothing. On a Mac that is set up, setup suggests `--disk` only when the installed add-on supports it.
53 changes: 47 additions & 6 deletions docs/provider/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ service, to download the add-on's installer. Code:

```bash
darkbloom sandbox [status [--json]]
darkbloom sandbox setup [--yes] [--no-browser] [--linux-slots <n>] [--macos-slots <n>] [--wait-ready] [--server <url>]
darkbloom sandbox setup [--yes] [--no-browser] [--linux-slots <n>] [--macos-slots <n>] [--disk <volume>]... [--wait-ready] [--server <url>]
darkbloom sandbox pause | resume
darkbloom sandbox logs [-f] [-n <lines>]
darkbloom sandbox uninstall [--yes]
Expand All @@ -1267,6 +1267,7 @@ darkbloom sandbox uninstall [--yes]
| `setup --yes`, `-y` | `false` | Skip the confirmation |
| `setup --no-browser` | `false` | The installer does not open the approval page; open the printed link |
| `setup --linux-slots <n>`, `--macos-slots <n>` | what fits the Mac | Jobs at a time: Linux `0`–`16`, macOS `0`–`2`; both `0` is refused. The plan and the install take a chosen count as it is; setup shows it as `(your choice)` |
| `setup --disk <volume>` | none: the internal disk | Repeatable. A work disk for the VM images and jobs, such as `/Volumes/FastSSD`; `~` keeps the internal disk as well. Setup makes each path absolute, checks it (see [Setup](#setup)) and passes it on in order. Needs an add-on release with work disks (1.2.0 or later). The add-on, its settings and logs stay in `~/DarkbloomSandbox` |
| `setup --wait-ready` | `false` | The installer waits until the images are downloaded and the Mac takes jobs |
| `setup --server <url>` | `https://api-sandbox.darkbloom.dev` | Where `install.sh` comes from: an `https` URL without credentials, query or fragment |
| `pause` | — | `darkbloom-sandbox pause`: running jobs finish, no new jobs; then prints how many still run |
Expand All @@ -1282,14 +1283,45 @@ darkbloom sandbox uninstall [--yes]
stops before anything is downloaded
(`provider-swift/Sources/darkbloom/Sandbox/SandboxEligibility.swift`,
`SandboxEligibility`; measurements in `SandboxHostProbe`).
With `--disk`, one `Work disk` line follows per disk, from `statfs` on the
path (or its nearest existing parent). A path under `/Volumes/<name>` must be
on the volume mounted there, and the volume must be APFS with ownership on.
A disk that fails stops setup before anything is downloaded, with the fix:
for ownership off, the exact command, such as
`sudo diskutil enableOwnership /Volumes/FastSSD`. At a prompt and without
`--yes`, setup then asks `Turn ownership on for /Volumes/FastSSD now?`
(default no). On yes it runs that command in the terminal's foreground
process group, so sudo asks for the password itself; the CLI never reads it.
Then setup checks the disk again. If the command fails, setup prints
`Ownership is still off on …` and stops. With `--yes` or without a terminal,
setup prints the command and stops. Setup never formats a drive. The
installer checks each disk again by the add-on's own rules (local, writable,
not a disk image)
(`provider-swift/Sources/darkbloom/Sandbox/SandboxWorkDisk.swift`,
`SandboxWorkDisk`).
2. **Download.** Downloads `<server>/install.sh` over HTTPS: a redirect is
followed only to another `https` URL, and the response must be HTTP 200 over
`https`, at most 1 MiB, with a `#!` first line naming a shell. The script is
written as a `0600` file in a new `0700` directory, run with `/bin/sh` for
the plan and the install, and removed afterwards. The installer verifies the
add-on release before it installs it; the CLI does not verify the script
beyond TLS (`provider-swift/Sources/darkbloom/Sandbox/SandboxInstaller.swift`,
`SandboxInstaller`).
`SandboxInstaller`). With `--disk`, a script that does not name `--disk`
comes from a release without work disks: setup says that work disks need
add-on 1.2.0 or later and stops, changing nothing.
**Drive choice.** On a first setup without `--disk`, at a prompt and
without `--yes`, a script that names `--disk` makes setup list the drives
that can take the VM images and jobs, under `Where the VM images and jobs
go`: `1) This Mac's internal disk`, then one line per drive with its free
space, and a note when its ownership is off. A drive is listed when it is
mounted at its own `/Volumes/<name>`, shows in Finder, is local, writable
and APFS, and has room for its floor (a tenth of the drive, 50 to 100 GiB)
plus a Linux job and its images (34 GiB). Setup asks `Choose 1-N [1]:`;
Enter or the end of input keeps the internal disk, and any other answer
that is not a listed number asks again. A chosen drive gets the `Work disk`
check above (with the ownership offer) and goes to the plan and the install
as one `--disk`. The plan's lines then follow under `The add-on's plan for
this Mac`.
3. **Plan.** A script that names `--plan` (add-on 1.1.1 and later) runs with
`--plan --json-progress` and the owner's slot options, without `--yes` and
with stdin closed. It verifies the release, runs the add-on's own checks and
Expand Down Expand Up @@ -1344,7 +1376,7 @@ darkbloom sandbox uninstall [--yes]
terminal and without `--yes`, setup stops before installing.
5. **Install.** A script that names `--json-progress` runs with
`--json-progress --yes` and the owner's `--no-browser`, `--wait-ready` and
slot options, with stdin closed, and its stages render as
slot options and each `--disk <path>`, with stdin closed, and its stages render as
[progress events](#installer-progress-events). Any other script is an older
installer: it runs with the terminal and only the slot options, and the CLI
says so.
Expand All @@ -1370,7 +1402,7 @@ Rerunning `setup` decides from the add-on's answer
| No add-on, or `not_installed` | A first setup: check, plan, explain, confirm, install |
| `waiting_for_approval`, `waitlisted`, `enrolling` | Runs the installer again to continue, without the check or the question |
| `stopped`, `error`, no answer within 10 s, a failed status, an add-on older than `status --json` | Runs the installer again to repair or update the add-on |
| `ready`, `running`, `paused`, `downloading_images`, `updating`, an unknown state | Reports the state, then checks the plan again (below); with `--linux-slots` or `--macos-slots` it runs the installer to apply them, without the plan |
| `ready`, `running`, `paused`, `downloading_images`, `updating`, an unknown state | Reports the state, then checks the plan again (below); with `--linux-slots`, `--macos-slots` or `--disk` it runs the installer to apply them, without the plan, after the `Work disk` lines. The report offers `--disk` only when the add-on's `status --json` has a `disks` member |

On a Mac that is set up, after the report, setup downloads the installer and
runs its plan as for a first setup, which changes nothing, and compares the
Expand Down Expand Up @@ -1406,8 +1438,16 @@ With `--plan --json-progress` (add-on 1.1.1) the installer exits 0 after one
`macos_limit`, `free_bytes`, `floor_bytes`, `linux_images_bytes`,
`macos_images_bytes`, `linux_slot_bytes`, `macos_slot_bytes`, `cores`,
`cores_kept`, `memory_bytes`, `memory_kept_bytes` and `provider_memory_bytes`
(`SandboxSizingPlan`). It ignores `root`, `volume_bytes` and unknown members. A
line with another schema or without one of the numbers is not a plan.
(`SandboxSizingPlan`), and from `disks` (releases with work disks) each
entry's `path`, `root_volume`, `free_bytes`, `floor_bytes`, `linux_slots` and
`macos_slots`. When the plan uses an external disk or more than one disk, an
`[INFO] Work disk` line per disk follows the `Disk` line, such as
`/Volumes/FastSSD: 900 GiB free; 93 GiB stays free; 2 Linux jobs, 1 macOS job`.
It ignores `root`, `volume_bytes` and unknown members. A line with another
schema or without one of the numbers is not a plan. With `--disk`, a failed plan
(exit `2` when the installer refuses a disk) stops setup with the installer's
last stderr lines and its exit status, since the CLI's estimate knows no work
disks; without `--disk`, setup falls back to the estimate as before.

| `status` | Meaning | The CLI |
|---|---|---|
Expand Down Expand Up @@ -1484,6 +1524,7 @@ add-ons still render (`provider-swift/Sources/darkbloom/Sandbox/SandboxAddon.swi
| `accepting` | bool | A ready Mac with `false` shows the add-on's `detail` |
| `last_update_check` | Unix seconds or null (milliseconds and ISO 8601 are read too) | `Updates` line |
| `console_url` | string | `Console` line and the setup summary |
| `disks` | `[{"path", "root_volume", "state", "detail", "free_bytes", "slots": {"linux": {"total"}, "macos": {"total"}}, …}]` (add-on releases with work disks) | The member's presence means the add-on takes `--disk`. When it lists an external drive or more than one disk, one `Work disk` line per disk follows `Images`, such as `/Volumes/FastSSD: online, 812 GiB free; slots: Linux 2, macOS 1`. A disk that is not `online` adds its `detail` in parentheses. An entry without `path` or `state` is skipped |

An add-on that answers with exit status `64` or its usage on stderr predates
the option or action: `status` then shows the add-on's own `status` output,
Expand Down
53 changes: 53 additions & 0 deletions docs/provider/sandboxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ into your Darkbloom balance.
rules.
To choose the number of jobs, add `--linux-slots <n>` and `--macos-slots <n>`;
`--macos-slots 1` keeps one of macOS's two macOS VMs for your own use.
To put the VM images and jobs on an external drive, add `--disk <volume>`,
or pick the drive when setup asks; see
[Use an external drive](#use-an-external-drive).

2. Approve this Mac in your browser. The installer opens the approval page with
the code filled in, and setup prints the link and code as well. Sign in with
Expand All @@ -56,6 +59,45 @@ into your Darkbloom balance.
takes jobs once an image is installed. To keep setup open until then, add
`--wait-ready` to step 1.

## Use an external drive

If the internal disk is what limits this Mac, or to spare it the wear, give the
jobs another drive. The VM images and the jobs then use that drive. The add-on,
its settings and its logs stay in `~/DarkbloomSandbox`. This needs add-on 1.2.0
or later; with an earlier release setup says so and changes nothing.

1. Use a Thunderbolt or USB4 NVMe SSD that stays connected and powered. A job
on a drive that goes away is stopped and is not paid.
2. Format it as APFS in Disk Utility. Erasing deletes everything on the drive.
Setup never formats a drive.
3. Turn on ownership, which macOS leaves off for external drives. Setup offers
to do this for you (step 4). To do it yourself:

```bash
sudo diskutil enableOwnership /Volumes/FastSSD
```

4. Run `darkbloom sandbox setup`. On a first setup it lists the drives with
room for jobs and asks where the VM images and jobs go. Press Enter to keep
the internal disk, or type the drive's number. You can also name the drive.
Repeat `--disk` for more drives, and add `--disk ~` to keep using the
internal disk too:

```bash
darkbloom sandbox setup --disk /Volumes/FastSSD
```

Setup checks each drive before it installs anything. When ownership is off,
setup prints the command and asks whether to run it. If you agree, sudo asks
for your password, and setup checks the drive again. With `--yes`, or without
a terminal, setup prints the command and stops. When a drive is not APFS, setup
stops and tells you to erase it as APFS in Disk Utility; setup never formats a
drive. The plan then shows each drive, its free space and the jobs it gets.
Each drive keeps its own free space: a tenth of the drive, 50 to 100 GiB.
Running setup again keeps the drives you chose; give `--disk` again to change
them. `darkbloom sandbox status` shows each drive, its free space and slots,
and what to do when one is not connected.

## Verify

```bash
Expand All @@ -76,6 +118,7 @@ Settled jobs are in the console under **Billing → Earnings**.
| Take jobs again | `darkbloom sandbox resume` |
| Follow the add-on's log | `darkbloom sandbox logs -f` |
| Change the jobs at a time | `darkbloom sandbox setup --linux-slots <n> --macos-slots <n>` |
| Put the images and jobs on an external drive | `darkbloom sandbox setup --disk /Volumes/<name>` |
| Remove the add-on and its files | `darkbloom sandbox uninstall` |

Uninstalling ends running jobs, which are not paid: pause first and uninstall
Expand Down Expand Up @@ -112,6 +155,16 @@ While jobs run, setup skips the check. The
Ctrl-C if you like: the Mac enrolls once it is approved, and `setup` follows
the waiting enrollment when you run it again. A restart ends that wait; run
setup again after one.
- **`[FAIL] Work disk: … ignores file ownership`.** Ownership is off on the
drive. Answer yes when setup offers to turn it on, or run the `↳ fix:`
command (`sudo diskutil enableOwnership …`) yourself, then run setup again.
- **`Work disk: … offline` in `darkbloom sandbox status`.** The drive is not
connected, so its slots take no jobs. Connect it again; its slots take jobs
once its images are checked.
- **`[FAIL] Work disk: … is not APFS`** or **`is not a mounted drive`.** Format
the drive as APFS in Disk Utility, or connect it, then run setup again.
- **`work disks need add-on 1.2.0 or later`.** The add-on release on offer
cannot use other drives yet. Run setup without `--disk`.
- **`[WARN] Network`, `Power` or `Sleep`.** These do not block setup, but a
sleeping, unplugged or dropped Mac loses its running jobs, and lost jobs are
not paid. Follow the `↳ fix:` line.
Expand Down
36 changes: 35 additions & 1 deletion provider-swift/Sources/darkbloom/Sandbox/SandboxAddon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ struct SandboxAddonStatus: Equatable, Sendable {
var accepting: Bool?
var lastUpdateCheck: Date?
var consoleURL: String?
/// The add-on reports its work disks (`disks`), so it takes
/// `install --disk`.
var supportsWorkDisks = false
/// Its work disks, in order: the internal disk alone without `--disk`.
var disks: [Disk] = []

/// One work disk, as `status --json` reports it.
struct Disk: Equatable, Sendable {
/// Its mount point.
var path: String
/// The install root's own volume, the internal disk.
var rootVolume: Bool
/// `online`, `verifying` or `offline`.
var state: String
/// What to do about it, when it is not online.
var detail: String?
var freeBytes: Int64?
var linuxSlots: Int
var macOSSlots: Int
}
}

extension SandboxAddonStatus {
Expand Down Expand Up @@ -188,7 +208,21 @@ extension SandboxAddonStatus {
},
accepting: object["accepting"] as? Bool,
lastUpdateCheck: Self.timestamp(object["last_update_check"]),
consoleURL: text("console_url"))
consoleURL: text("console_url"),
supportsWorkDisks: object["disks"] is [Any],
disks: (object["disks"] as? [[String: Any]] ?? []).compactMap(Self.disk))
}

/// One entry of `disks`; nil without a path and a state.
private static func disk(_ entry: [String: Any]) -> Disk? {
guard let path = entry["path"] as? String, let state = entry["state"] as? String else { return nil }
func total(_ platform: String) -> Int {
let slots = (entry["slots"] as? [String: Any])?[platform] as? [String: Any]
return max(0, slots?["total"] as? Int ?? 0)
}
return Disk(path: path, rootVolume: entry["root_volume"] as? Bool ?? false, state: state,
detail: (entry["detail"] as? String).flatMap { $0.isEmpty ? nil : $0 },
freeBytes: entry["free_bytes"] as? Int64, linuxSlots: total("linux"), macOSSlots: total("macos"))
}

/// Unix seconds (or milliseconds) or an ISO 8601 string.
Expand Down
25 changes: 22 additions & 3 deletions provider-swift/Sources/darkbloom/Sandbox/SandboxEligibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,22 @@ extension SandboxSizingPlan {
.init(level: level("disk"), name: "Disk",
detail: "\(gibDown(freeBytes)) GiB free; \(gibDown(floorBytes)) GiB stays free for you; "
+ disk("Linux", linux) + "; " + disk("macOS", macOS)),
]
] + diskChecks
}

/// One line per disk when the plan uses a work disk (an external drive,
/// or more than one disk): its room and the jobs placed on it.
private var diskChecks: [SandboxEligibility.Check] {
guard disks.count > 1 || disks.contains(where: { !$0.rootVolume }) else { return [] }
return disks.map { disk in
let jobs = [("Linux", disk.linuxSlots), ("macOS", disk.macOSSlots)].compactMap { name, count -> String? in
count > 0 ? Self.jobCount(count, name) : nil
}
return .init(level: .info, name: "Work disk",
detail: "\(disk.path)\(disk.rootVolume ? " (internal)" : ""): "
+ "\(gibDown(disk.freeBytes)) GiB free; \(gibDown(disk.floorBytes)) GiB stays free; "
+ (jobs.isEmpty ? "no jobs" : jobs.joined(separator: ", ")))
}
}

/// The verdict, then what this Mac can run at a time or what it lacks.
Expand Down Expand Up @@ -294,11 +309,15 @@ extension SandboxSizingPlan {
}

private static func slotLine(_ name: String, _ platform: Platform) -> String {
let jobs = platform.slots == 0 ? "no \(name) jobs"
: "\(platform.slots) \(name) job" + (platform.slots == 1 ? "" : "s")
let jobs = platform.slots == 0 ? "no \(name) jobs" : jobCount(platform.slots, name)
guard platform.automatic else { return "\(jobs) (your choice)" }
return platform.limit.map { "\(jobs) (limited by \($0))" } ?? jobs
}

/// `1 Linux job`, `2 macOS jobs`.
private static func jobCount(_ count: Int, _ name: String) -> String {
"\(count) \(name) job" + (count == 1 ? "" : "s")
}
}

extension SandboxSizingPlan.Platform {
Expand Down
Loading
Loading