diff --git a/.dockerignore b/.dockerignore index b97e508..de755e0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,6 +6,8 @@ Adobe Plugin/ Design/ Fly App/ +Fly 2 App/ +Fly Agent App/ Phone App/ # Frontend deps + generated bundles — rebuilt inside the images. diff --git a/API Server/Dockerfile b/API Server/Dockerfile index 34491bd..65c309f 100644 --- a/API Server/Dockerfile +++ b/API Server/Dockerfile @@ -24,10 +24,18 @@ RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" \ # ---- Stage 3: minimal runtime ---- FROM alpine:latest RUN apk add --no-cache ca-certificates tzdata \ - && adduser -D -u 10001 app + && adduser -D -u 10001 app \ + && mkdir -p /app/data && chown app:app /app/data WORKDIR /app COPY --from=build /out/api-server ./api-server USER app +# Plugin enable-state + config is the one thing the API Server keeps on disk. +# /app/data is owned by the runtime user, so a named volume mounted there +# inherits that ownership and stays writable. +ENV PLUGINS_FILE=/app/data/plugins.json +VOLUME ["/app/data"] +HEALTHCHECK --interval=10s --timeout=3s --start-period=20s --retries=12 \ + CMD wget -qO- http://127.0.0.1:8080/healthz || exit 1 # Default listen address (override with API_ADDR). PocketBase URL, CORS origins, # and the optional POCKETBASE_ADMIN_* service account come from env at runtime. ENV API_ADDR=:8080 diff --git a/API Server/cmd/server/main.go b/API Server/cmd/server/main.go index 6b8e0a1..aa2c351 100644 --- a/API Server/cmd/server/main.go +++ b/API Server/cmd/server/main.go @@ -32,6 +32,10 @@ func main() { 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(), diff --git a/API Server/internal/api/storage.go b/API Server/internal/api/storage.go new file mode 100644 index 0000000..e7f878b --- /dev/null +++ b/API Server/internal/api/storage.go @@ -0,0 +1,150 @@ +package api + +import ( + "context" + "encoding/json" + "fmt" + "log" + "net/http" + "time" + + "pilotvault/apiserver/internal/config" +) + +// PocketBase file storage. Document blobs live in PocketBase's file storage, and +// by default that is the pb_data volume next to the SQLite database. When the +// PB_S3_* variables describe a bucket (the SeaweedFS and S3 compose files set +// them), the API Server points PocketBase's "Files storage" at that bucket on +// every boot. Clients never notice: a document is always downloaded through +// GET /api/documents/{id}/file, which streams from PocketBase whichever backend +// it uses. + +// storageSettings is the slice of PocketBase's settings this step owns. The json +// names are PocketBase's own (core.S3Config), so the PATCH body is this type +// marshalled back out. +type storageSettings struct { + Enabled bool `json:"enabled"` + Bucket string `json:"bucket"` + Region string `json:"region"` + Endpoint string `json:"endpoint"` + AccessKey string `json:"accessKey"` + Secret string `json:"secret,omitempty"` + ForcePathStyle bool `json:"forcePathStyle"` +} + +// sameExceptSecret compares everything a read of the settings can be trusted +// on. PocketBase masks the stored secret, so a rotation of the secret alone is +// invisible from here — changing any other PB_S3_* value forces the write, and +// so does editing it in the PocketBase admin UI. +func (s storageSettings) sameExceptSecret(other storageSettings) bool { + s.Secret, other.Secret = "", "" + return s == other +} + +func wantedStorage(cfg config.Config) storageSettings { + return storageSettings{ + Enabled: true, + Bucket: cfg.S3Bucket, + Region: cfg.S3Region, + Endpoint: cfg.S3Endpoint, + AccessKey: cfg.S3AccessKey, + Secret: cfg.S3Secret, + ForcePathStyle: cfg.S3ForcePathStyle, + } +} + +// StartFileStorage applies the configured S3 file storage in the background. +// It does nothing when no bucket was asked for. A PocketBase that is still +// starting is retried for a while; the server itself never waits on this, so a +// bad endpoint cannot keep the panel (where the connection is fixed) down. +func (s *Server) StartFileStorage() { + s.mu.RLock() + cfg := s.cfg + s.mu.RUnlock() + + if !cfg.StorageConfigured() { + if cfg.S3Enabled { + log.Println("storage: WARNING: PB_S3_ENABLED is set but the bucket, endpoint or credentials are incomplete — file storage stays on the local volume") + } + return + } + if !s.admin.configured() { + log.Println("storage: WARNING: PB_S3_* is set but POCKETBASE_ADMIN_EMAIL/PASSWORD are not — cannot point PocketBase at the bucket") + return + } + + want := wantedStorage(cfg) + go func() { + const attempts = 10 + for i := 1; ; i++ { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + err := s.ensureFileStorage(ctx, want) + cancel() + if err == nil { + return + } + if i == attempts { + log.Printf("storage: WARNING: could not apply S3 file storage after %d attempts: %v", attempts, err) + return + } + time.Sleep(3 * time.Second) + } + }() +} + +// ensureFileStorage points PocketBase's record-file storage at the bucket. +// +// It never turns S3 *off*: files already written to a bucket are reachable only +// while PocketBase still points at it, so running the plain compose file again +// leaves the setting where it is rather than stranding every existing document. +// Moving back to local storage is a deliberate act in PocketBase's admin UI. +func (s *Server) ensureFileStorage(ctx context.Context, want storageSettings) error { + raw, status, err := s.admin.do(ctx, http.MethodGet, "/api/settings", nil) + if err != nil { + return err + } + if status < 200 || status >= 300 { + return fmt.Errorf("read settings: status %d: %s", status, raw) + } + var current struct { + S3 storageSettings `json:"s3"` + } + if err := json.Unmarshal(raw, ¤t); err != nil { + return err + } + + if current.S3.sameExceptSecret(want) { + log.Printf("storage: • file storage already on S3 (%s)", want.Bucket) + } else { + // Only the s3 block is sent: everything else in the settings — mail, + // backups, rate limits — belongs to whoever set it. + raw, status, err = s.admin.do(ctx, http.MethodPatch, "/api/settings", + map[string]any{"s3": want}) + if err != nil { + return err + } + if status < 200 || status >= 300 { + return fmt.Errorf("apply settings: status %d: %s", status, raw) + } + log.Printf("storage: ✓ file storage → S3 (%s at %s)", want.Bucket, want.Endpoint) + } + + s.testFileStorage(ctx) + return nil +} + +// testFileStorage asks PocketBase to prove it can reach the bucket, and only +// says so in the log: uploads will fail if it cannot, but the server still has +// to come up. +func (s *Server) testFileStorage(ctx context.Context) { + raw, status, err := s.admin.do(ctx, http.MethodPost, "/api/settings/test/s3", + map[string]any{"filesystem": "storage"}) + switch { + case err != nil: + log.Printf("storage: WARNING: S3 storage test failed: %v", err) + case status < 200 || status >= 300: + log.Printf("storage: WARNING: S3 storage unreachable (status %d): %s", status, raw) + default: + log.Printf("storage: ✓ S3 storage reachable") + } +} diff --git a/API Server/internal/api/storage_test.go b/API Server/internal/api/storage_test.go new file mode 100644 index 0000000..5637409 --- /dev/null +++ b/API Server/internal/api/storage_test.go @@ -0,0 +1,49 @@ +package api + +import ( + "testing" + + "pilotvault/apiserver/internal/config" +) + +func TestStorageSameExceptSecret(t *testing.T) { + a := storageSettings{Enabled: true, Bucket: "pilotvault", Region: "us-east-1", + Endpoint: "http://seaweedfs:8333", AccessKey: "k", Secret: "s1", ForcePathStyle: true} + + // PocketBase masks the secret on read, so a differing secret alone matches. + b := a + b.Secret = "******" + if !a.sameExceptSecret(b) { + t.Fatal("secret-only difference should compare equal") + } + + b = a + b.Endpoint = "http://seaweedfs-s3:8333" + if a.sameExceptSecret(b) { + t.Fatal("endpoint change should force a write") + } + + if a.sameExceptSecret(storageSettings{}) { + t.Fatal("a fresh PocketBase (S3 off) should force a write") + } +} + +func TestStorageConfigured(t *testing.T) { + full := config.Config{S3Enabled: true, S3Bucket: "b", S3Endpoint: "http://e", + S3AccessKey: "k", S3Secret: "s"} + if !full.StorageConfigured() { + t.Fatal("fully described bucket should be configured") + } + for name, mut := range map[string]func(*config.Config){ + "disabled": func(c *config.Config) { c.S3Enabled = false }, + "no endpoint": func(c *config.Config) { c.S3Endpoint = "" }, + "no key": func(c *config.Config) { c.S3AccessKey = "" }, + "no secret": func(c *config.Config) { c.S3Secret = "" }, + } { + c := full + mut(&c) + if c.StorageConfigured() { + t.Errorf("%s: should not be configured", name) + } + } +} diff --git a/API Server/internal/config/config.go b/API Server/internal/config/config.go index 28df5be..62a33ae 100644 --- a/API Server/internal/config/config.go +++ b/API Server/internal/config/config.go @@ -20,6 +20,33 @@ type Config struct { // 503 and the rest of the server is unaffected. PocketBaseAdminEmail string PocketBaseAdminPassword string + + // PocketBase file storage. With S3Enabled set and the bucket fully + // described, the server points PocketBase's "Files storage" at this bucket + // on boot instead of the pb_data volume; left unset, uploads stay on disk + // exactly as they always have. Only record files (document blobs) move — + // PocketBase's own backups are deliberately not touched. + // + // S3Endpoint has no default: an in-stack SeaweedFS and one outside it are + // different addresses, and guessing either would be worse than not trying. + S3Enabled bool + S3Bucket string + S3Region string + S3Endpoint string + S3AccessKey string + S3Secret string + // S3ForcePathStyle keeps bucket names in the path rather than the hostname. + // True by default because that is what a self-hosted gateway serves — + // virtual-host style would need a DNS entry per bucket. + S3ForcePathStyle bool +} + +// StorageConfigured reports whether S3 file storage has been fully specified. +// Anything less counts as "not asked for": a half-filled .env leaves uploads on +// the local volume rather than pointing PocketBase at a bucket it cannot reach. +func (c Config) StorageConfigured() bool { + return c.S3Enabled && c.S3Bucket != "" && c.S3Endpoint != "" && + c.S3AccessKey != "" && c.S3Secret != "" } // EnvFile is the .env path (relative to the working directory) that Load reads @@ -39,6 +66,13 @@ func Load() Config { PluginsFile: getenv("PLUGINS_FILE", "plugins.json"), PocketBaseAdminEmail: getenv("POCKETBASE_ADMIN_EMAIL", os.Getenv("PB_ADMIN_EMAIL")), PocketBaseAdminPassword: getenv("POCKETBASE_ADMIN_PASSWORD", os.Getenv("PB_ADMIN_PASSWORD")), + S3Enabled: boolEnv("PB_S3_ENABLED", false), + S3Bucket: getenv("PB_S3_BUCKET", "pilotvault"), + S3Region: getenv("PB_S3_REGION", "us-east-1"), + S3Endpoint: strings.TrimRight(getenv("PB_S3_ENDPOINT", ""), "/"), + S3AccessKey: getenv("PB_S3_ACCESS_KEY", ""), + S3Secret: getenv("PB_S3_SECRET", ""), + S3ForcePathStyle: boolEnv("PB_S3_FORCE_PATH_STYLE", true), } return cfg } @@ -104,6 +138,18 @@ func getenv(key, def string) string { return def } +// boolEnv reads a boolean variable, accepting the usual spellings; anything +// unrecognised (or unset) falls back to def. +func boolEnv(key string, def bool) bool { + switch strings.ToLower(strings.TrimSpace(os.Getenv(key))) { + case "1", "true", "yes", "on": + return true + case "0", "false", "no", "off": + return false + } + return def +} + func splitCSV(s string) []string { parts := strings.Split(s, ",") out := make([]string, 0, len(parts)) diff --git a/API Server/pocketbase/pb_migrations/1720300500_seed_orgs_and_users.js b/API Server/pocketbase/pb_migrations/1720300500_seed_orgs_and_users.js index a94249d..a802ca7 100644 --- a/API Server/pocketbase/pb_migrations/1720300500_seed_orgs_and_users.js +++ b/API Server/pocketbase/pb_migrations/1720300500_seed_orgs_and_users.js @@ -49,9 +49,14 @@ migrate( if (dirty) app.save(u) return } + // An account with no seed password is one expected to pre-exist (it is + // only reconciled above). On a fresh database there is nothing to + // reconcile, and PocketBase refuses an auth record without a password — + // which would abort the whole migration — so skip it. + if (!password) return u = new Record(uc) u.set('email', email) - if (password) u.setPassword(password) + u.setPassword(password) u.set('role', role) u.set('verified', true) u.set('emailVisibility', false) diff --git a/API Server/pocketbase/pb_migrations/1720300800_add_documents.js b/API Server/pocketbase/pb_migrations/1720300800_add_documents.js index 9ea7ea7..5072ecd 100644 --- a/API Server/pocketbase/pb_migrations/1720300800_add_documents.js +++ b/API Server/pocketbase/pb_migrations/1720300800_add_documents.js @@ -106,16 +106,8 @@ migrate( { name: 'notes', type: 'text', max: 2000 }, // -- versioning (replaces_id chain) + audit -- - { - name: 'replaces', - type: 'relation', - required: false, - collectionId: '', // self-reference; patched to documents.id after save - cascadeDelete: false, - minSelect: 0, - maxSelect: 1, - presentable: false, - }, + // `replaces` (self-relation, the version chain) is added after the + // first save below — its target id does not exist until then. { name: 'version', type: 'number', min: 1 }, { name: 'uploaded_by', @@ -152,12 +144,23 @@ migrate( }) app.save(documents) - // Point the self-referential `replaces` relation at the now-created - // collection (its id wasn't known before the first save). + // Add the self-referential `replaces` relation now that the collection has + // an id. PocketBase rejects a relation with a blank collectionId, so it + // cannot be part of the first save. const saved = app.findCollectionByNameOrId('documents') - const replaces = saved.fields.find((f) => f.name === 'replaces') - if (replaces) { - replaces.collectionId = saved.id + if (!saved.fields.getByName('replaces')) { + saved.fields.add( + new Field({ + name: 'replaces', + type: 'relation', + required: false, + collectionId: saved.id, + cascadeDelete: false, + minSelect: 0, + maxSelect: 1, + presentable: false, + }), + ) app.save(saved) } }, diff --git a/Docker/.env.example b/Docker/.env.example index a43297f..5986fac 100644 --- a/Docker/.env.example +++ b/Docker/.env.example @@ -1,4 +1,4 @@ -# Copy to .env and fill in. Used by the combined docker-compose.yml (build & run). +# Copy to .env and fill in. Used by docker-compose.yml. # --- PocketBase superuser (also used by the API Server to authenticate) ------ # Created/updated on the PocketBase container's first boot. REQUIRED. @@ -18,7 +18,26 @@ PB_PORT=8070 API_PORT=8080 WEB_PORT=8090 +# --- Settings the API Server panel can also change --------------------------- +# The panel's Settings screens apply these immediately, but only for the life of +# the container — the values below are re-applied on every restart and win. Set +# them here to make a change permanent. +# POCKETBASE_URL where the API Server looks for the database. Defaults to +# the bundled pocketbase service; set it to reach one +# outside this stack. +# WEBAPP_URL the Web App address the panel status page probes. It is +# a container-to-container call, so it must be reachable +# from the API Server, not from your browser. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# POCKETBASE_URL=http://pocketbase:8070 +# WEBAPP_URL=http://web-app:8090 + # --- Storage ---------------------------------------------------------------- -# Docker-managed named volume by default; set PB_DATA to an absolute host path -# for a bind mount, e.g. PB_DATA=/srv/pilotvault/pb_data +# Docker-managed named volumes by default. To store one on a host path instead, +# set an absolute path, e.g. PB_DATA=/srv/pilotvault/pb_data. +# PB_DATA — the PocketBase database and its backups, plus the uploaded +# document blobs. PB_DATA=pb_data +# API_DATA — the API Server's plugins.json (plugin enable-state + config). A +# host path must be writable by uid 10001, the image's runtime user. +API_DATA=api_data diff --git a/Docker/.env.prod.example b/Docker/.env.prod.example index 75315b0..2001af8 100644 --- a/Docker/.env.prod.example +++ b/Docker/.env.prod.example @@ -22,7 +22,7 @@ POCKETBASE_ADMIN_PASSWORD=change-me-long-password # Allowed CORS origin(s) for the web app (match your public URL / WEB_PORT). CORS_ALLOW_ORIGINS=http://localhost:8090 -# --- Ports ------------------------------------------------------------------ +# --- Ports ------------------------------------------------------------------- # WEB_PORT is the public front door (bound on all interfaces). WEB_PORT=8090 # PocketBase admin UI and the API panel are bound to localhost only by default. @@ -32,7 +32,26 @@ PB_BIND=127.0.0.1 API_PORT=8080 API_BIND=127.0.0.1 +# --- Settings the API Server panel can also change --------------------------- +# The panel's Settings screens apply these immediately, but only for the life of +# the container — the values below are re-applied on every restart and win. Set +# them here to make a change permanent. +# POCKETBASE_URL where the API Server looks for the database. Defaults to +# the bundled pocketbase service; set it to reach one +# outside this stack. +# WEBAPP_URL the Web App address the panel status page probes. It is +# a container-to-container call, so it must be reachable +# from the API Server, not from your browser. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# POCKETBASE_URL=http://pocketbase:8070 +# WEBAPP_URL=http://web-app:8090 + # --- Storage ---------------------------------------------------------------- -# Default is a Docker-managed named volume ("pb_data"). Set PB_DATA to an -# absolute host path for a bind mount, e.g. PB_DATA=/srv/pilotvault/pb_data +# Docker-managed named volumes by default. To store one on a host path instead, +# set an absolute path, e.g. PB_DATA=/srv/pilotvault/pb_data. +# PB_DATA — the PocketBase database and its backups, plus the uploaded +# document blobs. PB_DATA=pb_data +# API_DATA — the API Server's plugins.json (plugin enable-state + config). A +# host path must be writable by uid 10001, the image's runtime user. +API_DATA=api_data diff --git a/Docker/.env.prod.s3.example b/Docker/.env.prod.s3.example new file mode 100644 index 0000000..29d03bb --- /dev/null +++ b/Docker/.env.prod.s3.example @@ -0,0 +1,80 @@ +# PilotVault — production stack config. +# Copy to .env and fill in, then: +# docker compose -f docker-compose.prod.s3.yml pull +# docker compose -f docker-compose.prod.s3.yml up -d + +# --- Registry images -------------------------------------------------------- +# Defaults point at the internal registry; override to pin a tag or use a mirror. +PB_IMAGE=10.2.1.10:5500/admin/pilotvault-pocketbase:latest +API_IMAGE=10.2.1.10:5500/admin/pilotvault-api-server:latest +WEB_IMAGE=10.2.1.10:5500/admin/pilotvault-web-app:latest + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on the PocketBase container's first boot. The API Server uses +# these same credentials to manage the database. +POCKETBASE_ADMIN_EMAIL=admin@dji.local +POCKETBASE_ADMIN_PASSWORD=change-me-long-password + +# The app super-admin login (superadmin@pilotvault.local) is created by the +# bundled PocketBase migrations on first boot — distinct from the superuser above. + +# --- API Server ------------------------------------------------------------- +# Allowed CORS origin(s) for the web app (match your public URL / WEB_PORT). +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Ports ------------------------------------------------------------------- +# WEB_PORT is the public front door (bound on all interfaces). +WEB_PORT=8090 +# PocketBase admin UI and the API panel are bound to localhost only by default. +# Set PB_BIND / API_BIND to 0.0.0.0 to expose them on the network. +PB_PORT=8070 +PB_BIND=127.0.0.1 +API_PORT=8080 +API_BIND=127.0.0.1 + +# --- Settings the API Server panel can also change --------------------------- +# The panel's Settings screens apply these immediately, but only for the life of +# the container — the values below are re-applied on every restart and win. Set +# them here to make a change permanent. +# POCKETBASE_URL where the API Server looks for the database. Defaults to +# the bundled pocketbase service; set it to reach one +# outside this stack. +# WEBAPP_URL the Web App address the panel status page probes. It is +# a container-to-container call, so it must be reachable +# from the API Server, not from your browser. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# POCKETBASE_URL=http://pocketbase:8070 +# WEBAPP_URL=http://web-app:8090 + +# --- Storage ---------------------------------------------------------------- +# Docker-managed named volumes by default. To store one on a host path instead, +# set an absolute path, e.g. PB_DATA=/srv/pilotvault/pb_data. +# PB_DATA — the PocketBase database and its backups. +# The documents themselves live in the bucket below. +PB_DATA=pb_data +# API_DATA — the API Server's plugins.json (plugin enable-state + config). A +# host path must be writable by uid 10001, the image's runtime user. +API_DATA=api_data + +# --- File storage: external S3 ----------------------------------------------- +# PocketBase keeps its record files — the document store's scans of pilot +# certificates, aircraft registrations, insurance and authorisations — in the +# bucket below instead of on PB_DATA. The database and PocketBase's own backups +# stay where they are. +# +# Nothing in this stack runs a gateway: both the endpoint and the bucket must +# already exist. For a gateway on this Docker host use +# http://host.docker.internal:8333 — the compose file adds the host entry that +# makes that name resolve inside the containers. +PB_S3_ENDPOINT=http://10.2.1.10:8333 +PB_S3_BUCKET=pilotvault +PB_S3_ACCESS_KEY= +PB_S3_SECRET= +# SeaweedFS and MinIO ignore the region; PocketBase insists on having one. +PB_S3_REGION=us-east-1 +# true for SeaweedFS and MinIO, false for AWS S3 proper. +PB_S3_FORCE_PATH_STYLE=true + +# Existing uploads are NOT migrated when this is switched on: PocketBase copies +# nothing, so documents uploaded before the switch stop resolving. Read the file +# storage section of README.md first. diff --git a/Docker/.env.prod.seaweedfs.example b/Docker/.env.prod.seaweedfs.example new file mode 100644 index 0000000..954742b --- /dev/null +++ b/Docker/.env.prod.seaweedfs.example @@ -0,0 +1,89 @@ +# PilotVault — production stack config. +# Copy to .env and fill in, then: +# docker compose -f docker-compose.prod.seaweedfs.yml pull +# docker compose -f docker-compose.prod.seaweedfs.yml up -d + +# --- Registry images -------------------------------------------------------- +# Defaults point at the internal registry; override to pin a tag or use a mirror. +PB_IMAGE=10.2.1.10:5500/admin/pilotvault-pocketbase:latest +API_IMAGE=10.2.1.10:5500/admin/pilotvault-api-server:latest +WEB_IMAGE=10.2.1.10:5500/admin/pilotvault-web-app:latest + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on the PocketBase container's first boot. The API Server uses +# these same credentials to manage the database. +POCKETBASE_ADMIN_EMAIL=admin@dji.local +POCKETBASE_ADMIN_PASSWORD=change-me-long-password + +# The app super-admin login (superadmin@pilotvault.local) is created by the +# bundled PocketBase migrations on first boot — distinct from the superuser above. + +# --- API Server ------------------------------------------------------------- +# Allowed CORS origin(s) for the web app (match your public URL / WEB_PORT). +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Ports ------------------------------------------------------------------- +# WEB_PORT is the public front door (bound on all interfaces). +WEB_PORT=8090 +# PocketBase admin UI and the API panel are bound to localhost only by default. +# Set PB_BIND / API_BIND to 0.0.0.0 to expose them on the network. +PB_PORT=8070 +PB_BIND=127.0.0.1 +API_PORT=8080 +API_BIND=127.0.0.1 + +# --- Settings the API Server panel can also change --------------------------- +# The panel's Settings screens apply these immediately, but only for the life of +# the container — the values below are re-applied on every restart and win. Set +# them here to make a change permanent. +# POCKETBASE_URL where the API Server looks for the database. Defaults to +# the bundled pocketbase service; set it to reach one +# outside this stack. +# WEBAPP_URL the Web App address the panel status page probes. It is +# a container-to-container call, so it must be reachable +# from the API Server, not from your browser. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# POCKETBASE_URL=http://pocketbase:8070 +# WEBAPP_URL=http://web-app:8090 + +# --- Storage ---------------------------------------------------------------- +# Docker-managed named volumes by default. To store one on a host path instead, +# set an absolute path, e.g. PB_DATA=/srv/pilotvault/pb_data. +# PB_DATA — the PocketBase database and its backups. +# The documents themselves live in the bucket below. +# Back it up together with SEAWEED_DATA below. +PB_DATA=pb_data +# API_DATA — the API Server's plugins.json (plugin enable-state + config). A +# host path must be writable by uid 10001, the image's runtime user. +API_DATA=api_data + +# --- File storage: SeaweedFS ------------------------------------------------- +# PocketBase keeps its record files — the document store's scans of pilot +# certificates, aircraft registrations, insurance and authorisations — in the +# bucket below instead of on PB_DATA. The database and PocketBase's own backups +# stay where they are. +# +# The credentials do double duty: they configure the SeaweedFS gateway's single +# identity *and* are what PocketBase authenticates with. There are no safe +# defaults, and the stack refuses to start without them. +PB_S3_ACCESS_KEY= +PB_S3_SECRET= +# The bucket. Created on first boot by the seaweedfs-init container. +PB_S3_BUCKET=pilotvault +# SeaweedFS ignores the region; PocketBase insists on having one. +PB_S3_REGION=us-east-1 + +# SEAWEED_DATA — where SeaweedFS keeps the files. A Docker-managed named volume +# by default; set an absolute host path for a bind mount, the same way PB_DATA +# works above. Back it up alongside PB_DATA: from here on the documents live +# here, not in the database volume. +SEAWEED_DATA=seaweed_data +# The gateway image, pinned so a redeploy months from now brings up the same +# one. +# SEAWEED_IMAGE=chrislusf/seaweedfs:4.45 +# The S3 gateway publishes no host port: the stack reaches it over the compose +# network. + +# Existing uploads are NOT migrated when this is switched on: PocketBase copies +# nothing, so documents uploaded before the switch stop resolving. Read the file +# storage section of README.md first. diff --git a/Docker/.env.prod.seaweedfs.split.example b/Docker/.env.prod.seaweedfs.split.example new file mode 100644 index 0000000..5f9e945 --- /dev/null +++ b/Docker/.env.prod.seaweedfs.split.example @@ -0,0 +1,120 @@ +# PilotVault — production stack config. +# Copy to .env and fill in, then: +# docker compose -f docker-compose.prod.seaweedfs.split.yml pull +# docker compose -f docker-compose.prod.seaweedfs.split.yml up -d + +# --- Registry images -------------------------------------------------------- +# Defaults point at the internal registry; override to pin a tag or use a mirror. +PB_IMAGE=10.2.1.10:5500/admin/pilotvault-pocketbase:latest +API_IMAGE=10.2.1.10:5500/admin/pilotvault-api-server:latest +WEB_IMAGE=10.2.1.10:5500/admin/pilotvault-web-app:latest + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on the PocketBase container's first boot. The API Server uses +# these same credentials to manage the database. +POCKETBASE_ADMIN_EMAIL=admin@dji.local +POCKETBASE_ADMIN_PASSWORD=change-me-long-password + +# The app super-admin login (superadmin@pilotvault.local) is created by the +# bundled PocketBase migrations on first boot — distinct from the superuser above. + +# --- API Server ------------------------------------------------------------- +# Allowed CORS origin(s) for the web app (match your public URL / WEB_PORT). +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Ports ------------------------------------------------------------------- +# WEB_PORT is the public front door (bound on all interfaces). +WEB_PORT=8090 +# PocketBase admin UI and the API panel are bound to localhost only by default. +# Set PB_BIND / API_BIND to 0.0.0.0 to expose them on the network — which is +# what a stack running on a remote host needs, behind a reverse proxy. +PB_PORT=8070 +PB_BIND=127.0.0.1 +API_PORT=8080 +API_BIND=127.0.0.1 + +# --- Settings the API Server panel can also change --------------------------- +# The panel's Settings screens apply these immediately, but only for the life of +# the container — the values below are re-applied on every restart and win. Set +# them here to make a change permanent. +# POCKETBASE_URL where the API Server looks for the database. Defaults to +# the bundled pocketbase service; set it to reach one +# outside this stack. +# WEBAPP_URL the Web App address the panel status page probes. It is +# a container-to-container call, so it must be reachable +# from the API Server, not from your browser. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# POCKETBASE_URL=http://pocketbase:8070 +# WEBAPP_URL=http://web-app:8090 + +# --- Storage ---------------------------------------------------------------- +# Docker-managed named volumes by default. To store one on a host path instead, +# set an absolute path, e.g. PB_DATA=/srv/pilotvault/pb_data. +# PB_DATA — the PocketBase database and its backups. +# The documents themselves live in the bucket below. +# Back it up together with SEAWEED_DATA below. +PB_DATA=pb_data +# API_DATA — the API Server's plugins.json (plugin enable-state + config). A +# host path must be writable by uid 10001, the image's runtime user. +API_DATA=api_data + +# --- File storage: SeaweedFS ------------------------------------------------- +# PocketBase keeps its record files — the document store's scans of pilot +# certificates, aircraft registrations, insurance and authorisations — in the +# bucket below instead of on PB_DATA. The database and PocketBase's own backups +# stay where they are. +# +# The credentials do double duty: seaweedfs-init writes them into the filer's +# IAM store as the identity named "pilotvault" *and* they are what PocketBase +# authenticates with. There are no safe defaults, and the stack refuses to start +# without them. Change them here and restart to rotate: the seed updates the +# identity in place rather than adding a second one. +PB_S3_ACCESS_KEY= +PB_S3_SECRET= +# The bucket. Created on first boot by the seaweedfs-init container. +PB_S3_BUCKET=pilotvault +# SeaweedFS ignores the region; PocketBase insists on having one. +PB_S3_REGION=us-east-1 + +# SEAWEED_DATA — where SeaweedFS keeps the files. A Docker-managed named volume +# by default; set an absolute host path for a bind mount, the same way PB_DATA +# works above. Back it up alongside PB_DATA: from here on the documents live +# here, not in the database volume. +# +# The master, volume and filer containers all mount it at /data, which is the +# layout `weed server -dir=/data` writes — so this file and +# docker-compose.prod.seaweedfs.yml are interchangeable on the same volume, with +# nothing to migrate either way. +SEAWEED_DATA=seaweed_data +# The SeaweedFS image, pinned so a redeploy months from now brings up the same +# one. All five SeaweedFS containers run it. +# SEAWEED_IMAGE=chrislusf/seaweedfs:4.45 +# The S3 gateway, master, volume and filer publish no host port at all. The +# admin UI below shows what they would: the volume server in particular serves +# file content by id with no authentication, so it stays on the compose network. +# Reach the others with `docker compose exec`. + +# --- SeaweedFS admin UI ------------------------------------------------------ +# Cluster topology, volumes, buckets, maintenance tasks, and Object Store → +# Users, where further S3 identities are created and revoked. They land in the +# filer's IAM store, the same one seeded above, and the gateway picks them up +# without a restart. +# +# REQUIRED: weed disables authentication entirely when the password is empty, +# and this panel can mint credentials for the bucket. +SEAWEED_ADMIN_USER=admin +SEAWEED_ADMIN_PASSWORD= +# Optional view-only login. +SEAWEED_ADMIN_READONLY_USER= +SEAWEED_ADMIN_READONLY_PASSWORD= +# Bound to localhost by default, like PB_BIND and API_BIND. On a remote host +# that means unreachable — set 0.0.0.0 and put it behind the same reverse proxy +# as the other panels. +SEAWEED_ADMIN_BIND=127.0.0.1 +SEAWEED_ADMIN_PORT=23646 +# Its own small volume: session key and maintenance-task state, no object data. +SEAWEED_ADMIN_DATA=seaweed_admin + +# Existing uploads are NOT migrated when this is switched on: PocketBase copies +# nothing, so documents uploaded before the switch stop resolving. Read the file +# storage section of README.md first. diff --git a/Docker/.env.s3.example b/Docker/.env.s3.example new file mode 100644 index 0000000..6a421ad --- /dev/null +++ b/Docker/.env.s3.example @@ -0,0 +1,66 @@ +# Copy to .env and fill in. Used by docker-compose.s3.yml. + +# --- PocketBase superuser (also used by the API Server to authenticate) ------ +# Created/updated on the PocketBase container's first boot. REQUIRED. +POCKETBASE_ADMIN_EMAIL=admin@dji.local +POCKETBASE_ADMIN_PASSWORD=change-me-long-password + +# The app super-admin login (superadmin@pilotvault.local) is created by the +# bundled PocketBase migrations on first boot — no separate env var needed. + +# --- API Server ------------------------------------------------------------- +# Allowed CORS origin(s) for the web app (match WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +PB_PORT=8070 +API_PORT=8080 +WEB_PORT=8090 + +# --- Settings the API Server panel can also change --------------------------- +# The panel's Settings screens apply these immediately, but only for the life of +# the container — the values below are re-applied on every restart and win. Set +# them here to make a change permanent. +# POCKETBASE_URL where the API Server looks for the database. Defaults to +# the bundled pocketbase service; set it to reach one +# outside this stack. +# WEBAPP_URL the Web App address the panel status page probes. It is +# a container-to-container call, so it must be reachable +# from the API Server, not from your browser. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# POCKETBASE_URL=http://pocketbase:8070 +# WEBAPP_URL=http://web-app:8090 + +# --- Storage ---------------------------------------------------------------- +# Docker-managed named volumes by default. To store one on a host path instead, +# set an absolute path, e.g. PB_DATA=/srv/pilotvault/pb_data. +# PB_DATA — the PocketBase database and its backups. +# The documents themselves live in the bucket below. +PB_DATA=pb_data +# API_DATA — the API Server's plugins.json (plugin enable-state + config). A +# host path must be writable by uid 10001, the image's runtime user. +API_DATA=api_data + +# --- File storage: external S3 ----------------------------------------------- +# PocketBase keeps its record files — the document store's scans of pilot +# certificates, aircraft registrations, insurance and authorisations — in the +# bucket below instead of on pb_data. The database and PocketBase's own backups +# stay where they are. +# +# Nothing in this stack runs a gateway: both the endpoint and the bucket must +# already exist. For a gateway on this Docker host use +# http://host.docker.internal:8333 — the compose file adds the host entry that +# makes that name resolve inside the containers. +PB_S3_ENDPOINT=http://host.docker.internal:8333 +PB_S3_BUCKET=pilotvault +PB_S3_ACCESS_KEY= +PB_S3_SECRET= +# SeaweedFS and MinIO ignore the region; PocketBase insists on having one. +PB_S3_REGION=us-east-1 +# true for SeaweedFS and MinIO, false for AWS S3 proper. +PB_S3_FORCE_PATH_STYLE=true + +# Existing uploads are NOT migrated when this is switched on: PocketBase copies +# nothing, so documents uploaded before the switch stop resolving. Read the file +# storage section of README.md first. diff --git a/Docker/.env.seaweedfs.example b/Docker/.env.seaweedfs.example new file mode 100644 index 0000000..c89a766 --- /dev/null +++ b/Docker/.env.seaweedfs.example @@ -0,0 +1,65 @@ +# Copy to .env and fill in. Used by docker-compose.seaweedfs.yml. + +# --- PocketBase superuser (also used by the API Server to authenticate) ------ +# Created/updated on the PocketBase container's first boot. REQUIRED. +POCKETBASE_ADMIN_EMAIL=admin@dji.local +POCKETBASE_ADMIN_PASSWORD=change-me-long-password + +# The app super-admin login (superadmin@pilotvault.local) is created by the +# bundled PocketBase migrations on first boot — no separate env var needed. + +# --- API Server ------------------------------------------------------------- +# Allowed CORS origin(s) for the web app (match WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +PB_PORT=8070 +API_PORT=8080 +WEB_PORT=8090 + +# --- Settings the API Server panel can also change --------------------------- +# The panel's Settings screens apply these immediately, but only for the life of +# the container — the values below are re-applied on every restart and win. Set +# them here to make a change permanent. +# POCKETBASE_URL where the API Server looks for the database. Defaults to +# the bundled pocketbase service; set it to reach one +# outside this stack. +# WEBAPP_URL the Web App address the panel status page probes. It is +# a container-to-container call, so it must be reachable +# from the API Server, not from your browser. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# POCKETBASE_URL=http://pocketbase:8070 +# WEBAPP_URL=http://web-app:8090 + +# --- Storage ---------------------------------------------------------------- +# Docker-managed named volumes by default. To store one on a host path instead, +# set an absolute path, e.g. PB_DATA=/srv/pilotvault/pb_data. +# PB_DATA — the PocketBase database and its backups. +# The documents themselves live in the bucket below. +PB_DATA=pb_data +# API_DATA — the API Server's plugins.json (plugin enable-state + config). A +# host path must be writable by uid 10001, the image's runtime user. +API_DATA=api_data + +# --- File storage: SeaweedFS ------------------------------------------------- +# PocketBase keeps its record files — the document store's scans of pilot +# certificates, aircraft registrations, insurance and authorisations — in the +# bucket below instead of on pb_data. The database and PocketBase's own backups +# stay where they are. +# +# The credentials do double duty: they configure the SeaweedFS gateway's single +# identity *and* are what PocketBase authenticates with. There are no safe +# defaults, and the stack refuses to start without them. +PB_S3_ACCESS_KEY= +PB_S3_SECRET= +# The bucket. Created on first boot by the seaweedfs-init container. +PB_S3_BUCKET=pilotvault +# SeaweedFS ignores the region; PocketBase insists on having one. +PB_S3_REGION=us-east-1 +# The gateway image, pinned so a rebuild months from now brings up the same one. +# SEAWEED_IMAGE=chrislusf/seaweedfs:4.45 + +# Existing uploads are NOT migrated when this is switched on: PocketBase copies +# nothing, so documents uploaded before the switch stop resolving. Read the file +# storage section of README.md first. diff --git a/Docker/.env.seaweedfs.split.example b/Docker/.env.seaweedfs.split.example new file mode 100644 index 0000000..6233e2f --- /dev/null +++ b/Docker/.env.seaweedfs.split.example @@ -0,0 +1,91 @@ +# Copy to .env and fill in. Used by docker-compose.seaweedfs.split.yml. + +# --- PocketBase superuser (also used by the API Server to authenticate) ------ +# Created/updated on the PocketBase container's first boot. REQUIRED. +POCKETBASE_ADMIN_EMAIL=admin@dji.local +POCKETBASE_ADMIN_PASSWORD=change-me-long-password + +# The app super-admin login (superadmin@pilotvault.local) is created by the +# bundled PocketBase migrations on first boot — no separate env var needed. + +# --- API Server ------------------------------------------------------------- +# Allowed CORS origin(s) for the web app (match WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +PB_PORT=8070 +API_PORT=8080 +WEB_PORT=8090 + +# --- Settings the API Server panel can also change --------------------------- +# The panel's Settings screens apply these immediately, but only for the life of +# the container — the values below are re-applied on every restart and win. Set +# them here to make a change permanent. +# POCKETBASE_URL where the API Server looks for the database. Defaults to +# the bundled pocketbase service; set it to reach one +# outside this stack. +# WEBAPP_URL the Web App address the panel status page probes. It is +# a container-to-container call, so it must be reachable +# from the API Server, not from your browser. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# POCKETBASE_URL=http://pocketbase:8070 +# WEBAPP_URL=http://web-app:8090 + +# --- Storage ---------------------------------------------------------------- +# Docker-managed named volumes by default. To store one on a host path instead, +# set an absolute path, e.g. PB_DATA=/srv/pilotvault/pb_data. +# PB_DATA — the PocketBase database and its backups. +# The documents themselves live in the bucket below. +PB_DATA=pb_data +# API_DATA — the API Server's plugins.json (plugin enable-state + config). A +# host path must be writable by uid 10001, the image's runtime user. +API_DATA=api_data + +# --- File storage: SeaweedFS ------------------------------------------------- +# PocketBase keeps its record files — the document store's scans of pilot +# certificates, aircraft registrations, insurance and authorisations — in the +# bucket below instead of on pb_data. The database and PocketBase's own backups +# stay where they are. +# +# The credentials do double duty: seaweedfs-init writes them into the filer's +# IAM store as the identity named "pilotvault" *and* they are what PocketBase +# authenticates with. There are no safe defaults, and the stack refuses to start +# without them. Change them here and restart to rotate: the seed updates the +# identity in place rather than adding a second one. +PB_S3_ACCESS_KEY= +PB_S3_SECRET= +# The bucket. Created on first boot by the seaweedfs-init container. +PB_S3_BUCKET=pilotvault +# SeaweedFS ignores the region; PocketBase insists on having one. +PB_S3_REGION=us-east-1 +# The SeaweedFS image, pinned so a rebuild months from now brings up the same +# one. All five SeaweedFS containers run it. +# SEAWEED_IMAGE=chrislusf/seaweedfs:4.45 + +# --- SeaweedFS admin UI ------------------------------------------------------ +# http://localhost:23646 — cluster topology, volumes, buckets, and Object Store +# → Users, where further S3 identities are created and revoked. They land in the +# filer's IAM store, the same one seeded above, and the gateway picks them up +# without a restart. +# +# REQUIRED: weed disables authentication entirely when the password is empty, +# and this panel can mint credentials for the bucket. +SEAWEED_ADMIN_USER=admin +SEAWEED_ADMIN_PASSWORD= +# SEAWEED_ADMIN_PORT=23646 + +# --- SeaweedFS host ports (optional; defaults shown) ------------------------- +# Published for aws-cli, `weed shell` and poking around while developing. The +# stack itself reaches every one of these over the compose network, and the S3 +# gateway too, which is not published so a second stack cannot clash on it. Note +# SEAWEED_VOLUME_PORT: the volume server serves file content by id with NO +# authentication, so do not carry this mapping over to a shared machine. It +# lands on 8081 because API_PORT already has 8080. +# SEAWEED_MASTER_PORT=9333 +# SEAWEED_VOLUME_PORT=8081 +# SEAWEED_FILER_PORT=8888 + +# Existing uploads are NOT migrated when this is switched on: PocketBase copies +# nothing, so documents uploaded before the switch stop resolving. Read the file +# storage section of README.md first. diff --git a/Docker/README.md b/Docker/README.md new file mode 100644 index 0000000..625fb4a --- /dev/null +++ b/Docker/README.md @@ -0,0 +1,194 @@ +# PilotVault — Docker (multi-container stack) + +Three containers — **PocketBase**, **API Server**, **Web App** — on one compose +network. This is the deployment to use unless you specifically want everything +in a single image; for that see [`../Docker-AIO`](../Docker-AIO). + +``` +Browser ─► Web App BFF (:8090) ──/api/*──► API Server (:8080) ─► PocketBase (:8070) +``` + +Only the Web App port is meant to be public. The API Server and the PocketBase +admin UI are published for convenience and, in the prod files, bound to +`127.0.0.1` by default. + +| File | Use | +|---|---| +| `docker-compose.yml` | **builds from source** in this repo — for development and local testing | +| `docker-compose.prod.yml` | **pulls prebuilt images** from the registry — for deployment | +| `.env.example` / `.env.prod.example` | copy to `.env` for the matching compose file | +| `docker-compose[.prod].{s3,seaweedfs,seaweedfs.split}.yml` | the same stack with file storage in S3 — see [File storage](#file-storage-seaweedfs--s3) | +| `pocketbase/` | the PocketBase image (official release binary on alpine, plus the bundled migrations) | + +## Run it + +```bash +cd Docker +cp .env.example .env # then edit — POCKETBASE_ADMIN_* have no safe defaults +docker compose up -d --build +``` + +Production, from the registry: + +```bash +cp .env.prod.example .env # then edit +docker compose -f docker-compose.prod.yml pull +docker compose -f docker-compose.prod.yml up -d +``` + +Then: web app on `http://host:8090/`, the API Server's superadmin panel on +`http://host:8080/`, PocketBase admin on `http://host:8070/_/`. + +The PocketBase image builds with the **repo root** as its context (it copies the +migrations from `API Server/pocketbase/pb_migrations`), so the root +`.dockerignore` keeps the Fly/Phone apps and other siblings out of it. + +## First boot + +Everything happens inside PocketBase, and every step is idempotent, so restarts +and upgrades are safe: + +1. **The entrypoint** upserts the PocketBase superuser from + `POCKETBASE_ADMIN_EMAIL` / `POCKETBASE_ADMIN_PASSWORD`. This is the only way to + create the first superuser — the REST API cannot bootstrap it. The API Server + then authenticates with the same credentials. +2. **PocketBase runs the bundled JS migrations**, which create/reconcile every + collection (users, organizations, drones, flights, documents, routes, plugin + settings…) and seed the baseline org and accounts, including the + `superadmin@pilotvault.local` app login. + +Unlike DriverVault, the API Server does not create schema itself. A release that +adds a collection ships it as a new migration in the PocketBase image, so +upgrading means pulling/rebuilding **both** images. + +> The image pins PocketBase **v0.39.11**. It must be v0.23 or newer — the +> migrations use the v0.23+ JSVM API and the entrypoint uses `superuser upsert`. + +## Volumes + +| Volume | Holds | +|---|---| +| `pb_data` (`PB_DATA`) | the PocketBase SQLite database, its backups and — unless S3 is on — the uploaded document blobs | +| `api_data` (`API_DATA`) | the API Server's `plugins.json`: plugin enable-state and config | + +Both default to Docker-managed named volumes; set `PB_DATA` / `API_DATA` to an +absolute host path in `.env` for a bind mount instead. PocketBase runs as root, +so a root-owned host directory is fine for `pb_data`. The API Server runs as +uid 10001, so an `API_DATA` host directory must be writable by that uid (a named +volume inherits the right ownership from the image on its own). + +> One thing does **not** persist: the API Server panel's *Settings → PocketBase* +> screen applies immediately but only for the life of the container. Set +> `POCKETBASE_URL`, `POCKETBASE_ADMIN_EMAIL` / `POCKETBASE_ADMIN_PASSWORD`, +> `WEBAPP_URL` and `CORS_ALLOW_ORIGINS` in `.env` to change them permanently — +> in this stack the compose environment wins over anything the panel writes. + +## File storage (SeaweedFS / S3) + +Uploaded files — the document store's scans of pilot certificates, aircraft +registrations, insurance and authorisations — live inside `pb_data` by default, +next to the database. The further compose files put them in an S3 bucket +instead, so the blobs and the database can be sized, backed up and moved +independently. Nothing else changes: a document has always been downloaded +through the API Server (`GET /api/documents/{id}/file`), never from a storage +URL, so the Web App and the Fly/Phone apps cannot tell the difference. + +Each shape is one self-contained compose file — nothing to layer, nothing to +remember — with an `.env` example of the same name: + +| Shape | From the registry | From source | +|---|---|---| +| **Local storage** — the default, unchanged | `docker-compose.prod.yml` | `docker-compose.yml` | +| **SeaweedFS in this stack** | `docker-compose.prod.seaweedfs.yml` | `docker-compose.seaweedfs.yml` | +| **SeaweedFS, split into its roles** | `docker-compose.prod.seaweedfs.split.yml` | `docker-compose.seaweedfs.split.yml` | +| **An S3 endpoint outside it** | `docker-compose.prod.s3.yml` | `docker-compose.s3.yml` | + +So `docker-compose.prod.seaweedfs.yml` is configured from +`.env.prod.seaweedfs.example`, `docker-compose.s3.yml` from `.env.s3.example`, +and so on: + +```sh +cp .env.prod.seaweedfs.example .env # then edit it — PB_S3_* have no defaults +docker compose -f docker-compose.prod.seaweedfs.yml pull +docker compose -f docker-compose.prod.seaweedfs.yml up -d +``` + +Set `PB_S3_ACCESS_KEY` and `PB_S3_SECRET` first — every storage file refuses to +start without them. The SeaweedFS ones add a `seaweedfs` container (master, +volume, filer and S3 gateway in one process, on its own `seaweed_data` volume) +plus a one-shot `seaweedfs-init` that creates the bucket, because PocketBase never +issues a `CreateBucket` of its own. The external-S3 ones add no containers at +all: set `PB_S3_ENDPOINT`, and create the bucket yourself. + +### Split SeaweedFS + +`weed server -s3` runs master, volume, filer and gateway as four goroutines in +one process. The `.split.` files run them as four containers, plus a fifth: the +SeaweedFS **admin UI** on port 23646, where the cluster can be inspected and — +under *Object Store → Users* — further S3 identities minted and revoked. Split +also gets you per-role restarts and upgrades, per-role Prometheus metrics, and +room to add a second volume server later. + +Identities work differently there, and it matters. SeaweedFS reads credentials +from, in descending priority: an `-s3.config` file, the filer's IAM store, then +`AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` — and a higher source *replaces* +a lower one rather than adding to it. The single-process files use the env vars, +which is why nothing else may write identities there: the first user added in a +panel would displace PocketBase's key. So in the split files `seaweedfs-init` +seeds PocketBase's identity (named `pilotvault`) into the filer's store instead — +the same store the admin UI writes — and the gateway runs with no config file at +all. One source of truth, PocketBase's key visible in the panel beside every +other, and new keys picked up without a restart. Rotating `PB_S3_SECRET` in +`.env` and restarting updates that identity in place. + +Set `SEAWEED_ADMIN_PASSWORD`: `weed admin` serves the panel with no +authentication when it is empty, and a panel that can mint bucket credentials is +the bucket. In the prod file it is bound to loopback like `PB_BIND` and +`API_BIND`, so a remote host needs `SEAWEED_ADMIN_BIND=0.0.0.0` behind a reverse +proxy. That file publishes nothing for master, volume and filer — the volume +server serves file content by id with no authentication of any kind, and the +admin UI already shows what those ports would. + +Switching between `docker-compose.seaweedfs.yml` and its `.split.` twin needs no +migration: master, volume and filer share one `/data` mount, which is exactly +the layout `weed server -dir=/data` writes. + +### How the switch happens + +On every boot the API Server reads `PB_S3_*` and writes PocketBase's *Files +storage* settings from them (only when they differ from what is already there), +then asks PocketBase to prove it can reach the bucket. It retries for about half +a minute while PocketBase is still starting, and never blocks the server from +coming up. Watch for it in the log: + +``` +[api] storage: ✓ file storage → S3 (pilotvault at http://seaweedfs:8333) +[api] storage: ✓ S3 storage reachable +``` + +A boot that finds the settings already correct logs +`• file storage already on S3` and writes nothing. + +Two things to know before turning it on: + +- **Existing files are not migrated.** PocketBase copies nothing when the setting + flips, so documents uploaded before the switch stop resolving. Copy + `pb_data/storage///` into the bucket root, keeping + that layout, *before* enabling it — or start from a stack with no documents. +- **Going back to the plain compose file is not an off switch.** It leaves + PocketBase pointed at the bucket, deliberately: files already written there are + reachable only while it is. Move them back and turn it off in PocketBase's own + admin UI. For the same reason a rotation of `PB_S3_SECRET` alone is invisible to + the API Server — PocketBase masks the stored secret on read — so change another + `PB_S3_*` value alongside it, or set it in the admin UI. + +## Notes + +- `docker-compose.yml` builds the API Server and Web App from `../API Server` + and `../Web App`, and PocketBase from the repo root, so run it from this + directory with the repo checked out. +- The Web App's Vue bundle uses same-origin `/bff` and `/api`, which the BFF + proxies — no CORS in play. `CORS_ALLOW_ORIGINS` therefore only matters if a + browser calls the API Server directly. Native apps are not subject to CORS. +- Nothing in this stack terminates TLS. Put your own reverse proxy in front of + the Web App port and set `CORS_ALLOW_ORIGINS` to its public origin. diff --git a/Docker/docker-compose.prod.s3.yml b/Docker/docker-compose.prod.s3.yml new file mode 100644 index 0000000..1c4c953 --- /dev/null +++ b/Docker/docker-compose.prod.s3.yml @@ -0,0 +1,152 @@ +name: pilotvault + +# Production PilotVault stack, with external S3 — pulls prebuilt images from the +# registry instead of building from source. Self-contained: one file, no +# overlays. Everything an operator needs to set lives in .env. +# +# 1. cp .env.prod.s3.example .env (then edit it — PB_S3_* especially) +# 2. docker compose -f docker-compose.prod.s3.yml pull +# 3. docker compose -f docker-compose.prod.s3.yml up -d +# +# This is docker-compose.prod.yml pointed at an S3 endpoint that already exists +# somewhere else — its own host, another compose project, or any S3-compatible +# service. PocketBase keeps its record files — the document store's scans of +# pilot certificates, aircraft registrations, insurance and authorisations — in +# that bucket instead of on the pb_data volume. The database and PocketBase's +# own backups stay on PB_DATA. Clients cannot tell the difference: a document +# has always been downloaded through the API Server (GET +# /api/documents/{id}/file), never from a storage URL. +# +# The bucket must already exist, and nothing here runs the gateway. For a +# SeaweedFS that comes up with the stack, use docker-compose.prod.seaweedfs.yml. +# +# Before turning this on for a stack that already has uploads: PocketBase does +# NOT copy existing files into the bucket. See README.md. +# +# Traffic flow (browser): Web App BFF --/api--> API Server --> PocketBase. +# +# On first boot: +# • PocketBase upserts the superuser from POCKETBASE_ADMIN_* (create-if-missing). +# • PocketBase runs the bundled migrations: creates/reconciles every collection +# and seeds the baseline org + the superadmin@pilotvault.local app login. +# Both steps are idempotent, so restarts and upgrades are safe. + +services: + pocketbase: + image: "${PB_IMAGE:-10.2.1.10:5500/admin/pilotvault-pocketbase:latest}" + container_name: pilotvault-pocketbase + restart: unless-stopped + extra_hosts: + # Lets PB_S3_ENDPOINT name the Docker host as host.docker.internal. + # Harmless when the endpoint is somewhere else entirely. + - "host.docker.internal:host-gateway" + environment: + # The superuser is created/updated on boot (the API Server authenticates + # with it). This is the only place the first superuser can be created — the + # REST API cannot bootstrap it. On the same boot PocketBase runs the bundled + # migrations: every collection, plus the baseline org and the + # superadmin@pilotvault.local app login. + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + volumes: + # Named volume by default; set PB_DATA to a host path in .env for a bind mount. + - "${PB_DATA:-pb_data}:/pb/pb_data" + ports: + # Bound to localhost by default — the admin UI (/_/) is reachable only on + # the host. Set PB_BIND=0.0.0.0 in .env to expose it on the network. + - "${PB_BIND:-127.0.0.1}:${PB_PORT:-8070}:8070" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + + api-server: + image: "${API_IMAGE:-10.2.1.10:5500/admin/pilotvault-api-server:latest}" + container_name: pilotvault-api-server + restart: unless-stopped + extra_hosts: + # Lets PB_S3_ENDPOINT name the Docker host as host.docker.internal. + # Harmless when the endpoint is somewhere else entirely. + - "host.docker.internal:host-gateway" + depends_on: + pocketbase: + condition: service_healthy + environment: + API_ADDR: ":8080" + # Reach PocketBase by its service name on the internal network. Override + # POCKETBASE_URL in .env to point the API Server at a database outside + # this stack — that is also how you make a retarget done from the panel + # permanent, since the panel's change lasts only for the container's life. + POCKETBASE_URL: "${POCKETBASE_URL:-http://pocketbase:8070}" + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD}" + # Probed by the panel status page. This is a server-to-server call inside + # the compose network, so the default is the service name — plain + # localhost:8090 would resolve to this container itself. + WEBAPP_URL: "${WEBAPP_URL:-http://web-app:8090}" + # Same-origin requests go through the Web App BFF, so CORS is only needed + # if a browser ever calls the API Server directly. Default to the web origin. + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Plugin enable-state + config, on the api_data volume below. + PLUGINS_FILE: "/app/data/plugins.json" + # --- File storage -------------------------------------------------- + # The PilotVault API Server reads these on every boot and writes them into + # PocketBase's Files storage settings, idempotently. Only record files + # move — the document store's blobs. The database and PocketBase's own + # backups stay on pb_data. The bucket must already exist: nothing here + # creates it. + PB_S3_ENABLED: "true" + PB_S3_BUCKET: "${PB_S3_BUCKET:-pilotvault}" + PB_S3_ENDPOINT: "${PB_S3_ENDPOINT:?set PB_S3_ENDPOINT in .env}" + PB_S3_REGION: "${PB_S3_REGION:-us-east-1}" + PB_S3_ACCESS_KEY: "${PB_S3_ACCESS_KEY:?set PB_S3_ACCESS_KEY in .env}" + PB_S3_SECRET: "${PB_S3_SECRET:?set PB_S3_SECRET in .env}" + # true for SeaweedFS and MinIO, false for AWS S3 proper. + PB_S3_FORCE_PATH_STYLE: "${PB_S3_FORCE_PATH_STYLE:-true}" + volumes: + # The one thing the API Server keeps on disk: plugins.json. Named volume + # by default; set API_DATA to a host path in .env for a bind mount (it + # must be writable by uid 10001, the image's runtime user). + - "${API_DATA:-api_data}:/app/data" + ports: + # Localhost-only by default (the Web App reaches it over the internal + # network). Set API_BIND=0.0.0.0 to expose the API panel — and the + # Fly App uplink, if drones connect here directly — on the network. + - "${API_BIND:-127.0.0.1}:${API_PORT:-8080}:8080" + healthcheck: + # Declared here rather than relying only on the image's HEALTHCHECK, so the + # depends_on gate below still works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + web-app: + image: "${WEB_IMAGE:-10.2.1.10:5500/admin/pilotvault-web-app:latest}" + container_name: pilotvault-web-app + restart: unless-stopped + depends_on: + # Wait for the API Server to be serving rather than merely started. + api-server: + condition: service_healthy + environment: + ADDR: ":8090" + # The BFF reverse-proxies /api/* to the API Server over the internal network. + API_BASE: "http://api-server:8080" + ports: + # The public front door. Bound on all interfaces so browsers can reach it. + - "${WEB_PORT:-8090}:8090" + healthcheck: + # The BFF has no health route of its own; the SPA index answers 200. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + +volumes: + pb_data: + api_data: diff --git a/Docker/docker-compose.prod.seaweedfs.split.yml b/Docker/docker-compose.prod.seaweedfs.split.yml new file mode 100644 index 0000000..5864be3 --- /dev/null +++ b/Docker/docker-compose.prod.seaweedfs.split.yml @@ -0,0 +1,369 @@ +name: pilotvault + +# Production PilotVault stack, with SeaweedFS split into its four roles — pulls +# prebuilt images from the registry instead of building from source. +# Self-contained: one file, no overlays. Everything an operator needs to set +# lives in .env. +# +# 1. cp .env.prod.seaweedfs.split.example .env (then edit it) +# 2. docker compose -f docker-compose.prod.seaweedfs.split.yml pull +# 3. docker compose -f docker-compose.prod.seaweedfs.split.yml up -d +# +# This is docker-compose.prod.seaweedfs.yml with the storage layer taken apart. +# `weed server -s3` runs master, volume, filer and gateway as goroutines in one +# process; here each is its own container, plus the SeaweedFS admin UI. What +# that buys: +# +# • the admin UI (weed admin) — a cluster view, and Object Store → Users, +# where S3 identities are created and revoked without touching a file; +# • per-role restart, upgrade and Prometheus metrics; +# • room to add a second volume server later, on this host or another. +# +# What it costs: five containers instead of one, five healthchecks to keep the +# boot order honest, and one more port worth binding carefully. If none of the +# above is wanted, use docker-compose.prod.seaweedfs.yml — the S3 behaviour is +# identical. +# +# The on-disk layout is deliberately the same as the single-process file's: +# master, volume and filer share one /data mount, exactly as `weed server -dir` +# lays it out (master raft state, volume .dat/.idx, the filer's filerldb2/ — no +# filename overlap). So the two files are interchangeable on the same +# SEAWEED_DATA, with no migration either way. A *second* volume server would +# need its own. +# +# Only the admin UI publishes a host port. The S3 gateway, master, volume and +# filer are reachable over the compose network, through the admin UI, or with +# `docker compose exec` — the volume server in particular serves file content by +# id with no authentication at all, so it has no business on a public interface. +# +# Before turning this on for a stack that already has uploads: PocketBase does +# NOT copy existing files into the bucket. See README.md. +# +# Traffic flow (browser): Web App BFF --/api--> API Server --> PocketBase. +# +# On first boot: +# • PocketBase upserts the superuser from POCKETBASE_ADMIN_* (create-if-missing). +# • PocketBase runs the bundled migrations: creates/reconciles every collection +# and seeds the baseline org + the superadmin@pilotvault.local app login. +# Both steps are idempotent, so restarts and upgrades are safe. + +services: + # --- SeaweedFS: master ----------------------------------------------------- + # Keeps the volume/topology metadata and hands out file ids. -ip is the name + # the other roles are told to reach it by, so it must be the service name and + # not the container IP the process would otherwise detect. + seaweedfs-master: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-master + restart: unless-stopped + command: > + master -ip=seaweedfs-master -ip.bind=0.0.0.0 -mdir=/data + -volumeSizeLimitMB=1024 -metricsPort=9324 + volumes: + # Named volume by default; set SEAWEED_DATA to a host path in .env for a + # bind mount, exactly as PB_DATA works. Back it up alongside PB_DATA — + # from here on the documents live here, not in the database volume. + - "${SEAWEED_DATA:-seaweed_data}:/data" + # No published port: the master UI is one of the pages the admin UI serves. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: volume server --------------------------------------------- + # Where the bytes actually land. -max=0 lets it size itself from free disk + # rather than the default cap of 8 volumes. + seaweedfs-volume: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-volume + restart: unless-stopped + command: > + volume -master=seaweedfs-master:9333 -ip=seaweedfs-volume -ip.bind=0.0.0.0 + -port=8080 -dir=/data -max=0 -metricsPort=9325 + depends_on: + seaweedfs-master: + condition: service_healthy + volumes: + - "${SEAWEED_DATA:-seaweed_data}:/data" + # No published port, and this one is not an oversight: 8080 serves file + # content by file id with NO authentication — the S3 credentials do not + # apply to it. Publishing it would publish every document in the stack. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: filer ------------------------------------------------------ + # Gives the flat volume store a directory tree — buckets, object keys — and + # holds the S3 identities the admin UI writes. -defaultStoreDir is where its + # embedded leveldb goes; without it that would be the container's working + # directory, and the identities would not survive a recreate. + seaweedfs-filer: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-filer + restart: unless-stopped + command: > + filer -master=seaweedfs-master:9333 -ip=seaweedfs-filer -ip.bind=0.0.0.0 + -port=8888 -defaultStoreDir=/data -metricsPort=9326 + depends_on: + seaweedfs-volume: + condition: service_healthy + volumes: + - "${SEAWEED_DATA:-seaweed_data}:/data" + # No published port. The filer's gRPC side (8888 + 10000) carries the IAM + # service that mints S3 credentials; keep both ends of it on the compose + # network. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8888/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: bucket and identity seed ---------------------------------- + # Runs once and exits, before the gateway starts. Two jobs: + # + # 1. create the bucket — PocketBase never issues a CreateBucket of its own; + # 2. write PocketBase's S3 identity into the filer's IAM store. + # + # (2) is why this stack does not set AWS_ACCESS_KEY_ID on the gateway, the way + # docker-compose.prod.seaweedfs.yml does. Those env vars are the *lowest* + # priority credential source in SeaweedFS: they are read only while the + # filer's store is empty, so the first identity added in the admin UI would + # silently displace them and lock PocketBase out. Seeding the store the admin + # UI itself writes leaves one source of truth, and the key PocketBase uses + # appears under Object Store → Users like any other. + # + # Both commands update in place, so every later boot re-applies the values + # from .env and changes nothing else — which is also how a rotated + # PB_S3_SECRET reaches the gateway. + # + # The closing grep is the gate: an empty IAM store means the gateway would + # come up in its allow-anyone default, so this fails loudly instead and the + # gateway below never starts. No `|| true` here, deliberately. + seaweedfs-init: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-init + restart: "no" + depends_on: + seaweedfs-filer: + condition: service_healthy + environment: + # Passed as env and expanded by the shell inside the container, so the + # secret stays out of the container's argv. + PB_S3_BUCKET: "${PB_S3_BUCKET:-pilotvault}" + PB_S3_ACCESS_KEY: "${PB_S3_ACCESS_KEY:?set PB_S3_ACCESS_KEY in .env}" + PB_S3_SECRET: "${PB_S3_SECRET:?set PB_S3_SECRET in .env}" + entrypoint: ["/bin/sh", "-c"] + command: + - | + set -e + printf '%s\n' \ + "s3.bucket.create -name $$PB_S3_BUCKET" \ + "s3.configure -user pilotvault -access_key $$PB_S3_ACCESS_KEY -secret_key $$PB_S3_SECRET -actions Admin -apply" \ + | weed shell -master=seaweedfs-master:9333 -filer=seaweedfs-filer:8888 + echo "s3.configure" \ + | weed shell -master=seaweedfs-master:9333 -filer=seaweedfs-filer:8888 \ + | grep -q "$$PB_S3_ACCESS_KEY" + + # --- SeaweedFS: S3 gateway ------------------------------------------------- + # The endpoint PocketBase talks to. No -config file: with only -filer given, + # credentials come from the filer's IAM store, which is what lets the admin UI + # add and revoke identities without a restart. A config file would take + # priority over that store and make the admin UI's users inert. + seaweedfs-s3: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-s3 + restart: unless-stopped + command: > + s3 -filer=seaweedfs-filer:8888 -ip.bind=0.0.0.0 -port=8333 + -metricsPort=9327 + depends_on: + seaweedfs-filer: + condition: service_healthy + # Never serve before an identity exists — see seaweedfs-init above. + seaweedfs-init: + condition: service_completed_successfully + # No published port: the stack reaches the gateway over the compose network. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8333/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: admin UI --------------------------------------------------- + # Cluster topology, volumes, buckets, maintenance tasks, and Object Store → + # Users, where S3 access keys are minted and revoked. It finds the filer + # through the master, so -master is all it needs. + # + # Bound to loopback by default, like the PocketBase and API panels: on a + # remote host that means unreachable, so set SEAWEED_ADMIN_BIND=0.0.0.0 the + # same way PB_BIND and API_BIND get set — and put it behind the same reverse + # proxy. + # + # An unauthenticated panel that can mint credentials for the bucket *is* the + # bucket, so the password is required rather than defaulted — weed leaves auth + # off entirely when it is empty. It is read from WEED_ADMIN_* rather than a + # flag, which keeps it off the process command line. -dataDir persists the + # session key and the maintenance-task settings. + seaweedfs-admin: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-admin + restart: unless-stopped + command: > + admin -port=23646 -master=seaweedfs-master:9333 -dataDir=/data + -metricsPort=9328 + depends_on: + seaweedfs-master: + condition: service_healthy + environment: + WEED_ADMIN_USER: "${SEAWEED_ADMIN_USER:-admin}" + WEED_ADMIN_PASSWORD: "${SEAWEED_ADMIN_PASSWORD:?set SEAWEED_ADMIN_PASSWORD in .env}" + # Optional view-only login. weed ignores it unless the admin password + # above is set, which it is. + WEED_ADMIN_READONLY_USER: "${SEAWEED_ADMIN_READONLY_USER:-}" + WEED_ADMIN_READONLY_PASSWORD: "${SEAWEED_ADMIN_READONLY_PASSWORD:-}" + volumes: + # Its own small volume: session key and maintenance state, no object data. + - "${SEAWEED_ADMIN_DATA:-seaweed_admin}:/data" + ports: + - "${SEAWEED_ADMIN_BIND:-127.0.0.1}:${SEAWEED_ADMIN_PORT:-23646}:23646" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:23646/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + pocketbase: + image: "${PB_IMAGE:-10.2.1.10:5500/admin/pilotvault-pocketbase:latest}" + container_name: pilotvault-pocketbase + restart: unless-stopped + depends_on: + # PocketBase is the process that reads and writes the objects, so the + # gateway has to be serving before it is asked to store anything. + seaweedfs-s3: + condition: service_healthy + environment: + # The superuser is created/updated on boot (the API Server authenticates + # with it). This is the only place the first superuser can be created — the + # REST API cannot bootstrap it. On the same boot PocketBase runs the bundled + # migrations: every collection, plus the baseline org and the + # superadmin@pilotvault.local app login. + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + volumes: + # Named volume by default; set PB_DATA to a host path in .env for a bind mount. + - "${PB_DATA:-pb_data}:/pb/pb_data" + ports: + # Bound to localhost by default — the admin UI (/_/) is reachable only on + # the host. Set PB_BIND=0.0.0.0 in .env to expose it on the network. + - "${PB_BIND:-127.0.0.1}:${PB_PORT:-8070}:8070" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + + api-server: + image: "${API_IMAGE:-10.2.1.10:5500/admin/pilotvault-api-server:latest}" + container_name: pilotvault-api-server + restart: unless-stopped + depends_on: + pocketbase: + condition: service_healthy + # The bucket must exist before the API Server points PocketBase at it. + seaweedfs-init: + condition: service_completed_successfully + environment: + API_ADDR: ":8080" + # Reach PocketBase by its service name on the internal network. Override + # POCKETBASE_URL in .env to point the API Server at a database outside + # this stack — that is also how you make a retarget done from the panel + # permanent, since the panel's change lasts only for the container's life. + POCKETBASE_URL: "${POCKETBASE_URL:-http://pocketbase:8070}" + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD}" + # Probed by the panel status page. This is a server-to-server call inside + # the compose network, so the default is the service name — plain + # localhost:8090 would resolve to this container itself. + WEBAPP_URL: "${WEBAPP_URL:-http://web-app:8090}" + # Same-origin requests go through the Web App BFF, so CORS is only needed + # if a browser ever calls the API Server directly. Default to the web origin. + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Plugin enable-state + config, on the api_data volume below. + PLUGINS_FILE: "/app/data/plugins.json" + # --- File storage -------------------------------------------------- + # The PilotVault API Server reads these on every boot and writes them into + # PocketBase's Files storage settings, idempotently. Only record files + # move — the document store's blobs. The database and PocketBase's own + # backups stay on pb_data. + PB_S3_ENABLED: "true" + PB_S3_BUCKET: "${PB_S3_BUCKET:-pilotvault}" + # The gateway's service name: a server-to-server call inside the compose + # network. + PB_S3_ENDPOINT: "http://seaweedfs-s3:8333" + # SeaweedFS ignores the region; PocketBase insists on having one. + PB_S3_REGION: "${PB_S3_REGION:-us-east-1}" + PB_S3_ACCESS_KEY: "${PB_S3_ACCESS_KEY}" + PB_S3_SECRET: "${PB_S3_SECRET}" + # Path style, because a self-hosted gateway has no per-bucket DNS. + PB_S3_FORCE_PATH_STYLE: "true" + volumes: + # The one thing the API Server keeps on disk: plugins.json. Named volume + # by default; set API_DATA to a host path in .env for a bind mount (it + # must be writable by uid 10001, the image's runtime user). + - "${API_DATA:-api_data}:/app/data" + ports: + # Localhost-only by default (the Web App reaches it over the internal + # network). Set API_BIND=0.0.0.0 to expose the API panel — and the + # Fly App uplink, if drones connect here directly — on the network. + - "${API_BIND:-127.0.0.1}:${API_PORT:-8080}:8080" + healthcheck: + # Declared here rather than relying only on the image's HEALTHCHECK, so the + # depends_on gate below still works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + web-app: + image: "${WEB_IMAGE:-10.2.1.10:5500/admin/pilotvault-web-app:latest}" + container_name: pilotvault-web-app + restart: unless-stopped + depends_on: + # Wait for the API Server to be serving rather than merely started. + api-server: + condition: service_healthy + environment: + ADDR: ":8090" + # The BFF reverse-proxies /api/* to the API Server over the internal network. + API_BASE: "http://api-server:8080" + ports: + # The public front door. Bound on all interfaces so browsers can reach it. + - "${WEB_PORT:-8090}:8090" + healthcheck: + # The BFF has no health route of its own; the SPA index answers 200. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + +volumes: + pb_data: + api_data: + # Shared by master, volume and filer — the same layout `weed server -dir` + # writes, so this file and docker-compose.prod.seaweedfs.yml can swap places + # on it. + seaweed_data: + # The admin UI's own session key and maintenance-task state. Small, and no + # part of the object store. + seaweed_admin: diff --git a/Docker/docker-compose.prod.seaweedfs.yml b/Docker/docker-compose.prod.seaweedfs.yml new file mode 100644 index 0000000..384892e --- /dev/null +++ b/Docker/docker-compose.prod.seaweedfs.yml @@ -0,0 +1,195 @@ +name: pilotvault + +# Production PilotVault stack, with SeaweedFS — pulls prebuilt images from the +# registry instead of building from source. Self-contained: one file, no +# overlays. Everything an operator needs to set lives in .env. +# +# 1. cp .env.prod.seaweedfs.example .env (then edit it) +# 2. docker compose -f docker-compose.prod.seaweedfs.yml pull +# 3. docker compose -f docker-compose.prod.seaweedfs.yml up -d +# +# This is docker-compose.prod.yml plus an S3 object store: PocketBase keeps its +# record files — the document store's scans of pilot certificates, aircraft +# registrations, insurance and authorisations — in a SeaweedFS bucket instead of +# on the pb_data volume next to the database. The database and PocketBase's own +# backups stay on PB_DATA. Clients cannot tell the difference: a document has +# always been downloaded through the API Server (GET /api/documents/{id}/file), +# never from a storage URL. +# +# Before turning this on for a stack that already has uploads: PocketBase does +# NOT copy existing files into the bucket. See README.md. +# +# Traffic flow (browser): Web App BFF --/api--> API Server --> PocketBase. +# +# On first boot: +# • PocketBase upserts the superuser from POCKETBASE_ADMIN_* (create-if-missing). +# • PocketBase runs the bundled migrations: creates/reconciles every collection +# and seeds the baseline org + the superadmin@pilotvault.local app login. +# Both steps are idempotent, so restarts and upgrades are safe. + +services: + seaweedfs: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs + restart: unless-stopped + # One process, four roles: master, volume, filer and the S3 gateway. -dir is + # the only state it keeps. + command: server -dir=/data -s3 -master.volumeSizeLimitMB=1024 + environment: + # SeaweedFS falls back to these when started without an -s3.config file, + # and configuring one identity is what takes the S3 gateway out of its + # default allow-anyone mode. The same credentials PocketBase authenticates + # with below — one pair to set, in .env. + AWS_ACCESS_KEY_ID: "${PB_S3_ACCESS_KEY:?set PB_S3_ACCESS_KEY in .env}" + AWS_SECRET_ACCESS_KEY: "${PB_S3_SECRET:?set PB_S3_SECRET in .env}" + volumes: + # Named volume by default; set SEAWEED_DATA to a host path in .env for a + # bind mount, exactly as PB_DATA works. Back it up alongside PB_DATA — + # from here on the documents live here, not in the database volume. + - "${SEAWEED_DATA:-seaweed_data}:/data" + # No published port: the stack reaches the gateway over the compose network. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + seaweedfs-init: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-init + # Runs once and exits. PocketBase never issues a CreateBucket of its own and + # SeaweedFS will not conjure one on first upload, so something has to. + # Creating a bucket that already exists is a no-op, so every later boot + # passes straight through. + restart: "no" + depends_on: + seaweedfs: + condition: service_healthy + entrypoint: ["/bin/sh", "-c"] + # `|| true` so a restart is never blocked by the shell's exit status: this + # step is best-effort, and a gateway that is genuinely unreachable is + # reported by the API Server's own S3 check at boot, with the reason. + command: + - 'echo "s3.bucket.create -name ${PB_S3_BUCKET:-pilotvault}" | weed shell -master=seaweedfs:9333 || true' + + pocketbase: + image: "${PB_IMAGE:-10.2.1.10:5500/admin/pilotvault-pocketbase:latest}" + container_name: pilotvault-pocketbase + restart: unless-stopped + depends_on: + # PocketBase is the process that reads and writes the objects, so the + # gateway has to be serving before it is asked to store anything. + seaweedfs: + condition: service_healthy + environment: + # The superuser is created/updated on boot (the API Server authenticates + # with it). This is the only place the first superuser can be created — the + # REST API cannot bootstrap it. On the same boot PocketBase runs the bundled + # migrations: every collection, plus the baseline org and the + # superadmin@pilotvault.local app login. + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + volumes: + # Named volume by default; set PB_DATA to a host path in .env for a bind mount. + - "${PB_DATA:-pb_data}:/pb/pb_data" + ports: + # Bound to localhost by default — the admin UI (/_/) is reachable only on + # the host. Set PB_BIND=0.0.0.0 in .env to expose it on the network. + - "${PB_BIND:-127.0.0.1}:${PB_PORT:-8070}:8070" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + + api-server: + image: "${API_IMAGE:-10.2.1.10:5500/admin/pilotvault-api-server:latest}" + container_name: pilotvault-api-server + restart: unless-stopped + depends_on: + pocketbase: + condition: service_healthy + # The bucket must exist before the API Server points PocketBase at it. + seaweedfs-init: + condition: service_completed_successfully + environment: + API_ADDR: ":8080" + # Reach PocketBase by its service name on the internal network. Override + # POCKETBASE_URL in .env to point the API Server at a database outside + # this stack — that is also how you make a retarget done from the panel + # permanent, since the panel's change lasts only for the container's life. + POCKETBASE_URL: "${POCKETBASE_URL:-http://pocketbase:8070}" + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD}" + # Probed by the panel status page. This is a server-to-server call inside + # the compose network, so the default is the service name — plain + # localhost:8090 would resolve to this container itself. + WEBAPP_URL: "${WEBAPP_URL:-http://web-app:8090}" + # Same-origin requests go through the Web App BFF, so CORS is only needed + # if a browser ever calls the API Server directly. Default to the web origin. + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Plugin enable-state + config, on the api_data volume below. + PLUGINS_FILE: "/app/data/plugins.json" + # --- File storage -------------------------------------------------- + # The PilotVault API Server reads these on every boot and writes them into + # PocketBase's Files storage settings, idempotently. Only record files + # move — the document store's blobs. The database and PocketBase's own + # backups stay on pb_data. + PB_S3_ENABLED: "true" + PB_S3_BUCKET: "${PB_S3_BUCKET:-pilotvault}" + # The service name: a server-to-server call inside the compose network. + PB_S3_ENDPOINT: "http://seaweedfs:8333" + # SeaweedFS ignores the region; PocketBase insists on having one. + PB_S3_REGION: "${PB_S3_REGION:-us-east-1}" + PB_S3_ACCESS_KEY: "${PB_S3_ACCESS_KEY}" + PB_S3_SECRET: "${PB_S3_SECRET}" + # Path style, because a self-hosted gateway has no per-bucket DNS. + PB_S3_FORCE_PATH_STYLE: "true" + volumes: + # The one thing the API Server keeps on disk: plugins.json. Named volume + # by default; set API_DATA to a host path in .env for a bind mount (it + # must be writable by uid 10001, the image's runtime user). + - "${API_DATA:-api_data}:/app/data" + ports: + # Localhost-only by default (the Web App reaches it over the internal + # network). Set API_BIND=0.0.0.0 to expose the API panel — and the + # Fly App uplink, if drones connect here directly — on the network. + - "${API_BIND:-127.0.0.1}:${API_PORT:-8080}:8080" + healthcheck: + # Declared here rather than relying only on the image's HEALTHCHECK, so the + # depends_on gate below still works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + web-app: + image: "${WEB_IMAGE:-10.2.1.10:5500/admin/pilotvault-web-app:latest}" + container_name: pilotvault-web-app + restart: unless-stopped + depends_on: + # Wait for the API Server to be serving rather than merely started. + api-server: + condition: service_healthy + environment: + ADDR: ":8090" + # The BFF reverse-proxies /api/* to the API Server over the internal network. + API_BASE: "http://api-server:8080" + ports: + # The public front door. Bound on all interfaces so browsers can reach it. + - "${WEB_PORT:-8090}:8090" + healthcheck: + # The BFF has no health route of its own; the SPA index answers 200. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + +volumes: + pb_data: + api_data: + seaweed_data: diff --git a/Docker/docker-compose.prod.yml b/Docker/docker-compose.prod.yml index 472ee71..52f7d64 100644 --- a/Docker/docker-compose.prod.yml +++ b/Docker/docker-compose.prod.yml @@ -1,17 +1,19 @@ name: pilotvault -# Production PilotVault stack — pulls prebuilt images from the registry instead of -# building from source. Everything an operator needs to set lives in .env. +# Production PilotVault stack — pulls prebuilt images from the registry instead +# of building from source. Everything an operator needs to set lives in .env. # -# 1. cp .env.prod.example .env (then edit — secrets/ports/volumes/images) +# 1. cp .env.prod.example .env (then edit it — all secrets/ports/volumes) # 2. docker compose -f docker-compose.prod.yml pull # 3. docker compose -f docker-compose.prod.yml up -d # # Traffic flow (browser): Web App BFF --/api--> API Server --> PocketBase. # -# On first boot PocketBase upserts its superuser from POCKETBASE_ADMIN_* and runs -# the bundled migrations (create/reconcile collections + seed the baseline org and -# the superadmin@pilotvault.local login). Idempotent, so restarts/upgrades are safe. +# On first boot: +# • PocketBase upserts the superuser from POCKETBASE_ADMIN_* (create-if-missing). +# • PocketBase runs the bundled migrations: creates/reconciles every collection +# and seeds the baseline org + the superadmin@pilotvault.local app login. +# Both steps are idempotent, so restarts and upgrades are safe. services: pocketbase: @@ -19,14 +21,19 @@ services: container_name: pilotvault-pocketbase restart: unless-stopped environment: + # The superuser is created/updated on boot (the API Server authenticates + # with it). This is the only place the first superuser can be created — the + # REST API cannot bootstrap it. On the same boot PocketBase runs the bundled + # migrations: every collection, plus the baseline org and the + # superadmin@pilotvault.local app login. POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" volumes: # Named volume by default; set PB_DATA to a host path in .env for a bind mount. - "${PB_DATA:-pb_data}:/pb/pb_data" ports: - # Bound to localhost by default — the admin UI (/_/) is reachable only on the - # host. Set PB_BIND=0.0.0.0 in .env to expose it on the network. + # Bound to localhost by default — the admin UI (/_/) is reachable only on + # the host. Set PB_BIND=0.0.0.0 in .env to expose it on the network. - "${PB_BIND:-127.0.0.1}:${PB_PORT:-8070}:8070" healthcheck: test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health || exit 1"] @@ -44,27 +51,64 @@ services: condition: service_healthy environment: API_ADDR: ":8080" - POCKETBASE_URL: "http://pocketbase:8070" + # Reach PocketBase by its service name on the internal network. Override + # POCKETBASE_URL in .env to point the API Server at a database outside + # this stack — that is also how you make a retarget done from the panel + # permanent, since the panel's change lasts only for the container's life. + POCKETBASE_URL: "${POCKETBASE_URL:-http://pocketbase:8070}" POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL}" POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD}" + # Probed by the panel status page. This is a server-to-server call inside + # the compose network, so the default is the service name — plain + # localhost:8090 would resolve to this container itself. + WEBAPP_URL: "${WEBAPP_URL:-http://web-app:8090}" + # Same-origin requests go through the Web App BFF, so CORS is only needed + # if a browser ever calls the API Server directly. Default to the web origin. CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Plugin enable-state + config, on the api_data volume below. + PLUGINS_FILE: "/app/data/plugins.json" + volumes: + # The one thing the API Server keeps on disk: plugins.json. Named volume + # by default; set API_DATA to a host path in .env for a bind mount (it + # must be writable by uid 10001, the image's runtime user). + - "${API_DATA:-api_data}:/app/data" ports: # Localhost-only by default (the Web App reaches it over the internal - # network). Set API_BIND=0.0.0.0 to expose the API panel on the network. + # network). Set API_BIND=0.0.0.0 to expose the API panel — and the + # Fly App uplink, if drones connect here directly — on the network. - "${API_BIND:-127.0.0.1}:${API_PORT:-8080}:8080" + healthcheck: + # Declared here rather than relying only on the image's HEALTHCHECK, so the + # depends_on gate below still works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s web-app: image: "${WEB_IMAGE:-10.2.1.10:5500/admin/pilotvault-web-app:latest}" container_name: pilotvault-web-app restart: unless-stopped depends_on: - - api-server + # Wait for the API Server to be serving rather than merely started. + api-server: + condition: service_healthy environment: ADDR: ":8090" + # The BFF reverse-proxies /api/* to the API Server over the internal network. API_BASE: "http://api-server:8080" ports: # The public front door. Bound on all interfaces so browsers can reach it. - "${WEB_PORT:-8090}:8090" + healthcheck: + # The BFF has no health route of its own; the SPA index answers 200. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s volumes: pb_data: + api_data: diff --git a/Docker/docker-compose.s3.yml b/Docker/docker-compose.s3.yml new file mode 100644 index 0000000..d38a487 --- /dev/null +++ b/Docker/docker-compose.s3.yml @@ -0,0 +1,149 @@ +name: pilotvault + +# Full PilotVault stack, with external S3: PocketBase (database) + API Server + +# Web App, built from source, storing files in an S3 endpoint that already +# exists somewhere else. Self-contained — one file, nothing to layer. +# +# cp .env.s3.example .env (then edit it — PB_S3_* especially) +# docker compose -f docker-compose.s3.yml up -d --build +# +# Traffic flow (browser): Web App BFF --/api--> API Server --> PocketBase. +# +# This is docker-compose.yml plus storage: PocketBase keeps its record files — +# the document store's scans of pilot certificates, aircraft registrations, +# insurance and authorisations — in that bucket instead of on the pb_data volume +# next to the database. The database and PocketBase's own backups stay on +# pb_data. Clients cannot tell the difference: a document has always been +# downloaded through the API Server (GET /api/documents/{id}/file), never from a +# storage URL. +# +# The bucket must already exist, and nothing here runs the gateway. For a +# SeaweedFS that comes up with the stack, use docker-compose.seaweedfs.yml. +# +# Before turning this on for a stack that already has uploads: PocketBase does +# NOT copy existing files into the bucket. See README.md. + +services: + pocketbase: + build: + # Repo root — the Dockerfile bundles the migrations from "API Server/". + context: .. + dockerfile: Docker/pocketbase/Dockerfile + image: pilotvault-pocketbase + container_name: pilotvault-pocketbase + restart: unless-stopped + extra_hosts: + # Lets PB_S3_ENDPOINT name the Docker host as host.docker.internal. + # Harmless when the endpoint is somewhere else entirely. + - "host.docker.internal:host-gateway" + environment: + # The superuser is created/updated on boot (the API Server authenticates + # with it). This is the only place the first superuser can be created — the + # REST API cannot bootstrap it. On the same boot PocketBase runs the bundled + # migrations: every collection, plus the baseline org and the + # superadmin@pilotvault.local app login. + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + volumes: + # Named volume by default; set PB_DATA to a host path in .env for a bind mount. + - "${PB_DATA:-pb_data}:/pb/pb_data" + ports: + # Admin UI / API exposed on the host for management (http://host:8070/_/). + - "${PB_PORT:-8070}:8070" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + + api-server: + build: + context: "../API Server" + image: pilotvault-api-server + container_name: pilotvault-api-server + restart: unless-stopped + extra_hosts: + # Lets PB_S3_ENDPOINT name the Docker host as host.docker.internal. + # Harmless when the endpoint is somewhere else entirely. + - "host.docker.internal:host-gateway" + depends_on: + pocketbase: + condition: service_healthy + environment: + API_ADDR: ":8080" + # Reach PocketBase by its service name on the internal network. Override + # POCKETBASE_URL in .env to point the API Server at a database outside + # this stack — that is also how you make a retarget done from the panel + # permanent, since the panel's change lasts only for the container's life. + POCKETBASE_URL: "${POCKETBASE_URL:-http://pocketbase:8070}" + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD}" + # Probed by the panel status page. This is a server-to-server call inside + # the compose network, so the default is the service name — plain + # localhost:8090 would resolve to this container itself. + WEBAPP_URL: "${WEBAPP_URL:-http://web-app:8090}" + # Same-origin requests go through the Web App BFF, so CORS is only needed + # if a browser ever calls the API Server directly. Default to the web origin. + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Plugin enable-state + config, on the api_data volume below. + PLUGINS_FILE: "/app/data/plugins.json" + # --- File storage -------------------------------------------------- + # The PilotVault API Server reads these on every boot and writes them into + # PocketBase's Files storage settings, idempotently. Only record files + # move — the document store's blobs. The database and PocketBase's own + # backups stay on pb_data. The bucket must already exist: nothing here + # creates it. + PB_S3_ENABLED: "true" + PB_S3_BUCKET: "${PB_S3_BUCKET:-pilotvault}" + PB_S3_ENDPOINT: "${PB_S3_ENDPOINT:?set PB_S3_ENDPOINT in .env}" + PB_S3_REGION: "${PB_S3_REGION:-us-east-1}" + PB_S3_ACCESS_KEY: "${PB_S3_ACCESS_KEY:?set PB_S3_ACCESS_KEY in .env}" + PB_S3_SECRET: "${PB_S3_SECRET:?set PB_S3_SECRET in .env}" + # true for SeaweedFS and MinIO, false for AWS S3 proper. + PB_S3_FORCE_PATH_STYLE: "${PB_S3_FORCE_PATH_STYLE:-true}" + volumes: + # The one thing the API Server keeps on disk: plugins.json. Named volume + # by default; set API_DATA to a host path in .env for a bind mount (it + # must be writable by uid 10001, the image's runtime user). + - "${API_DATA:-api_data}:/app/data" + ports: + # Optional direct access to the API Server (and its panel at /); the Web + # App reaches it over the internal network, not this host port. + - "${API_PORT:-8080}:8080" + healthcheck: + # Declared here rather than relying only on the image's HEALTHCHECK, so the + # depends_on gate below still works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + web-app: + build: + context: "../Web App" + image: pilotvault-web-app + container_name: pilotvault-web-app + restart: unless-stopped + depends_on: + # Wait for the API Server to be serving rather than merely started. + api-server: + condition: service_healthy + environment: + ADDR: ":8090" + # The BFF reverse-proxies /api/* to the API Server over the internal network. + API_BASE: "http://api-server:8080" + ports: + - "${WEB_PORT:-8090}:8090" + healthcheck: + # The BFF has no health route of its own; the SPA index answers 200. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + +volumes: + pb_data: + api_data: diff --git a/Docker/docker-compose.seaweedfs.split.yml b/Docker/docker-compose.seaweedfs.split.yml new file mode 100644 index 0000000..f056ab8 --- /dev/null +++ b/Docker/docker-compose.seaweedfs.split.yml @@ -0,0 +1,350 @@ +name: pilotvault + +# Full PilotVault stack, with SeaweedFS split into its four roles: PocketBase +# (database) + API Server + Web App, built from source, plus master, volume, +# filer, S3 gateway and the SeaweedFS admin UI as separate containers. +# Self-contained — one file, nothing to layer. +# +# cp .env.seaweedfs.split.example .env (then edit it) +# docker compose -f docker-compose.seaweedfs.split.yml up -d --build +# +# Traffic flow (browser): Web App BFF --/api--> API Server --> PocketBase. +# +# This is docker-compose.seaweedfs.yml with the storage layer taken apart. `weed +# server -s3` runs master, volume, filer and gateway as goroutines in one +# process; here each is its own container. What that buys: +# +# • the admin UI (weed admin) — a cluster view, and Object Store → Users, +# where S3 identities are created and revoked without touching a file; +# • per-role restart, upgrade and Prometheus metrics; +# • room to add a second volume server later, on this host or another. +# +# What it costs: five containers instead of one, and five healthchecks to keep +# the boot order honest. If none of the above is wanted, use +# docker-compose.seaweedfs.yml — the S3 behaviour is identical. +# +# The on-disk layout is deliberately the same as the single-process file's: +# master, volume and filer share one /data mount, exactly as `weed server -dir` +# lays it out (master raft state, volume .dat/.idx, the filer's filerldb2/ — no +# filename overlap). So the two files are interchangeable on the same volume, +# with no migration either way. A *second* volume server would need its own. +# +# Before turning this on for a stack that already has uploads: PocketBase does +# NOT copy existing files into the bucket. See README.md. + +services: + # --- SeaweedFS: master ----------------------------------------------------- + # Keeps the volume/topology metadata and hands out file ids. -ip is the name + # the other roles are told to reach it by, so it must be the service name and + # not the container IP the process would otherwise detect. + seaweedfs-master: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-master + restart: unless-stopped + command: > + master -ip=seaweedfs-master -ip.bind=0.0.0.0 -mdir=/data + -volumeSizeLimitMB=1024 -metricsPort=9324 + volumes: + - seaweed_data:/data + ports: + # Master UI / API. Useful while developing; the admin UI below covers the + # same ground with a nicer face. + - "${SEAWEED_MASTER_PORT:-9333}:9333" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: volume server --------------------------------------------- + # Where the bytes actually land. -max=0 lets it size itself from free disk + # rather than the default cap of 8 volumes. + seaweedfs-volume: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-volume + restart: unless-stopped + command: > + volume -master=seaweedfs-master:9333 -ip=seaweedfs-volume -ip.bind=0.0.0.0 + -port=8080 -dir=/data -max=0 -metricsPort=9325 + depends_on: + seaweedfs-master: + condition: service_healthy + volumes: + - seaweed_data:/data + ports: + # This port serves file content by file id with NO authentication — the S3 + # credentials do not apply to it. Publish it only where you would be + # willing to publish the bucket itself. Mapped to 8081 on the host because + # 8080 there is the API Server. + - "${SEAWEED_VOLUME_PORT:-8081}:8080" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: filer ------------------------------------------------------ + # Gives the flat volume store a directory tree — buckets, object keys — and + # holds the S3 identities the admin UI writes. -defaultStoreDir is where its + # embedded leveldb goes; without it that would be the container's working + # directory, and the identities would not survive a recreate. + seaweedfs-filer: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-filer + restart: unless-stopped + command: > + filer -master=seaweedfs-master:9333 -ip=seaweedfs-filer -ip.bind=0.0.0.0 + -port=8888 -defaultStoreDir=/data -metricsPort=9326 + depends_on: + seaweedfs-volume: + condition: service_healthy + volumes: + - seaweed_data:/data + ports: + - "${SEAWEED_FILER_PORT:-8888}:8888" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8888/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: bucket and identity seed ---------------------------------- + # Runs once and exits, before the gateway starts. Two jobs: + # + # 1. create the bucket — PocketBase never issues a CreateBucket of its own; + # 2. write PocketBase's S3 identity into the filer's IAM store. + # + # (2) is why this stack does not set AWS_ACCESS_KEY_ID on the gateway, the way + # docker-compose.seaweedfs.yml does. Those env vars are the *lowest* priority + # credential source in SeaweedFS: they are read only while the filer's store + # is empty, so the first identity added in the admin UI would silently + # displace them and lock PocketBase out. Seeding the store the admin UI itself + # writes leaves one source of truth, and the key PocketBase uses appears under + # Object Store → Users like any other. + # + # Both commands update in place, so every later boot re-applies the values + # from .env and changes nothing else — which is also how a rotated + # PB_S3_SECRET reaches the gateway. + # + # The closing grep is the gate: an empty IAM store means the gateway would + # come up in its allow-anyone default, so this fails loudly instead and the + # gateway below never starts. No `|| true` here, deliberately. + seaweedfs-init: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-init + restart: "no" + depends_on: + seaweedfs-filer: + condition: service_healthy + environment: + # Passed as env and expanded by the shell inside the container, so the + # secret stays out of the container's argv. + PB_S3_BUCKET: "${PB_S3_BUCKET:-pilotvault}" + PB_S3_ACCESS_KEY: "${PB_S3_ACCESS_KEY:?set PB_S3_ACCESS_KEY in .env}" + PB_S3_SECRET: "${PB_S3_SECRET:?set PB_S3_SECRET in .env}" + entrypoint: ["/bin/sh", "-c"] + command: + - | + set -e + printf '%s\n' \ + "s3.bucket.create -name $$PB_S3_BUCKET" \ + "s3.configure -user pilotvault -access_key $$PB_S3_ACCESS_KEY -secret_key $$PB_S3_SECRET -actions Admin -apply" \ + | weed shell -master=seaweedfs-master:9333 -filer=seaweedfs-filer:8888 + echo "s3.configure" \ + | weed shell -master=seaweedfs-master:9333 -filer=seaweedfs-filer:8888 \ + | grep -q "$$PB_S3_ACCESS_KEY" + + # --- SeaweedFS: S3 gateway ------------------------------------------------- + # The endpoint PocketBase talks to. No -config file: with only -filer given, + # credentials come from the filer's IAM store, which is what lets the admin UI + # add and revoke identities without a restart. A config file would take + # priority over that store and make the admin UI's users inert. + seaweedfs-s3: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-s3 + restart: unless-stopped + command: > + s3 -filer=seaweedfs-filer:8888 -ip.bind=0.0.0.0 -port=8333 + -metricsPort=9327 + depends_on: + seaweedfs-filer: + condition: service_healthy + # Never serve before an identity exists — see seaweedfs-init above. + seaweedfs-init: + condition: service_completed_successfully + # No published port: the stack reaches the gateway over the compose network. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8333/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + # --- SeaweedFS: admin UI --------------------------------------------------- + # http://localhost:23646 — cluster topology, volumes, buckets, maintenance + # tasks, and Object Store → Users, where S3 access keys are minted and + # revoked. It finds the filer through the master, so -master is all it needs. + # + # An unauthenticated panel that can mint credentials for the bucket *is* the + # bucket, so the password is required rather than defaulted — weed leaves auth + # off entirely when it is empty. It is read from WEED_ADMIN_* rather than a + # flag, which keeps it off the process command line. -dataDir persists the + # session key and the maintenance-task settings. + seaweedfs-admin: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-admin + restart: unless-stopped + command: > + admin -port=23646 -master=seaweedfs-master:9333 -dataDir=/data + -metricsPort=9328 + depends_on: + seaweedfs-master: + condition: service_healthy + environment: + WEED_ADMIN_USER: "${SEAWEED_ADMIN_USER:-admin}" + WEED_ADMIN_PASSWORD: "${SEAWEED_ADMIN_PASSWORD:?set SEAWEED_ADMIN_PASSWORD in .env}" + volumes: + - seaweed_admin:/data + ports: + - "${SEAWEED_ADMIN_PORT:-23646}:23646" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:23646/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 15s + + pocketbase: + build: + # Repo root — the Dockerfile bundles the migrations from "API Server/". + context: .. + dockerfile: Docker/pocketbase/Dockerfile + image: pilotvault-pocketbase + container_name: pilotvault-pocketbase + restart: unless-stopped + depends_on: + # PocketBase is the process that reads and writes the objects, so the + # gateway has to be serving before it is asked to store anything. + seaweedfs-s3: + condition: service_healthy + environment: + # The superuser is created/updated on boot (the API Server authenticates + # with it). This is the only place the first superuser can be created — the + # REST API cannot bootstrap it. On the same boot PocketBase runs the bundled + # migrations: every collection, plus the baseline org and the + # superadmin@pilotvault.local app login. + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + volumes: + # Named volume by default; set PB_DATA to a host path in .env for a bind mount. + - "${PB_DATA:-pb_data}:/pb/pb_data" + ports: + # Admin UI / API exposed on the host for management (http://host:8070/_/). + - "${PB_PORT:-8070}:8070" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + + api-server: + build: + context: "../API Server" + image: pilotvault-api-server + container_name: pilotvault-api-server + restart: unless-stopped + depends_on: + pocketbase: + condition: service_healthy + # The bucket must exist before the API Server points PocketBase at it. + seaweedfs-init: + condition: service_completed_successfully + environment: + API_ADDR: ":8080" + # Reach PocketBase by its service name on the internal network. Override + # POCKETBASE_URL in .env to point the API Server at a database outside + # this stack — that is also how you make a retarget done from the panel + # permanent, since the panel's change lasts only for the container's life. + POCKETBASE_URL: "${POCKETBASE_URL:-http://pocketbase:8070}" + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD}" + # Probed by the panel status page. This is a server-to-server call inside + # the compose network, so the default is the service name — plain + # localhost:8090 would resolve to this container itself. + WEBAPP_URL: "${WEBAPP_URL:-http://web-app:8090}" + # Same-origin requests go through the Web App BFF, so CORS is only needed + # if a browser ever calls the API Server directly. Default to the web origin. + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Plugin enable-state + config, on the api_data volume below. + PLUGINS_FILE: "/app/data/plugins.json" + # --- File storage -------------------------------------------------- + # The PilotVault API Server reads these on every boot and writes them into + # PocketBase's Files storage settings, idempotently. Only record files + # move — the document store's blobs. The database and PocketBase's own + # backups stay on pb_data. + PB_S3_ENABLED: "true" + PB_S3_BUCKET: "${PB_S3_BUCKET:-pilotvault}" + # The gateway's service name: a server-to-server call inside the compose + # network. + PB_S3_ENDPOINT: "http://seaweedfs-s3:8333" + # SeaweedFS ignores the region; PocketBase insists on having one. + PB_S3_REGION: "${PB_S3_REGION:-us-east-1}" + PB_S3_ACCESS_KEY: "${PB_S3_ACCESS_KEY}" + PB_S3_SECRET: "${PB_S3_SECRET}" + # Path style, because a self-hosted gateway has no per-bucket DNS. + PB_S3_FORCE_PATH_STYLE: "true" + volumes: + # The one thing the API Server keeps on disk: plugins.json. Named volume + # by default; set API_DATA to a host path in .env for a bind mount (it + # must be writable by uid 10001, the image's runtime user). + - "${API_DATA:-api_data}:/app/data" + ports: + # Optional direct access to the API Server (and its panel at /); the Web + # App reaches it over the internal network, not this host port. + - "${API_PORT:-8080}:8080" + healthcheck: + # Declared here rather than relying only on the image's HEALTHCHECK, so the + # depends_on gate below still works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + web-app: + build: + context: "../Web App" + image: pilotvault-web-app + container_name: pilotvault-web-app + restart: unless-stopped + depends_on: + # Wait for the API Server to be serving rather than merely started. + api-server: + condition: service_healthy + environment: + ADDR: ":8090" + # The BFF reverse-proxies /api/* to the API Server over the internal network. + API_BASE: "http://api-server:8080" + ports: + - "${WEB_PORT:-8090}:8090" + healthcheck: + # The BFF has no health route of its own; the SPA index answers 200. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + +volumes: + pb_data: + api_data: + # Shared by master, volume and filer — the same layout `weed server -dir` + # writes, so this file and docker-compose.seaweedfs.yml can swap places on it. + seaweed_data: + # The admin UI's own session key and maintenance-task state. Small, and no + # part of the object store. + seaweed_admin: diff --git a/Docker/docker-compose.seaweedfs.yml b/Docker/docker-compose.seaweedfs.yml new file mode 100644 index 0000000..cec7370 --- /dev/null +++ b/Docker/docker-compose.seaweedfs.yml @@ -0,0 +1,191 @@ +name: pilotvault + +# Full PilotVault stack, with SeaweedFS: PocketBase (database) + API Server + +# Web App, built from source, plus an S3 object store. Self-contained — one +# file, nothing to layer. +# +# cp .env.seaweedfs.example .env (then edit it) +# docker compose -f docker-compose.seaweedfs.yml up -d --build +# +# Traffic flow (browser): Web App BFF --/api--> API Server --> PocketBase. +# +# This is docker-compose.yml plus storage: PocketBase keeps its record files — +# the document store's scans of pilot certificates, aircraft registrations, +# insurance and authorisations — in a SeaweedFS bucket instead of on the pb_data +# volume next to the database. The database and PocketBase's own backups stay on +# pb_data. Clients cannot tell the difference: a document has always been +# downloaded through the API Server (GET /api/documents/{id}/file), never from a +# storage URL. +# +# Before turning this on for a stack that already has uploads: PocketBase does +# NOT copy existing files into the bucket. See README.md. + +services: + seaweedfs: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs + restart: unless-stopped + # One process, four roles: master, volume, filer and the S3 gateway. -dir is + # the only state it keeps. + command: server -dir=/data -s3 -master.volumeSizeLimitMB=1024 + environment: + # SeaweedFS falls back to these when started without an -s3.config file, + # and configuring one identity is what takes the S3 gateway out of its + # default allow-anyone mode. The same credentials PocketBase authenticates + # with below — one pair to set, in .env. + AWS_ACCESS_KEY_ID: "${PB_S3_ACCESS_KEY:?set PB_S3_ACCESS_KEY in .env}" + AWS_SECRET_ACCESS_KEY: "${PB_S3_SECRET:?set PB_S3_SECRET in .env}" + volumes: + # From here on the documents live here, not on pb_data. + - seaweed_data:/data + # No published port: the stack reaches the gateway over the compose network. + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + seaweedfs-init: + image: "${SEAWEED_IMAGE:-chrislusf/seaweedfs:4.45}" + container_name: pilotvault-seaweedfs-init + # Runs once and exits. PocketBase never issues a CreateBucket of its own and + # SeaweedFS will not conjure one on first upload, so something has to. + # Creating a bucket that already exists is a no-op, so every later boot + # passes straight through. + restart: "no" + depends_on: + seaweedfs: + condition: service_healthy + entrypoint: ["/bin/sh", "-c"] + # `|| true` so a restart is never blocked by the shell's exit status: this + # step is best-effort, and a gateway that is genuinely unreachable is + # reported by the API Server's own S3 check at boot, with the reason. + command: + - 'echo "s3.bucket.create -name ${PB_S3_BUCKET:-pilotvault}" | weed shell -master=seaweedfs:9333 || true' + + pocketbase: + build: + # Repo root — the Dockerfile bundles the migrations from "API Server/". + context: .. + dockerfile: Docker/pocketbase/Dockerfile + image: pilotvault-pocketbase + container_name: pilotvault-pocketbase + restart: unless-stopped + depends_on: + # PocketBase is the process that reads and writes the objects, so the + # gateway has to be serving before it is asked to store anything. + seaweedfs: + condition: service_healthy + environment: + # The superuser is created/updated on boot (the API Server authenticates + # with it). This is the only place the first superuser can be created — the + # REST API cannot bootstrap it. On the same boot PocketBase runs the bundled + # migrations: every collection, plus the baseline org and the + # superadmin@pilotvault.local app login. + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + volumes: + # Named volume by default; set PB_DATA to a host path in .env for a bind mount. + - "${PB_DATA:-pb_data}:/pb/pb_data" + ports: + # Admin UI / API exposed on the host for management (http://host:8070/_/). + - "${PB_PORT:-8070}:8070" + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + + api-server: + build: + context: "../API Server" + image: pilotvault-api-server + container_name: pilotvault-api-server + restart: unless-stopped + depends_on: + pocketbase: + condition: service_healthy + # The bucket must exist before the API Server points PocketBase at it. + seaweedfs-init: + condition: service_completed_successfully + environment: + API_ADDR: ":8080" + # Reach PocketBase by its service name on the internal network. Override + # POCKETBASE_URL in .env to point the API Server at a database outside + # this stack — that is also how you make a retarget done from the panel + # permanent, since the panel's change lasts only for the container's life. + POCKETBASE_URL: "${POCKETBASE_URL:-http://pocketbase:8070}" + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD}" + # Probed by the panel status page. This is a server-to-server call inside + # the compose network, so the default is the service name — plain + # localhost:8090 would resolve to this container itself. + WEBAPP_URL: "${WEBAPP_URL:-http://web-app:8090}" + # Same-origin requests go through the Web App BFF, so CORS is only needed + # if a browser ever calls the API Server directly. Default to the web origin. + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Plugin enable-state + config, on the api_data volume below. + PLUGINS_FILE: "/app/data/plugins.json" + # --- File storage -------------------------------------------------- + # The PilotVault API Server reads these on every boot and writes them into + # PocketBase's Files storage settings, idempotently. Only record files + # move — the document store's blobs. The database and PocketBase's own + # backups stay on pb_data. + PB_S3_ENABLED: "true" + PB_S3_BUCKET: "${PB_S3_BUCKET:-pilotvault}" + # The service name: a server-to-server call inside the compose network. + PB_S3_ENDPOINT: "http://seaweedfs:8333" + # SeaweedFS ignores the region; PocketBase insists on having one. + PB_S3_REGION: "${PB_S3_REGION:-us-east-1}" + PB_S3_ACCESS_KEY: "${PB_S3_ACCESS_KEY}" + PB_S3_SECRET: "${PB_S3_SECRET}" + # Path style, because a self-hosted gateway has no per-bucket DNS. + PB_S3_FORCE_PATH_STYLE: "true" + volumes: + # The one thing the API Server keeps on disk: plugins.json. Named volume + # by default; set API_DATA to a host path in .env for a bind mount (it + # must be writable by uid 10001, the image's runtime user). + - "${API_DATA:-api_data}:/app/data" + ports: + # Optional direct access to the API Server (and its panel at /); the Web + # App reaches it over the internal network, not this host port. + - "${API_PORT:-8080}:8080" + healthcheck: + # Declared here rather than relying only on the image's HEALTHCHECK, so the + # depends_on gate below still works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s + + web-app: + build: + context: "../Web App" + image: pilotvault-web-app + container_name: pilotvault-web-app + restart: unless-stopped + depends_on: + # Wait for the API Server to be serving rather than merely started. + api-server: + condition: service_healthy + environment: + ADDR: ":8090" + # The BFF reverse-proxies /api/* to the API Server over the internal network. + API_BASE: "http://api-server:8080" + ports: + - "${WEB_PORT:-8090}:8090" + healthcheck: + # The BFF has no health route of its own; the SPA index answers 200. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s + +volumes: + pb_data: + api_data: + seaweed_data: diff --git a/Docker/docker-compose.yml b/Docker/docker-compose.yml index 6f7b0e1..bcc25e5 100644 --- a/Docker/docker-compose.yml +++ b/Docker/docker-compose.yml @@ -1,17 +1,8 @@ name: pilotvault -# Combined PilotVault stack: PocketBase (database) + API Server + Web App, built -# from source on a shared network. Run from this Docker/ folder: -# -# cp .env.example .env # then edit the secrets/ports -# docker compose up --build -# +# Full PilotVault stack: PocketBase (database) + API Server + Web App. # Traffic flow (browser): Web App BFF --/api--> API Server --> PocketBase. -# -# On first boot PocketBase upserts its superuser from POCKETBASE_ADMIN_* and runs -# the bundled JS migrations, which create/reconcile every collection and seed the -# baseline org + accounts (including the superadmin@pilotvault.local app login). -# Every step is idempotent, so restarts and upgrades are safe. +# Copy .env.example to .env and fill in the secrets before `docker compose up`. services: pocketbase: @@ -25,7 +16,9 @@ services: environment: # The superuser is created/updated on boot (the API Server authenticates # with it). This is the only place the first superuser can be created — the - # REST API cannot bootstrap it. + # REST API cannot bootstrap it. On the same boot PocketBase runs the bundled + # migrations: every collection, plus the baseline org and the + # superadmin@pilotvault.local app login. POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" volumes: @@ -40,8 +33,6 @@ services: timeout: 3s retries: 12 start_period: 10s - networks: - - pilotvault api-server: build: @@ -54,19 +45,39 @@ services: condition: service_healthy environment: API_ADDR: ":8080" - # Reach PocketBase by its service name on the shared network. - POCKETBASE_URL: "http://pocketbase:8070" + # Reach PocketBase by its service name on the internal network. Override + # POCKETBASE_URL in .env to point the API Server at a database outside + # this stack — that is also how you make a retarget done from the panel + # permanent, since the panel's change lasts only for the container's life. + POCKETBASE_URL: "${POCKETBASE_URL:-http://pocketbase:8070}" POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL}" POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD}" - # Same-origin requests go through the Web App BFF, so CORS is only needed if - # a browser ever calls the API Server directly. Default to the web origin. + # Probed by the panel status page. This is a server-to-server call inside + # the compose network, so the default is the service name — plain + # localhost:8090 would resolve to this container itself. + WEBAPP_URL: "${WEBAPP_URL:-http://web-app:8090}" + # Same-origin requests go through the Web App BFF, so CORS is only needed + # if a browser ever calls the API Server directly. Default to the web origin. CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Plugin enable-state + config, on the api_data volume below. + PLUGINS_FILE: "/app/data/plugins.json" + volumes: + # The one thing the API Server keeps on disk: plugins.json. Named volume + # by default; set API_DATA to a host path in .env for a bind mount (it + # must be writable by uid 10001, the image's runtime user). + - "${API_DATA:-api_data}:/app/data" ports: - # Optional direct access to the API Server (and its panel at /); the Web App - # reaches it over the internal network, not this host port. + # Optional direct access to the API Server (and its panel at /); the Web + # App reaches it over the internal network, not this host port. - "${API_PORT:-8080}:8080" - networks: - - pilotvault + healthcheck: + # Declared here rather than relying only on the image's HEALTHCHECK, so the + # depends_on gate below still works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 20s web-app: build: @@ -75,19 +86,23 @@ services: container_name: pilotvault-web-app restart: unless-stopped depends_on: - - api-server + # Wait for the API Server to be serving rather than merely started. + api-server: + condition: service_healthy environment: ADDR: ":8090" - # The BFF reverse-proxies /api/* to the API Server over the shared network. + # The BFF reverse-proxies /api/* to the API Server over the internal network. API_BASE: "http://api-server:8080" ports: - "${WEB_PORT:-8090}:8090" - networks: - - pilotvault - -networks: - pilotvault: - driver: bridge + healthcheck: + # The BFF has no health route of its own; the SPA index answers 200. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 10s + timeout: 3s + retries: 12 + start_period: 10s volumes: pb_data: + api_data: diff --git a/Docker/pocketbase/Dockerfile b/Docker/pocketbase/Dockerfile index f30e133..cef3c00 100644 --- a/Docker/pocketbase/Dockerfile +++ b/Docker/pocketbase/Dockerfile @@ -10,24 +10,34 @@ # so restarts and upgrades are safe. # # BUILD CONTEXT IS THE REPO ROOT (the migrations live under "API Server/"). It is -# built for you by Docker/docker-compose.yml; to build it by hand run from -# E:\VS Code Projects\PilotVault: +# built for you by the Docker/docker-compose*.yml files; to build it by hand run +# from E:\VS Code Projects\PilotVault: # # docker build -f Docker/pocketbase/Dockerfile -t pilotvault-pocketbase . -FROM alpine:latest +FROM alpine:3.24 -# Pin the version to match the rest of PilotVault; override with --build-arg. -# PB_ARCH is "amd64" (default) or "arm64" (e.g. Apple Silicon). -ARG PB_VERSION=0.22.21 -ARG PB_ARCH=amd64 +# Pinned so a rebuild months from now produces the same PocketBase. It must be +# v0.23 or newer: the migrations use the v0.23+ JSVM API and the entrypoint uses +# `superuser upsert`. Override to upgrade (--build-arg PB_VERSION=0.40.0); set it +# to empty to resolve the latest release at build time, which needs an +# unauthenticated GitHub API call (rate-limited to 60/hour per IP). +ARG PB_VERSION="0.39.11" +# Provided automatically by BuildKit (amd64 / arm64). +ARG TARGETARCH="amd64" RUN apk add --no-cache ca-certificates tzdata unzip wget WORKDIR /pb RUN set -eux; \ + ver="${PB_VERSION}"; \ + if [ -z "$ver" ]; then \ + ver="$(wget -qO- https://api.github.com/repos/pocketbase/pocketbase/releases/latest \ + | grep -o '"tag_name": *"v[^"]*"' | head -1 | sed -E 's/.*"v([^"]+)".*/\1/')"; \ + fi; \ + echo "Installing PocketBase v${ver} (${TARGETARCH})"; \ wget -q -O /tmp/pb.zip \ - "https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_${PB_ARCH}.zip"; \ + "https://github.com/pocketbase/pocketbase/releases/download/v${ver}/pocketbase_${ver}_linux_${TARGETARCH}.zip"; \ unzip /tmp/pb.zip -d /pb; \ rm /tmp/pb.zip