An installation used to be this one: the deploy scripts and the Ansible defaults carried one site's domain, hypervisor and login, the Proxmox side and the database were set up by hand, and deploying meant copying scripts and a tree of roles beside the binary and keeping them in step with it. The binary now carries the roles, the Terraform module, the schema and the catalogue (embed.go), and installs itself: - hpcod setup: a full-screen installer for administrators. It asks where clusters are built, signs in to Proxmox before asking anything else (root's password once, or tokens), offers nodes and datastores from what Proxmox has, checks every field as it is typed, runs every step with its output live, checks the result and offers a test cluster. -yes runs the same steps from a site file; make deploy uses that. - hpcod verify: each fact checked by using it. - hpcod selftest: the smallest real cluster, by the portal's own path, a job run on it, then taken down. - Closed networks: hpcod serves HTTPS itself from a CA name-constrained to the site's domains, issuing and renewing its own certificate, and answers DNS for the portal and every cluster name. - A simulated Proxmox: Proxmox VE in QEMU on the control plane host, on a private bridge with NAT, for trying it without one. Every step reads back what it changed and is safe to run again. The site's values live in one file; group_vars/all/site.yml is generated from it, and the playbooks refuse to run without it. ci_user and -ssh-user no longer default to a personal account. scripts/B10, B20 and C20 are gone: their work is the setup steps. Proven end to end on a simulated Proxmox (Proxmox VE 9 in a VM on a real host): the install, the Proxmox step by the password path, the head template, verify READY, and a test cluster that ran srun on its compute node and was destroyed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
3.2 KiB
Go
110 lines
3.2 KiB
Go
package setup
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// Step is one part of an install. Every step can be run again: it either
|
|
// creates what is missing or rewrites what it generates, and never touches
|
|
// what was written once - tokens, passwords, the user file, a sites.yaml
|
|
// with a second site in it.
|
|
type Step struct {
|
|
ID string
|
|
Title string
|
|
Run func(context.Context, *Env) error
|
|
}
|
|
|
|
// Steps in the order they run. Later ones depend on earlier ones: the
|
|
// tree needs the account it is owned by, the schema needs the database,
|
|
// the Proxmox step needs the key, the template needs the tree and Proxmox.
|
|
// The portal is started once the schema and configuration are in place and
|
|
// before Proxmox, so an install that stops there - no credentials yet -
|
|
// still leaves a portal running; the Proxmox step restarts it when it
|
|
// writes the token the portal reads at start.
|
|
var Steps = []Step{
|
|
{"site", "Record the site", stepSite},
|
|
{"packages", "Install packages (PostgreSQL, Ansible, OpenTofu)", stepPackages},
|
|
{"account", "Service account and directories", stepAccount},
|
|
{"binary", "Install this binary", stepBinary},
|
|
{"keys", "SSH key and client certificate", stepKeys},
|
|
{"ca", "Certificate authority (direct serving)", stepCA},
|
|
{"database", "Database", stepDatabase},
|
|
{"tree", "Roles, Terraform module and schema files", stepTree},
|
|
{"schema", "Apply the schema", stepSchema},
|
|
{"catalogue", "Application catalogue", stepCatalogue},
|
|
{"config", "Portal and Terraform configuration", stepConfig},
|
|
{"unit", "Service unit", stepUnit},
|
|
{"start", "Start the portal", stepStart},
|
|
{"pvesim", "Simulated Proxmox (QEMU)", stepPVESim},
|
|
{"proxmox", "Prepare Proxmox", stepProxmox},
|
|
{"template", "Head node template", stepTemplate},
|
|
}
|
|
|
|
// Select picks steps by id, keeping their order. Empty means all.
|
|
func Select(only, skip []string) ([]Step, error) {
|
|
known := map[string]bool{}
|
|
for _, s := range Steps {
|
|
known[s.ID] = true
|
|
}
|
|
for _, id := range append(append([]string{}, only...), skip...) {
|
|
if !known[id] {
|
|
return nil, fmt.Errorf("no step %q (steps: %s)", id, strings.Join(StepIDs(), ", "))
|
|
}
|
|
}
|
|
in := func(list []string, id string) bool {
|
|
for _, x := range list {
|
|
if x == id {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
var out []Step
|
|
for _, s := range Steps {
|
|
if (len(only) == 0 || in(only, s.ID)) && !in(skip, s.ID) {
|
|
out = append(out, s)
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// StepIDs lists every step's id.
|
|
func StepIDs() []string {
|
|
var ids []string
|
|
for _, s := range Steps {
|
|
ids = append(ids, s.ID)
|
|
}
|
|
return ids
|
|
}
|
|
|
|
// Event reports a step starting (Err nil, Done false) or finishing.
|
|
type Event struct {
|
|
Step Step
|
|
Done bool
|
|
Err error
|
|
Elapsed time.Duration
|
|
}
|
|
|
|
// Run runs steps in order and stops at the first failure: every later step
|
|
// depends on the ones before it, and running on past a failure produces a
|
|
// second error that hides the first.
|
|
func Run(ctx context.Context, e *Env, steps []Step, events func(Event)) error {
|
|
for _, s := range steps {
|
|
if events != nil {
|
|
events(Event{Step: s})
|
|
}
|
|
t0 := time.Now()
|
|
err := s.Run(ctx, e)
|
|
if events != nil {
|
|
events(Event{Step: s, Done: true, Err: err, Elapsed: time.Since(t0)})
|
|
}
|
|
if err != nil {
|
|
return fmt.Errorf("%s: %w", s.Title, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|