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>
164 lines
4.8 KiB
Go
164 lines
4.8 KiB
Go
package tui
|
||
|
||
import (
|
||
"strings"
|
||
|
||
"github.com/charmbracelet/bubbles/key"
|
||
tea "github.com/charmbracelet/bubbletea"
|
||
"github.com/charmbracelet/huh"
|
||
"github.com/charmbracelet/lipgloss"
|
||
)
|
||
|
||
// Every screen is drawn inside one frame: a header with the version and the
|
||
// site, the stages of an install down the left, the screen itself on the
|
||
// right, and the keys that work on it along the bottom. Each runs on the
|
||
// alternate screen, so nothing of the last one is left above the next.
|
||
|
||
var stages = []string{"Start", "Proxmox", "Site", "Review", "Install", "Check", "Test cluster"}
|
||
|
||
const (
|
||
stStart = iota
|
||
stProxmox
|
||
stSite
|
||
stReview
|
||
stInstall
|
||
stCheck
|
||
stTest
|
||
)
|
||
|
||
// header is what the frame says about this run.
|
||
var header struct {
|
||
version, site string
|
||
// inInstall marks the stages before the current one as done.
|
||
inInstall bool
|
||
}
|
||
|
||
// sized is a screen that wants to know how much room it has.
|
||
type sized interface{ setSize(w, h int) }
|
||
|
||
type frame struct {
|
||
stage int
|
||
title string
|
||
hints string
|
||
inner tea.Model
|
||
w, h int
|
||
// done is set when the inner screen has finished.
|
||
done bool
|
||
}
|
||
|
||
const sideW = 22
|
||
|
||
func (f *frame) Init() tea.Cmd { return f.inner.Init() }
|
||
|
||
// contentSize is the room inside the panel. Every column and row of the
|
||
// window is accounted for: the sidebar is sideW plus its border, one
|
||
// column of gap, the panel's padding and border; above, the header and
|
||
// its rule, the panel's title and border; below, the keys. A frame one row
|
||
// too tall scrolls its own header off the top.
|
||
func (f *frame) contentSize() (int, int) {
|
||
return max(f.w-sideW-2-1-4-2, 30), max(f.h-2-1-2-1, 8)
|
||
}
|
||
|
||
func (f *frame) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||
if ws, ok := msg.(tea.WindowSizeMsg); ok {
|
||
f.w, f.h = ws.Width, ws.Height
|
||
cw, ch := f.contentSize()
|
||
if s, ok := f.inner.(sized); ok {
|
||
s.setSize(cw, ch)
|
||
}
|
||
if fm, ok := f.inner.(*huh.Form); ok {
|
||
fm.WithWidth(cw).WithHeight(ch)
|
||
}
|
||
}
|
||
m, cmd := f.inner.Update(msg)
|
||
f.inner = m
|
||
if fm, ok := m.(*huh.Form); ok && fm.State != huh.StateNormal {
|
||
f.done = true
|
||
return f, tea.Quit
|
||
}
|
||
return f, cmd
|
||
}
|
||
|
||
func (f *frame) View() string {
|
||
if f.w == 0 {
|
||
return ""
|
||
}
|
||
cw, ch := f.contentSize()
|
||
|
||
// Header: the name on the left, version and site on the right.
|
||
left := sAcc.Render(" ◆ hpcod") + sTitle.Render(" setup")
|
||
right := sDim.Render(header.version)
|
||
if header.site != "" {
|
||
right = sDim.Render(header.site+" · ") + right
|
||
}
|
||
gap := max(f.w-lipgloss.Width(left)-lipgloss.Width(right)-2, 1)
|
||
top := left + strings.Repeat(" ", gap) + right + " "
|
||
rule := sFaint.Render(strings.Repeat("─", f.w))
|
||
|
||
// The stages.
|
||
var side strings.Builder
|
||
side.WriteString(sDim.Render("STEPS") + "\n\n")
|
||
for i, s := range stages {
|
||
switch {
|
||
case i == f.stage:
|
||
side.WriteString(sAcc.Render("› "+s) + "\n")
|
||
case i < f.stage && header.inInstall:
|
||
side.WriteString(sOK.Render("✓ ") + sText.Render(s) + "\n")
|
||
default:
|
||
side.WriteString(sFaint.Render("· "+s) + "\n")
|
||
}
|
||
}
|
||
sidebar := lipgloss.NewStyle().Width(sideW).Height(ch+1).Padding(1, 2).
|
||
Border(lipgloss.RoundedBorder()).BorderForeground(cDim).Render(side.String())
|
||
|
||
// The screen itself, clipped to its box.
|
||
body := f.inner.View()
|
||
lines := strings.Split(body, "\n")
|
||
if len(lines) > ch {
|
||
lines = lines[len(lines)-ch:]
|
||
}
|
||
content := lipgloss.NewStyle().Width(cw).Height(ch).MaxHeight(ch).Render(strings.Join(lines, "\n"))
|
||
titled := sBlue.Render(f.title) + "\n" + content
|
||
panel := lipgloss.NewStyle().Padding(0, 2).
|
||
Border(lipgloss.RoundedBorder()).BorderForeground(cBlue).Render(titled)
|
||
|
||
mid := lipgloss.JoinHorizontal(lipgloss.Top, sidebar, " ", panel)
|
||
foot := " " + f.hints
|
||
if f.hints == "" {
|
||
foot = " " + keys("enter", "continue", "esc", "back", "ctrl+c", "quit")
|
||
}
|
||
return top + "\n" + rule + "\n" + mid + "\n" + foot
|
||
}
|
||
|
||
// keys renders pairs of key and meaning for the footer.
|
||
func keys(kv ...string) string {
|
||
var parts []string
|
||
for i := 0; i+1 < len(kv); i += 2 {
|
||
parts = append(parts, sKey.Render(kv[i])+" "+sDim.Render(kv[i+1]))
|
||
}
|
||
return strings.Join(parts, " ")
|
||
}
|
||
|
||
// show runs one screen in the frame and returns its final state.
|
||
func show(stage int, title, hints string, inner tea.Model) (tea.Model, error) {
|
||
f := &frame{stage: stage, title: title, hints: hints, inner: inner}
|
||
if _, err := tea.NewProgram(f, tea.WithAltScreen()).Run(); err != nil {
|
||
return nil, err
|
||
}
|
||
return f.inner, nil
|
||
}
|
||
|
||
// ask runs a form in the frame. Esc as well as ctrl+c leaves it.
|
||
func ask(stage int, title string, form *huh.Form) error {
|
||
km := huh.NewDefaultKeyMap()
|
||
km.Quit = key.NewBinding(key.WithKeys("ctrl+c", "esc"), key.WithHelp("esc", "back"))
|
||
form = form.WithTheme(formTheme()).WithKeyMap(km).WithShowHelp(false)
|
||
if _, err := show(stage, title, keys("↑↓", "move", "enter", "next", "esc", "back"), form); err != nil {
|
||
return err
|
||
}
|
||
if form.State == huh.StateAborted {
|
||
return huh.ErrUserAborted
|
||
}
|
||
return nil
|
||
}
|