up

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package up is nova-up: it takes one machine from nothing to a first sprint (docs/SPEC-UP.md). Setup is a list of steps, each in its own file, each registering itself from an init into the one registry (Register), so a step added later adds a file and edits no other. A run plans every step first, each saying what it found (ok, create, change, missing), and applies only when the plan holds no missing step: a dependency nova-up cannot provide stops the run before anything is written (SPEC-UP "Plan, then apply"). A step's plan reads, its apply writes, and a second run over an applied machine plans ok everywhere and changes nothing (SPEC-UP "Idempotence").

Everything a step touches outside its root goes through Machine: the programs it runs (Exec), the clock, the randomness a password is drawn from, the operating system and the home directory, so a test runs every step on a fake machine rooted in a temporary directory.

Index

Constants

View Source
const (
	Seat       = "coordinator" // the coordinator's seat in the secrets store and the sprint's actor
	SprintTwin = "stores/sprint.twin"
	SecretsDir = "secrets"
	SecretsGit = "secrets.git" // the secrets store's upstream: a bare repository beside it
	KeysDir    = "keys"
	SeatFile   = "seat.env"
	SmokeDir   = "smoke"
	LogsDir    = "logs"
)

The layout of a root (docs/SPEC-UP.md "The root"). Every path a step writes is one of these, under the root, but for the one unit file the service manager reads from its own directory (redis.go).

View Source
const (
	RedisLoop = "redis-local"
	RedisBind = "127.0.0.1"
	RedisPort = 6390
	RedisDir  = "stores/redis"
	// RedisACLRecord holds the users the last acl apply set; a plan reads it, never the store.
	RedisACLRecord = "stores/redis/acl.applied"
)

Variables

View Source
var RedisUsers = []string{"coordinator", "bench", "ns-table", "ns-friend"}

RedisUsers are the ACL users of a store (nova-redis acl render), coordinator first.

Functions

func KeyFile

func KeyFile() string

KeyFile is the seat's age identity under the root.

func PasswordName

func PasswordName(user string) string

PasswordName is the secret holding user's password.

func RedisAddr

func RedisAddr() string

RedisAddr is the store's address.

func Register

func Register(s Step)

Register adds a step; each step's file calls it from an init. Two steps of one name or one order are a bug of the build, refused at init.

func Tool

func Tool(stamp string, machine func() (Machine, error)) *tool.Tool

Tool is nova-up on pkg/tool, over the machine machine returns (Local on a real machine, a fake in a test). The one verb, up, is the default, so `nova-up --local` is `nova-up up --local` (docs/SPEC-UP.md).

Types

type Cmd

type Cmd struct {
	Name  string
	Args  []string
	Dir   string
	Env   []string
	Stdin string
}

Cmd is one program run: its name, arguments, working directory, the variables added to its environment, and its standard input. A secret travels in Stdin or in a variable, never in Args.

func (Cmd) String

func (c Cmd) String() string

String is the command as a line, for a refusal: name and arguments, never Stdin or Env.

type Env

type Env struct {
	Machine
	Ctx  context.Context
	Root string
}

Env is one run: the machine, the root and what the steps share.

func (*Env) Path

func (e *Env) Path(elem ...string) string

Path is a path under the root.

func (*Env) Run

func (e *Env) Run(c Cmd) (string, error)

Run runs c and wraps a failure with the command line and its output's last line.

type Exec

type Exec interface {
	LookPath(name string) (string, error)
	Run(ctx context.Context, c Cmd) (stdout string, err error)
}

Exec is how a step finds and runs programs.

type Finding

type Finding struct {
	State  State
	Detail string
}

Finding is one step's plan: its state and a one-line detail. A missing finding's detail carries the install command that provides it.

type Line

type Line struct {
	Step string
	Finding
}

Line is one step's printed plan: `UP <step> <state> <detail>`.

func (Line) String

func (l Line) String() string

type Machine

type Machine struct {
	GOOS string // runtime.GOOS on a real machine
	Home string // the home directory; the default root and the service manager's directory are under it
	UID  int    // the login's uid, for launchd's gui domain
	Exec Exec
	Now  func() time.Time
	Rand io.Reader // passwords are drawn from it
}

Machine is the world a run sees outside its root.

func Local

func Local() (Machine, error)

Local is this machine.

type Result

type Result struct {
	Lines   []Line
	Applied int
	Missing []string
	Err     error
}

Result is one run: the plan's lines, how many steps were applied, and the error that stopped it. Missing lists the steps that stopped the run before any apply.

func Up

func Up(e *Env, dryRun bool) Result

Up plans every registered step and, unless dryRun or a step is missing, applies each step that is not ok, in order (SPEC-UP "Plan, then apply"). A step is planned after the steps before it are applied, so its plan reads the machine they left; a dry run plans each step on the machine as it is.

func (Result) Changes

func (r Result) Changes() int

Changes is the number of steps the plan found not ok.

type State

type State string

State is what a step's plan found.

const (
	OK      State = "ok"      // already as the step wants it; apply does nothing
	Create  State = "create"  // absent; apply makes it
	Change  State = "change"  // present and different; apply brings it to the step's form
	Missing State = "missing" // a dependency nova-up cannot provide; the run stops before any apply
)

type Step

type Step struct {
	Name  string
	Order int // steps run in ascending order; a step's order is stated in docs/SPEC-UP.md
	Plan  func(e *Env) Finding
	Apply func(e *Env) error
}

Step is one part of a setup. Plan reads and never writes; Apply runs only after a plan of create or change and brings the machine to what Plan wants.

func Steps

func Steps() []Step

Steps is the registry in run order.

Jump to

Keyboard shortcuts

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