Phase 9, part 1: editions and their settings

SUPERMARKET_MODE picks local (the default), server or multi. internal/config
reads and checks every setting the editions need (database, secret key,
storage, the app's own mail, an https address), reporting all problems at
once. supermarket config prints them without passwords; supermarket
secret-key makes a key. Settings -> About shows the edition. Server and
multi-tenant are checked but refuse to start until they're built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 06:55:30 -07:00
co-authored by Claude Opus 5.5
parent 338eaa2c79
commit 7a857c7346
12 changed files with 671 additions and 9 deletions
+56 -8
View File
@@ -1,8 +1,9 @@
// Supermarket serves the marketing suite's web app. It's meant to run in
// its Docker container (see compose.yaml), with its data folder at /data.
//
// Environment:
// Environment (see internal/config):
//
// SUPERMARKET_MODE the edition: local (default), server or multi
// SUPERMARKET_DATA data folder (default /data)
// SUPERMARKET_ADDR listen address (default :8080)
// SUPERMARKET_PUBLIC_URL the address the browser uses (default http://localhost:8470)
@@ -10,6 +11,11 @@
// SUPERMARKET_MCP_SOCKET Unix socket for agents' MCP (default <data>/mcp.sock)
// SUPERMARKET_HOST_DATA the data folder's path on the host, to show in
// setup instructions (default: same as the data folder)
//
// The server and multi-tenant editions also need SUPERMARKET_DATABASE_URL,
// SUPERMARKET_SECRET_KEY and SUPERMARKET_MAIL_URL, and multi-tenant needs
// SUPERMARKET_STORAGE (s3://…) with SUPERMARKET_S3_*. `supermarket config`
// checks them; `supermarket secret-key` makes a key.
package main
import (
@@ -30,6 +36,7 @@ import (
"supermarket/internal/ai"
"supermarket/internal/backup"
"supermarket/internal/config"
"supermarket/internal/content"
"supermarket/internal/core"
"supermarket/internal/crm"
@@ -49,6 +56,18 @@ func main() {
fmt.Println(version)
return
}
if len(os.Args) > 1 && os.Args[1] == "secret-key" {
k, err := config.NewKey()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(k)
return
}
if len(os.Args) > 1 && os.Args[1] == "config" {
os.Exit(configCommand())
}
if len(os.Args) > 1 && (os.Args[1] == "backup" || os.Args[1] == "backups" || os.Args[1] == "restore") {
if err := backupCommand(os.Args[1], os.Args[2:]); err != nil {
fmt.Fprintln(os.Stderr, err)
@@ -70,13 +89,41 @@ func env(key, def string) string {
return def
}
// configCommand prints the settings, without passwords or keys, and any
// problems with them. It exits 1 if there are some.
func configCommand() int {
cfg, err := config.Load(os.Getenv)
for _, it := range cfg.Summary() {
fmt.Printf("%-9s %s\n", it.Name+":", it.Value)
}
if err == nil {
err = cfg.Ready()
}
if err != nil {
fmt.Println()
fmt.Println("Problems:")
for _, line := range strings.Split(err.Error(), "\n") {
fmt.Println(" - " + line)
}
return 1
}
fmt.Println("\nThe settings are fine.")
return 0
}
func run(log *slog.Logger) error {
dataDir := env("SUPERMARKET_DATA", "/data")
addr := env("SUPERMARKET_ADDR", ":8080")
publicURL := strings.TrimRight(env("SUPERMARKET_PUBLIC_URL", "http://localhost:8470"), "/")
coreConf := env("SUPERMARKET_CORE_CONF", filepath.Join(dataDir, "core.conf"))
mcpSocket := env("SUPERMARKET_MCP_SOCKET", filepath.Join(dataDir, "mcp.sock"))
hostData := env("SUPERMARKET_HOST_DATA", dataDir)
cfg, err := config.Load(os.Getenv)
if err != nil {
for _, problem := range strings.Split(err.Error(), "\n") {
log.Error("settings: " + problem)
}
return errors.New("the settings need fixing: supermarket config shows them")
}
if err := cfg.Ready(); err != nil {
return err
}
dataDir, addr, publicURL := cfg.DataDir, cfg.Addr, cfg.PublicURL
coreConf, mcpSocket, hostData := cfg.CoreConf, cfg.MCPSocket, cfg.HostData
// Everything the app writes (database, secrets, clones) is for this user
// only: it will hold contacts and credentials.
@@ -155,6 +202,7 @@ func run(log *slog.Logger) error {
}
srv := &web.Server{
Config: cfg,
DB: database,
Secrets: sec,
Core: c,
@@ -215,7 +263,7 @@ func run(log *slog.Logger) error {
}
}()
go func() {
log.Info("Supermarket is running", "version", version, "listen", addr, "open", publicURL)
log.Info("Supermarket is running", "version", version, "edition", cfg.Edition, "listen", addr, "open", publicURL)
errCh <- httpServer.ListenAndServe()
}()