diff --git a/CHANGELOG.md b/CHANGELOG.md
index 63ca6e67..46afdf0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,22 @@ one too old for the test is refused at once instead of waited for.
Written against perftest's real output and tested with it, but not yet run
over real InfiniBand or RoCE: this cluster has neither.
+### The mirror on its own machine, in two commands
+
+`llmgw mirror init --control-plane
` sets a machine up as the model
+mirror: the user, `/srv/models`, and a service serving files to every node on
+:8081 and the management API on :8082. `server init --mirror
+http://:8082` uses it instead of running one beside the control plane.
+It took a unit written by hand and an edit to `server.yaml` before.
+
+The management API can fetch and delete models; `mirror serve --api-allow`
+makes it answer only the addresses given and the machine itself, and `mirror
+init` gives it the control plane's. With `--no-node`, the starter model is
+fetched and catalogued anyway, unpinned, and starts on the first node added.
+
+Tried on three empty VMs: mirror, control plane and a node, and a request
+answered by the starter model on the node.
+
### `server init` asks, and `node add` takes several nodes
- **`sudo llmgw server init`** in a terminal, without `--admin`, asks for the
diff --git a/docs/quick-install.md b/docs/quick-install.md
index 36ead553..cc77db5a 100644
--- a/docs/quick-install.md
+++ b/docs/quick-install.md
@@ -56,6 +56,19 @@ sudo llmgw server init --admin you@example.com --host llm.example.com
It is safe to run again. It keeps what exists and finishes what is missing.
+**The mirror on its own machine**, when it wants a larger disk than the
+control plane has: first on that machine, with llmgw installed as in step 1,
+
+```
+sudo llmgw mirror init --control-plane
+```
+
+then on the control plane `sudo llmgw server init --mirror http://:8082`. The mirror serves model files to every node, and takes
+orders only from the control plane. Untick "This machine as a node" in the
+form (or add `--no-node`) to keep models off the control plane; the starter
+model then starts on the first node you add.
+
**Check:** open `http://:8080/chat`, sign in with the printed
password, and ask something. The small model answers. Change the password on
the account page.
diff --git a/internal/cli/mirror.go b/internal/cli/mirror.go
index 934f633d..113d4c72 100644
--- a/internal/cli/mirror.go
+++ b/internal/cli/mirror.go
@@ -4,7 +4,9 @@ import (
"encoding/json"
"fmt"
"log/slog"
+ "net"
"net/http"
+ "net/netip"
"os"
"strings"
"time"
@@ -44,6 +46,7 @@ func newMirrorCmd() *cobra.Command {
newMirrorUnusedCmd(&dir),
newMirrorRemoveCmd(&dir),
newMirrorServeCmd(&dir),
+ newMirrorInitCmd(&dir),
)
return c
}
@@ -229,6 +232,7 @@ func newMirrorRemoveCmd(dir *string) *cobra.Command {
func newMirrorServeCmd(dir *string) *cobra.Command {
var listen, apiListen, base string
var tlsc tlsconf.Config
+ var allow []string
c := &cobra.Command{
Use: "serve",
@@ -268,9 +272,13 @@ func newMirrorServeCmd(dir *string) *cobra.Command {
Handler: readOnly(withManifest(*dir, http.FileServer(http.Dir(*dir)))),
ReadHeaderTimeout: 10 * time.Second,
}
+ allowed, err := parseAllow(allow)
+ if err != nil {
+ return err
+ }
admin := &http.Server{
Addr: apiListen,
- Handler: api.Handler(),
+ Handler: onlyFrom(allowed, api.Handler()),
ReadHeaderTimeout: 10 * time.Second,
}
@@ -279,9 +287,12 @@ func newMirrorServeCmd(dir *string) *cobra.Command {
fmt.Fprintf(out, "serving %s on %s\n", *dir, listen)
go func() { errs <- fmt.Errorf("serving the API: %w", serveAPI(admin, tlsc)) }()
- if tlsc.Enabled() {
+ switch {
+ case tlsc.Enabled():
fmt.Fprintf(out, "management API on %s, mutual TLS against %s\n", apiListen, tlsc.CA)
- } else {
+ case len(allowed) > 0:
+ fmt.Fprintf(out, "management API on %s, for %s and this machine only\n", apiListen, strings.Join(allow, ", "))
+ default:
// Said plainly rather than left to be discovered. An API that
// can delete models and start downloads, open to anyone who can
// reach the port, is a choice the operator should have made
@@ -300,6 +311,8 @@ func newMirrorServeCmd(dir *string) *cobra.Command {
c.Flags().StringVar(&apiListen, "api-listen", ":8082", "address to serve the management API on")
c.Flags().StringVar(&base, "base", "http://localhost:8081",
"the address nodes use to reach this mirror, as it should appear in catalog sources")
+ c.Flags().StringArrayVar(&allow, "api-allow", nil,
+ "an address or network the management API answers, besides this machine; repeatable (default: anyone)")
c.Flags().StringVar(&tlsc.CA, "tls-ca", "", "CA bundle that management clients must present a certificate from")
c.Flags().StringVar(&tlsc.Cert, "tls-cert", "", "this mirror's certificate")
c.Flags().StringVar(&tlsc.Key, "tls-key", "", "this mirror's private key")
@@ -398,3 +411,54 @@ func versionPath(p string) (model, version string, ok bool) {
}
return parts[0], parts[1], true
}
+
+// parseAllow reads addresses and networks: 10.0.0.140, 10.0.0.0/24.
+func parseAllow(list []string) ([]netip.Prefix, error) {
+ var out []netip.Prefix
+ for _, s := range list {
+ for _, one := range strings.Split(s, ",") {
+ one = strings.TrimSpace(one)
+ if one == "" {
+ continue
+ }
+ if p, err := netip.ParsePrefix(one); err == nil {
+ out = append(out, p.Masked())
+ continue
+ }
+ a, err := netip.ParseAddr(one)
+ if err != nil {
+ return nil, fmt.Errorf("--api-allow %q is not an address or a network", one)
+ }
+ out = append(out, netip.PrefixFrom(a.Unmap(), a.Unmap().BitLen()))
+ }
+ }
+ return out, nil
+}
+
+// onlyFrom answers only this machine and the addresses allowed, when any
+// are: the management API can delete models and start downloads, and a
+// mirror on its own machine is reached over the network by one control plane
+// and no one else. Nothing allowed is the old behaviour, anyone.
+func onlyFrom(allowed []netip.Prefix, next http.Handler) http.Handler {
+ if len(allowed) == 0 {
+ return next
+ }
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ host, _, err := net.SplitHostPort(r.RemoteAddr)
+ a, perr := netip.ParseAddr(host)
+ if err != nil || perr != nil {
+ http.Error(w, "forbidden", http.StatusForbidden)
+ return
+ }
+ a = a.Unmap()
+ ok := a.IsLoopback()
+ for _, p := range allowed {
+ ok = ok || p.Contains(a)
+ }
+ if !ok {
+ http.Error(w, "this mirror is managed by its control plane only", http.StatusForbidden)
+ return
+ }
+ next.ServeHTTP(w, r)
+ })
+}
diff --git a/internal/cli/mirrorinit.go b/internal/cli/mirrorinit.go
new file mode 100644
index 00000000..35430fbe
--- /dev/null
+++ b/internal/cli/mirrorinit.go
@@ -0,0 +1,125 @@
+package cli
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "io"
+ "net"
+ "os"
+ "runtime"
+ "strings"
+ "time"
+
+ "github.com/spf13/cobra"
+
+ "gitea.mynodes.xyz/ilker/llmgw/internal/mirror"
+ "gitea.mynodes.xyz/ilker/llmgw/internal/tlsconf"
+)
+
+// mirror init sets a machine up as the cluster's model mirror, on its own:
+// the bytes for every node on :8081, the management API on :8082 for the
+// control plane alone. server init does the same beside the control plane;
+// this is for when the mirror wants its own disk.
+
+func newMirrorInitCmd(dir *string) *cobra.Command {
+ var (
+ controlPlanes []string
+ base string
+ )
+ cmd := &cobra.Command{
+ Use: "init",
+ Short: "Set this machine up as the cluster's model mirror and start it",
+ Long: `Creates the llmgw user and the mirror's directory, and a systemd unit that
+serves the model files to every node on :8081 and the management API on
+:8082, and starts it.
+
+The management API can fetch and delete models, so it answers this machine
+and the control planes given with --control-plane, and nobody else. Then on
+the control plane:
+
+ sudo llmgw server init --mirror http://:8082
+
+Safe to run again: it changes only what differs.`,
+ Example: ` sudo llmgw mirror init --control-plane 10.0.0.10`,
+ Args: cobra.NoArgs,
+ RunE: func(cmd *cobra.Command, _ []string) error {
+ if runtime.GOOS != "linux" {
+ return fmt.Errorf("mirror init sets up a Linux machine; this is %s", runtime.GOOS)
+ }
+ if os.Geteuid() != 0 {
+ return errors.New("mirror init creates a user, writes /etc and starts a service: run it as root")
+ }
+ if len(controlPlanes) == 0 {
+ return errors.New("--control-plane: which control plane manages this mirror (its address)")
+ }
+ if _, err := parseAllow(controlPlanes); err != nil {
+ return err
+ }
+ return mirrorInit(cmd.Context(), cmd.OutOrStdout(), *dir, base, controlPlanes)
+ },
+ }
+ cmd.Flags().StringArrayVar(&controlPlanes, "control-plane", nil,
+ "address of the control plane that manages this mirror; repeatable")
+ cmd.Flags().StringVar(&base, "base", "",
+ "the address nodes fetch from, http://host:8081 (default: this machine's first address)")
+ return cmd
+}
+
+func mirrorInit(ctx context.Context, out io.Writer, dir, base string, controlPlanes []string) error {
+ in := &serverInit{user: "llmgw", stateDir: "/var/lib/llmgw", out: out}
+ if err := in.ensureUser(ctx); err != nil {
+ return err
+ }
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ return err
+ }
+ if err := in.chown(dir, true); err != nil {
+ return err
+ }
+ addr := ""
+ if ips := localAddrs(); len(ips) > 0 {
+ addr = ips[0].String()
+ }
+ if base == "" {
+ if addr == "" {
+ return errors.New("this machine has no address to give nodes; give one with --base")
+ }
+ base = "http://" + net.JoinHostPort(addr, "8081")
+ }
+ unit := mirrorUnitFor(dir, ":8082", base, controlPlanes,
+ "'llmgw mirror init'. Bytes on :8081 for every node; the\n# management API on :8082, for the control plane only.")
+ changed, err := in.writeUnit(mirrorUnitPath, unit)
+ if err != nil {
+ return err
+ }
+ for _, args := range [][]string{{"daemon-reload"}, {"enable", "--now", "llmgw-mirror"}} {
+ if err := in.systemctl(ctx, args...); err != nil {
+ return err
+ }
+ }
+ if changed {
+ if err := in.systemctl(ctx, "restart", "llmgw-mirror"); err != nil {
+ return err
+ }
+ in.done("model mirror in %s: files on :8081 at %s, management on :8082 for %s", dir, base, strings.Join(controlPlanes, ", "))
+ } else {
+ in.kept("model mirror in %s", dir)
+ }
+ m, err := mirror.NewClient("http://127.0.0.1:8082", tlsconf.Config{}, 5*time.Second)
+ if err != nil {
+ return err
+ }
+ if err := waitFor(ctx, 30*time.Second, "the mirror to answer", func() (bool, error) {
+ return m.Health(ctx) == nil, nil
+ }); err != nil {
+ return err
+ }
+ in.kept("answering")
+ api := "http://:8082"
+ if addr != "" {
+ api = "http://" + net.JoinHostPort(addr, "8082")
+ }
+ fmt.Fprintf(out, "\nThe mirror is up. On the control plane:\n\n sudo llmgw server init --mirror %s\n\n", api)
+ return nil
+}
diff --git a/internal/cli/serverinit.go b/internal/cli/serverinit.go
index e1aa577d..7d3a9109 100644
--- a/internal/cli/serverinit.go
+++ b/internal/cli/serverinit.go
@@ -73,6 +73,8 @@ type serverInit struct {
// make it serve something: a mirror, this machine as a node, and a small
// model on it.
noMirror, noNode, noModel bool
+ // mirrorURL is a mirror on another machine to use instead of running one.
+ mirrorURL string
// pgSetup prepares PostgreSQL and returns the store address; a seam for
// tests. Nil does it for real.
pgSetup func(context.Context) (string, error)
@@ -136,6 +138,8 @@ func newServerInitCmd() *cobra.Command {
f.StringVar(&in.admin, "admin", "", "email of the first administrator; a password is generated and printed once")
f.StringVar(&in.pkiDir, "pki", in.pkiDir, "directory holding the certificate authority")
f.BoolVar(&in.noMirror, "no-mirror", false, "do not run a model mirror on this machine")
+ f.StringVar(&in.mirrorURL, "mirror", "",
+ "use the mirror on another machine, set up there by 'llmgw mirror init': its management API, http://host:8082")
f.BoolVar(&in.noNode, "no-node", false, "do not make this machine a node (and serve no model on it)")
f.BoolVar(&in.noModel, "no-model", false, "do not fetch and serve the starter model ("+starterName+")")
f.BoolVar(&in.postgres, "postgres", false,
@@ -168,7 +172,12 @@ func (in *serverInit) run(ctx context.Context) error {
hasSystemd = false
}
// Before the service starts, because the mirror goes into server.yaml.
- if hasSystemd && !in.noMirror {
+ switch {
+ case in.mirrorURL != "":
+ if err := in.useMirror(ctx); err != nil {
+ return fmt.Errorf("mirror: %w", err)
+ }
+ case hasSystemd && !in.noMirror:
if err := in.ensureMirror(ctx); err != nil {
return fmt.Errorf("mirror: %w", err)
}
@@ -180,14 +189,14 @@ func (in *serverInit) run(ctx context.Context) error {
if _, err := in.ensureNode(ctx); err != nil {
return fmt.Errorf("node: %w", err)
}
- switch {
- case in.noModel:
- case in.noMirror:
- fmt.Fprintln(in.out, " skip no starter model without the mirror")
- default:
- if err := in.ensureStarter(ctx); err != nil {
- return fmt.Errorf("starter model: %w", err)
- }
+ }
+ switch {
+ case !hasSystemd || in.noModel:
+ case in.noMirror && in.mirrorURL == "":
+ fmt.Fprintln(in.out, " skip no starter model without the mirror")
+ default:
+ if err := in.ensureStarter(ctx); err != nil {
+ return fmt.Errorf("starter model: %w", err)
}
}
in.nextSteps()
diff --git a/internal/cli/serverinit_cluster.go b/internal/cli/serverinit_cluster.go
index dc9d7bcc..2d9e492f 100644
--- a/internal/cli/serverinit_cluster.go
+++ b/internal/cli/serverinit_cluster.go
@@ -111,15 +111,25 @@ func (in *serverInit) writeUnit(path, body string) (bool, error) {
func (in *serverInit) mirrorUnit() string {
base := "http://" + net.JoinHostPort(in.reachableAddr(), "8081")
+ return mirrorUnitFor(mirrorDir, mirrorAPI, base, nil,
+ "'llmgw server init'. Bytes on :8081 for every node; the\n# management API on loopback only, for the control plane beside it.")
+}
+
+// mirrorUnitFor is a mirror's systemd unit. allow is who, besides the
+// machine itself, may use the management API.
+func mirrorUnitFor(dir, apiListen, base string, allow []string, about string) string {
+ exec := "/usr/local/bin/llmgw mirror serve --dir " + dir + " --listen :8081 --api-listen " + apiListen + " --base " + base
+ for _, a := range allow {
+ exec += " --api-allow " + a
+ }
return `[Unit]
Description=llmgw model mirror
After=network-online.target
Wants=network-online.target
[Service]
-# Written by 'llmgw server init'. Bytes on :8081 for every node; the
-# management API on loopback only, for the control plane beside it.
-ExecStart=/usr/local/bin/llmgw mirror serve --dir ` + mirrorDir + ` --listen :8081 --api-listen ` + mirrorAPI + ` --base ` + base + `
+# Written by ` + about + `
+ExecStart=` + exec + `
User=llmgw
Group=llmgw
Restart=on-failure
@@ -128,13 +138,53 @@ NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
-ReadWritePaths=` + mirrorDir + `
+ReadWritePaths=` + dir + `
[Install]
WantedBy=multi-user.target
`
}
+// mirrorAPIURL is the mirror's management API: one on its own machine, or
+// the one beside this control plane.
+func (in *serverInit) mirrorAPIURL() string {
+ if in.mirrorURL != "" {
+ return in.mirrorURL
+ }
+ return "http://" + mirrorAPI
+}
+
+// useMirror points the control plane at a mirror on another machine, set up
+// there by 'llmgw mirror init'.
+func (in *serverInit) useMirror(ctx context.Context) error {
+ m, err := mirror.NewClient(in.mirrorURL, tlsconf.Config{}, 5*time.Second)
+ if err != nil {
+ return err
+ }
+ if err := m.Health(ctx); err != nil {
+ return fmt.Errorf("the mirror at %s does not answer: %v. On that machine: sudo llmgw mirror init --control-plane ", in.mirrorURL, err)
+ }
+ cfg, err := config.Load(in.configPath())
+ if err != nil {
+ return err
+ }
+ switch cfg.Mirror.API {
+ case in.mirrorURL:
+ in.kept("mirror at %s", in.mirrorURL)
+ return nil
+ case "":
+ default:
+ in.kept("mirror at %s, as server.yaml says; change it there to use %s", cfg.Mirror.API, in.mirrorURL)
+ return nil
+ }
+ if err := appendMirrorBlockFor(in.configPath(), in.mirrorURL,
+ "# The model mirror, on its own machine, added by 'llmgw server init'."); err != nil {
+ return err
+ }
+ in.done("server.yaml points at the mirror at %s", in.mirrorURL)
+ return nil
+}
+
// ensureMirror runs a mirror on this machine and points the control plane at
// it. Its management API is on loopback, which is why it needs no certificate:
// nothing but this machine can reach it.
@@ -174,7 +224,9 @@ func (in *serverInit) ensureMirror(ctx context.Context) error {
}
if cfg.Mirror.API == "" {
- if err := appendMirrorBlock(in.configPath()); err != nil {
+ if err := appendMirrorBlockFor(in.configPath(), "http://"+mirrorAPI,
+ "# The model mirror on this machine, added by 'llmgw server init'. Its\n"+
+ "# management API is on loopback, so it needs no certificate."); err != nil {
return err
}
in.done("server.yaml points at the mirror")
@@ -189,9 +241,9 @@ func (in *serverInit) ensureMirror(ctx context.Context) error {
})
}
-// appendMirrorBlock adds the mirror to server.yaml without touching the rest,
-// keeping the file as it was beside it.
-func appendMirrorBlock(path string) error {
+// appendMirrorBlockFor adds the mirror to server.yaml without touching the
+// rest, keeping the file as it was beside it.
+func appendMirrorBlockFor(path, api, comment string) error {
b, err := os.ReadFile(path)
if err != nil {
return err
@@ -200,9 +252,7 @@ func appendMirrorBlock(path string) error {
if err := os.WriteFile(backup, b, 0o640); err != nil {
return err
}
- block := "\n# The model mirror on this machine, added by 'llmgw server init'. Its\n" +
- "# management API is on loopback, so it needs no certificate.\n" +
- "mirror:\n api: http://" + mirrorAPI + "\n"
+ block := "\n" + comment + "\nmirror:\n api: " + api + "\n"
info, err := os.Stat(path)
if err != nil {
return err
@@ -356,8 +406,11 @@ func hasNVIDIADevice() bool {
// starterModel is the catalog entry: a GPU profile first when there is a card,
// and a CPU profile always, both pinned to this machine.
-func starterModel(source string, gpuClasses []string) catalog.Model {
- pin := map[string]string{localLabelKey: localLabelValue}
+func starterModel(source string, gpuClasses []string, pinned bool) catalog.Model {
+ var pin map[string]string
+ if pinned {
+ pin = map[string]string{localLabelKey: localLabelValue}
+ }
var profiles []catalog.Profile
for _, class := range gpuClasses {
profiles = append(profiles, catalog.Profile{
@@ -401,7 +454,7 @@ func (in *serverInit) ensureStarter(ctx context.Context) error {
if !ok {
return fmt.Errorf("cannot turn %s into a download", starterSource)
}
- m, err := mirror.NewClient("http://"+mirrorAPI, tlsconf.Config{}, 15*time.Second)
+ m, err := mirror.NewClient(in.mirrorAPIURL(), tlsconf.Config{}, 15*time.Second)
if err != nil {
return err
}
@@ -444,14 +497,24 @@ func (in *serverInit) ensureStarter(ctx context.Context) error {
}
in.done("%s in the mirror", starterName)
- classes, _ := gpuClasses(ctx)
- body, err := json.Marshal(starterModel(st.URL, classes))
+ // Served here when this machine is a node, pinned so it does not wander
+ // to the first GPU node that joins; otherwise on whichever node joins.
+ pinned := !in.noNode
+ var classes []string
+ if pinned {
+ classes, _ = gpuClasses(ctx)
+ }
+ body, err := json.Marshal(starterModel(st.URL, classes, pinned))
if err != nil {
return err
}
if err := client.post(ctx, "/api/v1/models", body, &map[string]string{}); err != nil {
return fmt.Errorf("adding %s to the catalog: %w", starterName, err)
}
+ if !pinned {
+ in.done("%s in the catalog; it starts on the first node that joins", starterName)
+ return nil
+ }
where := "on CPU"
if len(classes) > 0 {
where = "on " + strings.Join(classes, ", ") + ", or CPU if the card is busy"
diff --git a/internal/cli/serverinit_cluster_test.go b/internal/cli/serverinit_cluster_test.go
index 0c29fc39..bdd36cfc 100644
--- a/internal/cli/serverinit_cluster_test.go
+++ b/internal/cli/serverinit_cluster_test.go
@@ -1,6 +1,8 @@
package cli
import (
+ "net/http"
+ "net/http/httptest"
"os"
"path/filepath"
"strings"
@@ -21,7 +23,7 @@ func TestTheInitAgentUnitIsTheShippedUnit(t *testing.T) {
}
func TestTheStarterUsesTheGPUAndFallsBackToCPUOnThisMachine(t *testing.T) {
- m := starterModel("http://10.0.0.5:8081/qwen2.5-0.5b-instruct/starter/q.gguf", []string{"4090-24g"})
+ m := starterModel("http://10.0.0.5:8081/qwen2.5-0.5b-instruct/starter/q.gguf", []string{"4090-24g"}, true)
c, err := catalog.New([]catalog.Model{m})
if err != nil {
t.Fatalf("the starter is not a valid catalog entry: %v", err)
@@ -46,7 +48,7 @@ func TestTheStarterUsesTheGPUAndFallsBackToCPUOnThisMachine(t *testing.T) {
t.Error("the starter should be running, not waiting to be asked for")
}
- if m := starterModel("http://x/q.gguf", nil); len(m.Profiles) != 1 || m.Profiles[0].Name != "cpu" {
+ if m := starterModel("http://x/q.gguf", nil, true); len(m.Profiles) != 1 || m.Profiles[0].Name != "cpu" {
t.Errorf("without a GPU only the CPU profile: %+v", m.Profiles)
}
}
@@ -56,7 +58,7 @@ func TestTheMirrorBlockIsAddedAndReads(t *testing.T) {
if err := in.run(t.Context()); err != nil {
t.Fatalf("%v\n%s", err, out)
}
- if err := appendMirrorBlock(in.configPath()); err != nil {
+ if err := appendMirrorBlockFor(in.configPath(), "http://"+mirrorAPI, "# the mirror"); err != nil {
t.Fatal(err)
}
cfg, err := config.Load(in.configPath())
@@ -87,3 +89,35 @@ func TestTheMirrorUnitAdvertisesAnAddressNodesCanReach(t *testing.T) {
t.Errorf("the management API is not on loopback: %s", u)
}
}
+
+func TestWithNoNodeHereTheStarterGoesToTheFirstNodeThatJoins(t *testing.T) {
+ m := starterModel("http://x/q.gguf", nil, false)
+ for _, p := range m.Profiles {
+ if len(p.NodeSelector) > 0 {
+ t.Errorf("profile %s is pinned to a machine that is not a node: %v", p.Name, p.NodeSelector)
+ }
+ }
+}
+
+func TestTheMirrorAPIOnlyAnswersItsControlPlane(t *testing.T) {
+ allowed, err := parseAllow([]string{"10.0.0.140", "10.1.0.0/24"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ h := onlyFrom(allowed, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {}))
+ for addr, want := range map[string]int{
+ "10.0.0.140:5000": 200, "10.1.0.7:5000": 200, "127.0.0.1:5000": 200, "[::1]:5000": 200,
+ "10.0.0.141:5000": 403, "192.168.1.9:5000": 403,
+ } {
+ r := httptest.NewRequest("GET", "/api/v1/health", nil)
+ r.RemoteAddr = addr
+ w := httptest.NewRecorder()
+ h.ServeHTTP(w, r)
+ if w.Code != want {
+ t.Errorf("%s: %d, want %d", addr, w.Code, want)
+ }
+ }
+ if _, err := parseAllow([]string{"not-an-address"}); err == nil {
+ t.Error("nonsense was accepted")
+ }
+}
diff --git a/internal/cli/tui_init.go b/internal/cli/tui_init.go
index 0edc9d59..ad111c20 100644
--- a/internal/cli/tui_init.go
+++ b/internal/cli/tui_init.go
@@ -227,6 +227,10 @@ func (m initModel) formKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
func (m *initModel) moveFocus(d int) {
m.focus = (m.focus + d + fCount) % fCount
+ // With --mirror there is no mirror to run here, so nothing to tick.
+ if m.focus == fMirror && m.in.mirrorURL != "" {
+ m.focus = (m.focus + d + fCount) % fCount
+ }
m.admin.Blur()
m.hosts.Blur()
switch m.focus {
@@ -325,9 +329,13 @@ func (m initModel) formView() string {
}
b.WriteString(" " + sDim.Render("Already in the certificate: "+found+". Add a DNS name or NAT address here.") + "\n\n")
b.WriteString(check(fPostgres, "PostgreSQL", "rather than SQLite; installed here, for several control planes or a larger store"))
- b.WriteString(check(fMirror, "Model mirror", "downloads model files once for every node"))
+ if m.in.mirrorURL != "" {
+ b.WriteString(" Model mirror " + sDim.Render("at "+m.in.mirrorURL+", from --mirror") + "\n")
+ } else {
+ b.WriteString(check(fMirror, "Model mirror", "downloads model files once for every node"))
+ }
b.WriteString(check(fNode, "This machine as a node", "serves models here too, on its GPUs or CPU"))
- b.WriteString(check(fModel, "Starter model", "a small Qwen, so /chat answers at once"))
+ b.WriteString(check(fModel, "Starter model", "a small Qwen, so there is something to ask at once"))
b.WriteString("\n" + label(fStart, lipgloss.NewStyle().Bold(true).Render("Set up")) + "\n")
if m.formError != "" {
b.WriteString("\n" + sBad.Render(m.formError) + "\n")
diff --git a/internal/cli/tui_init_test.go b/internal/cli/tui_init_test.go
index d1c1de97..bd4e6955 100644
--- a/internal/cli/tui_init_test.go
+++ b/internal/cli/tui_init_test.go
@@ -87,3 +87,17 @@ func TestInitsLinesAreFiledAndThePasswordKeptInView(t *testing.T) {
t.Error("the closing text was listed as a step")
}
}
+
+func TestWithAMirrorElsewhereTheFormDoesNotOfferOne(t *testing.T) {
+ in := &serverInit{mirrorURL: "http://10.0.0.150:8082"}
+ var m tea.Model = newInitModel(in, nil, true)
+ if v := m.View(); !strings.Contains(v, "at http://10.0.0.150:8082, from --mirror") {
+ t.Errorf("the mirror in use is not shown:\n%s", v)
+ }
+ // Tab from the addresses goes past the mirror line to PostgreSQL, then
+ // the node.
+ m = send(m, tea.KeyMsg{Type: tea.KeyTab}, tea.KeyMsg{Type: tea.KeyTab}, tea.KeyMsg{Type: tea.KeyTab})
+ if f := m.(initModel).focus; f != fNode {
+ t.Errorf("focus %d, want the node toggle %d", f, fNode)
+ }
+}