preflight

package
v0.20.6 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package preflight answers one question before a deploy runs: what, on THIS machine, will stop this service earning?

The catalog shows one generic earnings range per service. A user cannot tell, before deploying, whether a service will work at all in their situation — and several will not. They find out weeks later, when it has earned nothing.

This is the Go port of the web repository's app/preflight.py, and it keeps that module's two rules:

  • Informed consent, not a nanny. Where the answer is "this will earn nothing for you", say so plainly and let the deploy proceed. Nothing here blocks.
  • Never imply a check we did not run. Desktop cannot see what kind of internet connection it is on, how fast it is, or how much disk is free. Requirements that depend on those are reported as unverified preconditions in the user's own words, never as a pass, and everything unknown is listed by name.

Three things are deliberately NOT a straight copy of the web module, because on a desktop they would be wrong:

  • The web module warns when the SAME service is already deployed on the same worker, treating it as a second instance. Desktop deploys one container per service (cashpilot-<slug>), so redeploying a service replaces it. Firing "a second instance earns nothing" there would warn every user who simply re-deploys, which is the false alarm this whole feature exists to avoid.
  • The web module can confirm that two workers leave through the same public address and states a documented per-IP conflict as fact. Desktop knows the names and services of the other machines in the fleet but not their egress, so the same conflict is reported as something to check, conditional on the machines sharing one connection. A warning we cannot stand behind is stated as a question, never as a verdict.
  • The web module swaps in the per-architecture image on deploy (arch.image_for), so an entry with image_by_arch really does run everywhere it declares. Desktop deploys docker.image and nothing else, so on a CPU that has an override the image the user actually gets is the x86-64 one. This module reports what is deployed today, not what the catalog could offer: counting the override as a pass would promise a build nobody will ever pull. When the deploy path learns to pick the override, this finding goes away with it.

Index

Constants

View Source
const (
	EarnsNothing  = "will_earn_nothing"
	Reduced       = "reduced_earnings"
	CheckYourself = "check_these"
	LooksFine     = "looks_fine"
)

The four verdicts, worst first. Same vocabulary as the web repository, so a finding means the same thing in both products.

Variables

This section is empty.

Functions

func Builds added in v0.20.0

func Builds(docker catalog.DockerConfig) string

Builds is describeBuilds for callers outside this package.

func DaemonArch

func DaemonArch(ctx context.Context) string

DaemonArch reports the CPU architecture of the container runtime, as the runtime itself reports it ("arm64", "x86_64", "amd64").

The container runs on the DAEMON, not on the Desktop binary, and the two are not always the same machine: a remote Docker context, a Lima or Colima VM, or Podman in a virtual machine all move the real target elsewhere. Reading the Desktop binary's own architecture instead would be a guess dressed as a check, so an unreachable runtime returns "" and the assessment says the CPU was not checked.

Works with Docker and with Podman, which serves the same API over DOCKER_HOST.

func Family

func Family(machine string) string

Family folds a reported machine name to one of the three families: "aarch64" -> "arm64", a family name to itself, anything unknown to "".

func Label

func Label(family string) string

Label is how a family reads to a person.

func Supports added in v0.20.0

func Supports(docker catalog.DockerConfig, machine string) (supported bool, known bool)

Supports is supports for callers outside this package. The compose export asks it before writing a file for a chosen architecture, so the same rule that warns in the wizard refuses an export that could not run: one answer, not two.

Types

type Device

type Device struct {
	Name     string   `json:"name"`
	Services []string `json:"services"`
}

Device is one other machine in the fleet, reduced to what a preflight needs: what to call it, and what it already runs.

type Finding

type Finding struct {
	Verdict string `json:"verdict"`
	Message string `json:"message"`
}

Finding is one thing worth knowing before the deploy, in the words the user reads.

type Input

type Input struct {
	// Service is the catalog entry about to be deployed.
	Service catalog.Service
	// Fleet is the OTHER machines registered with this Desktop. The local machine is
	// not in here: Desktop runs one container per service, so its own deployments are
	// a redeploy rather than a second device.
	Fleet []Device
	// DaemonArch is what the container runtime reports about the CPU it runs on
	// ("arm64", "x86_64"). Empty means it could not be read, which is reported as
	// unchecked rather than guessed — the Desktop binary's own architecture is not
	// the same fact when the runtime is a VM or a remote context.
	DaemonArch string
}

Input is everything the assessment reads. Every field is optional: with an empty Input the assessment degrades to what the catalog entry alone says and keeps listing what it could not check.

type Report

type Report struct {
	Slug       string    `json:"slug"`
	Name       string    `json:"name"`
	Verdict    string    `json:"verdict"`
	Summary    string    `json:"summary"`
	Findings   []Finding `json:"findings"`
	NotChecked []string  `json:"notChecked"`
	// MachineArch is the architecture the assessment used, empty when unknown.
	MachineArch string `json:"machineArch"`
	Blocking    bool   `json:"blocking"`
}

Report is the whole answer, ready to render. Blocking is always false: this informs a decision, it never takes it.

func Assess

func Assess(in Input) Report

Assess answers "what will this realistically do for me?" before the deploy runs.

type Target

type Target struct {
	Family  string
	Variant int
	Known   bool
}

Target is one CPU a build can be made for: a family, plus the variant that only 32-bit ARM tracks (0 elsewhere). Known is false when nothing could be determined, which callers must read as "not checked" and never as a pass.

Jump to

Keyboard shortcuts

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