Files
PilotVault/API Server/cmd/server/main.go
T
tajniak81andClaude Opus 5.5 5be676fc97 Docker: S3 and SeaweedFS stacks, matching DriverVault
Docker/ gets the same deployment shapes as DriverVault: plain, SeaweedFS
in the stack, SeaweedFS split into its roles, and an external S3 endpoint,
each as a build-from-source and a registry compose file with an .env
example of the same name, plus a README.

The API Server now reads PB_S3_* on boot and points PocketBase's file
storage at the bucket (only when the settings differ), then asks
PocketBase to test it. It never turns S3 off. Plugin state gets an
api_data volume, since the image could not write plugins.json.

The PocketBase image pinned v0.22.21, which cannot run the v0.23+
migrations or `superuser upsert`; it now pins v0.39.11. Starting from an
empty database also exposed two migration bugs: the seed tried to create
a passwordless account, and the documents collection saved its
self-relation with a blank target. Both are fixed; databases that already
ran them are unaffected.

Verified on Docker: the SeaweedFS and split stacks come up healthy from
an empty database, uploads land in the bucket, and a restart is a no-op.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 17:50:20 +01:00

68 lines
1.8 KiB
Go

// Command server runs the PilotVault API Server. It is the single entry point
// the Fly App (drone/telemetry uplink) and the Web App / API Web Panel talk to.
// It keeps live device state in memory, fans telemetry out to dashboards over a
// websocket, and proxies authentication to a PocketBase kept behind it.
package main
import (
"context"
"errors"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"pilotvault/apiserver/internal/api"
"pilotvault/apiserver/internal/config"
"pilotvault/apiserver/internal/hub"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lmsgprefix)
log.SetPrefix("[api] ")
cfg := config.Load()
h := hub.New()
srv := api.New(cfg, h)
if err := srv.StartPlugins(); err != nil {
log.Printf("plugins: load failed: %v", err)
}
// Point PocketBase's file storage at S3 when PB_S3_* asks for it (the
// SeaweedFS / S3 compose files). Background and non-fatal.
srv.StartFileStorage()
httpServer := &http.Server{
Addr: cfg.Addr,
Handler: srv.Handler(),
ReadHeaderTimeout: 10 * time.Second,
// No WriteTimeout: /ws/* are long-lived streaming connections.
IdleTimeout: 60 * time.Second,
}
go func() {
log.Printf("listening on %s (PocketBase: %s, panel at /)", cfg.Addr, cfg.PocketBaseURL)
if err := httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("server error: %v", err)
}
}()
// Graceful shutdown.
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
<-stop
log.Println("shutting down...")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
srv.Stop(ctx)
if err := httpServer.Shutdown(ctx); err != nil {
log.Printf("shutdown error: %v", err)
}
log.Println("stopped")
}