feat(master): Ledger UI for Services and Agents (#18) (#29)
Docker Build / docker (push) Successful in 41s
Docker Build / docker (push) Successful in 41s
## Summary
- Rebuilds the master's **Services** and **Agents** pages per the "Ledger" design: sidebar shell with live nav counts, machine filter and Live indicator; dark/light theme (follows the OS, toggle overrides); embedded Schibsted Grotesk and JetBrains Mono (fontsource 5.3.0, OFL).
- Services: Swarm grouped per cluster with its machines under it, offline banner ("Agent offline since HH:MM", browser-local), Simple Icons derived from the image ref (letter circle fallback), existing badges and mode switch restyled, client-side search, machine filter and Icon / Icon + text / Text toggle.
- Agents: Online / Offline / Never connected / Revoked, master version in the header with outdated agent versions marked, revoke via popover instead of `confirm()`, "Add agent" as a three-step panel that completes when the agent says hello (SSE `agents`).
- Store: migration `0005_agent_cluster.sql` persists each agent's `swarm_cluster_id` (needed to list a cluster's managers and its offline state after a master restart).
- SSE keepalive is now a named `ping` event so the Live indicator also shows the connection is alive. `revokeAgent` now publishes `agents`.
Closes #18
## Notes
- Workers never report a cluster id (Docker only sets `Swarm.Cluster` on managers), so their Swarm role shows "—". Fixing that needs a new hello field.
- Master binary grows by about 2.16 MB, almost all Simple Icons 16.35.0 path data (gzipped JSON, regenerated with `go generate ./internal/master/web/icons`). The agent binary does not import it.
- Jobs, Job and Service detail pages only get the new shell; their own artboards are out of scope, as are Update buttons, Update all, header stats and the drift badge.
- Unchanged: CSRF on every POST, `Cache-Control: no-store` on the token response, 401 + `HX-Redirect` without a session, no `template.HTML` on agent- or user-controlled values, no Node build step.
## Test plan
- [x] `go test ./...`, `go test -race ./internal/master/...`
- [x] `go test -tags integration ./internal/master/store/` against Postgres 17
- [x] `docker build`
- [x] Browser check on fake data: both themes, 1440 px and 390 px, add-agent flow through connect
- [ ] Services grouping and icons against real stacks and a real Swarm cluster
- [ ] "Agent offline since" after stopping an agent
- [ ] Theme toggle, search and machine filter across reloads and mode changes
- [ ] Add agent end to end with a real agent, Copy buttons
- [ ] Phone at 390 px
https://claude.ai/code/session_01GAZsp3P7Qto6JnhipxWUJQ
Reviewed-on: #29
This commit was merged in pull request #29.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
// Package icons maps container image references to brand icons from the
|
||||
// Simple Icons set (CC0, see LICENSE-simple-icons.md). Only the master's UI
|
||||
// imports it, so the agent binary does not carry the data.
|
||||
package icons
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/shcizo/package-updater/internal/imageref"
|
||||
)
|
||||
|
||||
//go:generate go run ./gen
|
||||
|
||||
//go:embed simple-icons.json.gz
|
||||
var data []byte
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
paths map[string]string
|
||||
)
|
||||
|
||||
// aliases maps a normalised image name to the Simple Icons slug that differs
|
||||
// from it.
|
||||
var aliases = map[string]string{
|
||||
"postgres": "postgresql",
|
||||
"goauthentik": "authentik",
|
||||
"traefik": "traefikproxy",
|
||||
"node": "nodedotjs",
|
||||
"mongo": "mongodb",
|
||||
}
|
||||
|
||||
// skipNamespaces are registry namespaces that name a publisher, not a product.
|
||||
var skipNamespaces = map[string]bool{"library": true, "linuxserver": true, "bitnami": true, "hotio": true}
|
||||
|
||||
// suffixes are stripped from the last path segment to find the product name
|
||||
// ("authentik-server" is authentik).
|
||||
var suffixes = []string{"-server", "-web", "-api", "-worker", "-agent"}
|
||||
|
||||
func load() {
|
||||
once.Do(func() {
|
||||
paths = map[string]string{}
|
||||
zr, err := gzip.NewReader(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_ = json.NewDecoder(zr).Decode(&paths)
|
||||
})
|
||||
}
|
||||
|
||||
// Path returns the SVG path data (24x24 viewBox) of the icon with this Simple
|
||||
// Icons slug.
|
||||
func Path(slug string) (string, bool) {
|
||||
load()
|
||||
p, ok := paths[slug]
|
||||
return p, ok
|
||||
}
|
||||
|
||||
// Count returns how many icons are embedded.
|
||||
func Count() int {
|
||||
load()
|
||||
return len(paths)
|
||||
}
|
||||
|
||||
// ForImage returns the slug of the icon that best matches the image
|
||||
// reference, or "" when there is none. It tries the last path segment, that
|
||||
// segment without a role suffix, and the namespace, in that order.
|
||||
func ForImage(ref string) string {
|
||||
segs := strings.Split(imageref.Parse(ref).Repo, "/")
|
||||
if len(segs) > 1 && imageref.IsRegistryHost(segs[0]) {
|
||||
segs = segs[1:]
|
||||
}
|
||||
last := segs[len(segs)-1]
|
||||
candidates := []string{last}
|
||||
for _, s := range suffixes {
|
||||
if base, ok := strings.CutSuffix(last, s); ok && base != "" {
|
||||
candidates = append(candidates, base)
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(segs) > 1 && !skipNamespaces[segs[len(segs)-2]] {
|
||||
candidates = append(candidates, segs[len(segs)-2])
|
||||
}
|
||||
for _, c := range candidates {
|
||||
slug := normalise(c)
|
||||
if a, ok := aliases[slug]; ok {
|
||||
slug = a
|
||||
}
|
||||
if _, ok := Path(slug); ok {
|
||||
return slug
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// normalise lowercases s and keeps only a-z and 0-9, the form of Simple Icons slugs.
|
||||
func normalise(s string) string {
|
||||
var b strings.Builder
|
||||
for _, r := range strings.ToLower(s) {
|
||||
if r >= 'a' && r <= 'z' || r >= '0' && r <= '9' {
|
||||
b.WriteRune(r)
|
||||
}
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
Reference in New Issue
Block a user