Native Windows deployment: config file, service, signed auto-update
- internal/config: .env-style config file (gpu-turnstile.env next to the exe, -config flag or GPU_TURNSTILE_CONFIG); process env overrides file. - internal/service: Windows service via golang.org/x/sys/windows/svc — graceful SCM stop, 'service install/remove' commands, restart-on-failure recovery (also applies staged updates). First external dependency, Windows-only; Linux/Docker build unaffected (go.mod stays at 1.23). - internal/update: polls the Gitea releases API, verifies the Ed25519 signature of the downloaded binary against an embedded public key (openssl-signed by CI), swaps it in next to the running exe, and once the GPU lock is idle exits with code 3 so service recovery restarts onto the new version. Dev builds and empty pubkey never update. - CI: tag builds additionally produce gpu-turnstile.exe + .sig + .sha256 attached to a Gitea release. - LOG_FILE env var so the service has somewhere to log.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDefaults(t *testing.T) {
|
||||
cfg, err := Load(func(string) string { return "" })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.ListenOllama != ":11434" || cfg.ListenComfy != ":8188" {
|
||||
t.Fatalf("listen addrs = %s %s", cfg.ListenOllama, cfg.ListenComfy)
|
||||
}
|
||||
if cfg.UnloadTimeout != time.Minute || cfg.JobTimeout != 15*time.Minute {
|
||||
t.Fatalf("timeouts = %v %v", cfg.UnloadTimeout, cfg.JobTimeout)
|
||||
}
|
||||
if !cfg.AutoUpdate || cfg.UpdateInterval != 6*time.Hour {
|
||||
t.Fatalf("update = %v %v", cfg.AutoUpdate, cfg.UpdateInterval)
|
||||
}
|
||||
if cfg.LogLevel != slog.LevelWarn {
|
||||
t.Fatalf("log level = %v", cfg.LogLevel)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseEnvFile(t *testing.T) {
|
||||
input := `# comment
|
||||
OLLAMA_URL=http://host:11435
|
||||
|
||||
LOGLEVEL=debug
|
||||
SPACED = value with spaces
|
||||
`
|
||||
values, err := ParseEnvFile(strings.NewReader(input))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if values["OLLAMA_URL"] != "http://host:11435" {
|
||||
t.Fatalf("OLLAMA_URL = %q", values["OLLAMA_URL"])
|
||||
}
|
||||
if values["LOGLEVEL"] != "debug" {
|
||||
t.Fatalf("LOGLEVEL = %q", values["LOGLEVEL"])
|
||||
}
|
||||
if values["SPACED"] != "value with spaces" {
|
||||
t.Fatalf("SPACED = %q", values["SPACED"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseEnvFileMalformed(t *testing.T) {
|
||||
_, err := ParseEnvFile(strings.NewReader("OK=1\nNOT_A_PAIR\n"))
|
||||
if err == nil || !strings.Contains(err.Error(), "line 2") {
|
||||
t.Fatalf("err = %v, want line 2 error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvOverridesFile(t *testing.T) {
|
||||
file := map[string]string{"OLLAMA_URL": "http://file:1", "UNLOAD_TIMEOUT": "42s"}
|
||||
env := map[string]string{"OLLAMA_URL": "http://env:2"}
|
||||
getenv := func(k string) string {
|
||||
if v := env[k]; v != "" {
|
||||
return v
|
||||
}
|
||||
return file[k]
|
||||
}
|
||||
cfg, err := Load(getenv)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.OllamaURL != "http://env:2" {
|
||||
t.Fatalf("OllamaURL = %q, want env value", cfg.OllamaURL)
|
||||
}
|
||||
if cfg.UnloadTimeout != 42*time.Second {
|
||||
t.Fatalf("UnloadTimeout = %v, want file value", cfg.UnloadTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadErrors(t *testing.T) {
|
||||
for _, tc := range []struct{ key, value string }{
|
||||
{"UNLOAD_TIMEOUT", "bogus"},
|
||||
{"PROMPT_CAPTURE_LIMIT", "-5"},
|
||||
{"AUTO_UPDATE", "maybe"},
|
||||
{"LOGLEVEL", "shouty"},
|
||||
{"LOG_FORMAT", "yaml"},
|
||||
} {
|
||||
_, err := Load(func(k string) string {
|
||||
if k == tc.key {
|
||||
return tc.value
|
||||
}
|
||||
return ""
|
||||
})
|
||||
if err == nil {
|
||||
t.Errorf("%s=%s: expected error", tc.key, tc.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user