diff --git a/Docker-AIO/.env.example b/Docker-AIO/.env.example index e6b43d5..3101872 100644 --- a/Docker-AIO/.env.example +++ b/Docker-AIO/.env.example @@ -1,21 +1,47 @@ -# Copy to .env and fill in. Used by the Docker-AIO docker-compose.yml. +# Copy to .env and fill in. Used by docker-compose.yml. -# --- PocketBase superuser (also used by the API Server to authenticate) ------ +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on every boot; the API Server authenticates with the same +# credentials. No safe defaults. POCKETBASE_ADMIN_EMAIL=admin@dji.local -POCKETBASE_ADMIN_PASSWORD=djiadmin2026! +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. +# bundled PocketBase migrations on first boot — distinct from the superuser above. -# Allowed CORS origin(s) — "*" is convenient for a local demo. -CORS_ALLOW_ORIGINS=* +# --- 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) -------------------------- WEB_PORT=8090 -API_PORT=8080 PB_PORT=8070 +# API Server + its embedded web panel (served at the API root, +# http://host:8080/). +API_PORT=8080 + +# --- Build args (optional) --------------------------------------------------- +# PocketBase version. The Dockerfile already pins one; set this only to build a +# different version. Leaving it commented out keeps the pin (an empty value here +# is passed through as-is and would resolve the latest release at build time). +#PB_VERSION=0.39.11 + +# --- 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 is fixed to this +# container's own PocketBase and is not meant to be repointed.) +# WEBAPP_URL the Web App address the panel status page probes; the +# BFF serves it on port 8090 inside this container. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# WEBAPP_URL=http://127.0.0.1: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). +API_DATA=api_data diff --git a/Docker-AIO/.env.prod.example b/Docker-AIO/.env.prod.example index 6a02ce1..25551a3 100644 --- a/Docker-AIO/.env.prod.example +++ b/Docker-AIO/.env.prod.example @@ -3,26 +3,44 @@ # docker compose -f docker-compose.prod.yml pull # docker compose -f docker-compose.prod.yml up -d -# --- Registry image --------------------------------------------------------- +# --- Registry image ---------------------------------------------------------- +# Defaults to the internal registry; override to pin a tag or use a mirror. AIO_IMAGE=10.2.1.10:5500/admin/pilotvault-aio:latest # --- PocketBase superuser (required) ---------------------------------------- -# Created/updated on first boot. The API Server uses these to manage the database. +# Created/updated on every boot; the API Server authenticates with the same +# credentials. No safe defaults. 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. +# bundled PocketBase migrations on first boot — distinct from the superuser above. -# Allowed CORS origin(s) — match your public web URL / WEB_PORT. +# --- 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) -------------------------- WEB_PORT=8090 -API_PORT=8080 PB_PORT=8070 +API_PORT=8080 + +# --- 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 is fixed to this +# container's own PocketBase and is not meant to be repointed.) +# WEBAPP_URL the Web App address the panel status page probes; the +# BFF serves it on port 8090 inside this container. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# WEBAPP_URL=http://127.0.0.1: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). +API_DATA=api_data diff --git a/Docker-AIO/.env.prod.s3.example b/Docker-AIO/.env.prod.s3.example new file mode 100644 index 0000000..27cd7f6 --- /dev/null +++ b/Docker-AIO/.env.prod.s3.example @@ -0,0 +1,69 @@ +# PilotVault all-in-one — production 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 image ---------------------------------------------------------- +# Defaults to the internal registry; override to pin a tag or use a mirror. +AIO_IMAGE=10.2.1.10:5500/admin/pilotvault-aio:latest + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on every boot; the API Server authenticates with the same +# credentials. No safe defaults. +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 WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +WEB_PORT=8090 +PB_PORT=8070 +API_PORT=8080 + +# --- 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 is fixed to this +# container's own PocketBase and is not meant to be repointed.) +# WEBAPP_URL the Web App address the panel status page probes; the +# BFF serves it on port 8090 inside this container. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# WEBAPP_URL=http://127.0.0.1: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). +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-AIO/.env.prod.seaweedfs.example b/Docker-AIO/.env.prod.seaweedfs.example new file mode 100644 index 0000000..f4c0bbb --- /dev/null +++ b/Docker-AIO/.env.prod.seaweedfs.example @@ -0,0 +1,82 @@ +# PilotVault all-in-one — production config, SeaweedFS built into the same image (Dockerfile.seaweedfs). Copy to .env and fill in, then: +# docker compose -f docker-compose.prod.seaweedfs.yml build +# docker compose -f docker-compose.prod.seaweedfs.yml up -d +# The build needs the repo checkout; to deploy elsewhere, `push` after building +# and `pull` on the deploy host. + +# --- Image ------------------------------------------------------------------- +# The tag the build produces and `push`/`pull` use. Its own name, not +# pilotvault-aio: this image carries SeaweedFS and expects more volumes. +AIO_IMAGE=10.2.1.10:5500/admin/pilotvault-aio-seaweedfs:latest +# Build args, both pinned in the Dockerfile. Set to override at build time. +# PB_VERSION=0.39.11 +# SEAWEED_VERSION=4.45 + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on every boot; the API Server authenticates with the same +# credentials. No safe defaults. +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 WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +WEB_PORT=8090 +PB_PORT=8070 +API_PORT=8080 + +# --- 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 is fixed to this +# container's own PocketBase and is not meant to be repointed.) +# WEBAPP_URL the Web App address the panel status page probes; the +# BFF serves it on port 8090 inside this container. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# WEBAPP_URL=http://127.0.0.1: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). +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 container refuses to start without them. +PB_S3_ACCESS_KEY= +PB_S3_SECRET= +# The bucket. Created on first boot by PocketBase's program, before it serves. +PB_S3_BUCKET=pilotvault +# The endpoint, region and path style are fixed by the image — the gateway is +# inside the container at a loopback address that cannot change. + +# 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. It is mounted at /seaweed/data, the layout +# `weed server -dir` writes — the same one the .split. files use, so the two are +# interchangeable on it. +SEAWEED_DATA=seaweed_data +# The S3 gateway publishes no host port: PocketBase reaches it inside the +# container. + +# 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-AIO/.env.prod.seaweedfs.split.example b/Docker-AIO/.env.prod.seaweedfs.split.example new file mode 100644 index 0000000..a4118b9 --- /dev/null +++ b/Docker-AIO/.env.prod.seaweedfs.split.example @@ -0,0 +1,114 @@ +# PilotVault all-in-one — production config, SeaweedFS split into its roles and +# built into the same image (Dockerfile.seaweedfs.split). Copy to .env and fill in, then: +# docker compose -f docker-compose.prod.seaweedfs.split.yml build +# docker compose -f docker-compose.prod.seaweedfs.split.yml up -d +# The build needs the repo checkout; to deploy elsewhere, `push` after building +# and `pull` on the deploy host. + +# --- Image ------------------------------------------------------------------- +# The tag the build produces and `push`/`pull` use. Its own name, not +# pilotvault-aio: this image carries SeaweedFS and expects more volumes. +AIO_IMAGE=10.2.1.10:5500/admin/pilotvault-aio-seaweedfs-split:latest +# Build args, both pinned in the Dockerfile. Set to override at build time. +# PB_VERSION=0.39.11 +# SEAWEED_VERSION=4.45 + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on every boot; the API Server authenticates with the same +# credentials. No safe defaults. +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 WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +WEB_PORT=8090 +PB_PORT=8070 +API_PORT=8080 + +# --- 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 is fixed to this +# container's own PocketBase and is not meant to be repointed.) +# WEBAPP_URL the Web App address the panel status page probes; the +# BFF serves it on port 8090 inside this container. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# WEBAPP_URL=http://127.0.0.1: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). +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: the S3 gateway's program 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 container +# 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 S3 gateway's program. +PB_S3_BUCKET=pilotvault +# The endpoint, region and path style are fixed by the image — the gateway is +# inside the container at a loopback address that cannot change. + +# 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. +# +# Master, volume and filer share it (mounted at /seaweed/data), which is the +# layout `weed server -dir` 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 S3 gateway publishes no host port: PocketBase reaches it inside the +# container. The master, volume and filer listen on the container's loopback and +# 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. +# Reach them with `docker compose exec pilotvault wget -qO- +# http://127.0.0.1:9333/...` (volume 8081, filer 8888). + +# --- 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 — so the image refuses to +# start the panel at all without one, and the container stays unhealthy. +SEAWEED_ADMIN_USER=admin +SEAWEED_ADMIN_PASSWORD= +# Optional view-only login. +SEAWEED_ADMIN_READONLY_USER= +SEAWEED_ADMIN_READONLY_PASSWORD= +# Bound to localhost by default: storage plumbing, not one of the app's own +# panels. On a remote host that means unreachable — set 0.0.0.0 and put it +# behind a reverse proxy. +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-AIO/.env.s3.example b/Docker-AIO/.env.s3.example new file mode 100644 index 0000000..0e7826e --- /dev/null +++ b/Docker-AIO/.env.s3.example @@ -0,0 +1,70 @@ +# Copy to .env and fill in. Used by docker-compose.s3.yml. + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on every boot; the API Server authenticates with the same +# credentials. No safe defaults. +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 WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +WEB_PORT=8090 +PB_PORT=8070 +# API Server + its embedded web panel (served at the API root, +# http://host:8080/). +API_PORT=8080 + +# --- Build args (optional) --------------------------------------------------- +# PocketBase version. The Dockerfile already pins one; set this only to build a +# different version. Leaving it commented out keeps the pin (an empty value here +# is passed through as-is and would resolve the latest release at build time). +#PB_VERSION=0.39.11 + +# --- 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 is fixed to this +# container's own PocketBase and is not meant to be repointed.) +# WEBAPP_URL the Web App address the panel status page probes; the +# BFF serves it on port 8090 inside this container. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# WEBAPP_URL=http://127.0.0.1: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). +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-AIO/.env.seaweedfs.example b/Docker-AIO/.env.seaweedfs.example new file mode 100644 index 0000000..5b3b890 --- /dev/null +++ b/Docker-AIO/.env.seaweedfs.example @@ -0,0 +1,69 @@ +# Copy to .env and fill in. Used by docker-compose.seaweedfs.yml. + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on every boot; the API Server authenticates with the same +# credentials. No safe defaults. +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 WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +WEB_PORT=8090 +PB_PORT=8070 +# API Server + its embedded web panel (served at the API root, +# http://host:8080/). +API_PORT=8080 + +# --- Build args (optional) --------------------------------------------------- +# PocketBase version. The Dockerfile already pins one; set this only to build a +# different version. Leaving it commented out keeps the pin (an empty value here +# is passed through as-is and would resolve the latest release at build time). +#PB_VERSION=0.39.11 + +# --- 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 is fixed to this +# container's own PocketBase and is not meant to be repointed.) +# WEBAPP_URL the Web App address the panel status page probes; the +# BFF serves it on port 8090 inside this container. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# WEBAPP_URL=http://127.0.0.1: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). +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-AIO/.env.seaweedfs.split.example b/Docker-AIO/.env.seaweedfs.split.example new file mode 100644 index 0000000..e27ef6c --- /dev/null +++ b/Docker-AIO/.env.seaweedfs.split.example @@ -0,0 +1,95 @@ +# Copy to .env and fill in. Used by docker-compose.seaweedfs.split.yml. + +# --- PocketBase superuser (required) ---------------------------------------- +# Created/updated on every boot; the API Server authenticates with the same +# credentials. No safe defaults. +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 WEB_PORT / your public URL). +# Native apps are not subject to CORS. +CORS_ALLOW_ORIGINS=http://localhost:8090 + +# --- Host port mappings (optional; defaults shown) -------------------------- +WEB_PORT=8090 +PB_PORT=8070 +# API Server + its embedded web panel (served at the API root, +# http://host:8080/). +API_PORT=8080 + +# --- Build args (optional) --------------------------------------------------- +# PocketBase version. The Dockerfile already pins one; set this only to build a +# different version. Leaving it commented out keeps the pin (an empty value here +# is passed through as-is and would resolve the latest release at build time). +#PB_VERSION=0.39.11 + +# --- 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 is fixed to this +# container's own PocketBase and is not meant to be repointed.) +# WEBAPP_URL the Web App address the panel status page probes; the +# BFF serves it on port 8090 inside this container. +# CORS_ALLOW_ORIGINS browser origins allowed to call the API Server directly. +# WEBAPP_URL=http://127.0.0.1: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). +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-AIO/Dockerfile b/Docker-AIO/Dockerfile index 8c98f50..47f9dd2 100644 --- a/Docker-AIO/Dockerfile +++ b/Docker-AIO/Dockerfile @@ -1,30 +1,41 @@ # syntax=docker/dockerfile:1 # -# All-in-one PilotVault image: PocketBase + API Server + Web App in ONE container, -# supervised by supervisord. Convenience/demo image — for production run the three -# services separately (see Docker/docker-compose.yml). +# All-in-one PilotVault image: PocketBase + API Server + Web App (Go BFF) in ONE +# container, supervised by supervisord. For per-service restarts and upgrades +# run the three services separately instead (see ../Docker). # -# BUILD CONTEXT MUST BE THE REPO ROOT (this Dockerfile COPYs from "API Server/" -# and "Web App/"). From E:\VS Code Projects\PilotVault run: +# BUILD CONTEXT MUST BE THE REPO ROOT (this file COPYs from "API Server/" and +# "Web App/"). The root .dockerignore keeps the sibling apps out of it. From +# E:\VS Code Projects\PilotVault: # -# docker build -f Docker-AIO/Dockerfile -t pilotvault-aio . -# docker run -p 8090:8090 -p 8080:8080 -p 8070:8070 \ -# -v pilotvault_pb:/pb/pb_data pilotvault-aio +# docker build -f "Docker-AIO/Dockerfile" -t pilotvault-aio . # -# Internal ports (loopback-wired): PocketBase 8070, API Server 8080, Web App 8090. +# Run it (everything starts together): +# +# docker run -d --name pilotvault -p 8090:8090 -p 8080:8080 -p 8070:8070 \ +# -e POCKETBASE_ADMIN_EMAIL=admin@example.com \ +# -e POCKETBASE_ADMIN_PASSWORD=change-me-long-password \ +# -v pilotvault_pb:/pb/pb_data -v pilotvault_api:/app/data \ +# pilotvault-aio +# +# Then: web app on http://host:8090/, the API Server panel on http://host:8080/, +# PocketBase admin on http://host:8070/_/. On first boot PocketBase upserts its +# superuser and runs the bundled migrations (collections + the baseline org + +# the superadmin@pilotvault.local login). Every step is idempotent. # ============================================================================= -# Stage 1 — build the API Server's embedded Vue panel (-> internal/api/dist) +# Stage 1 — the API Server's embedded Vue panel (-> /internal/api/dist) # ============================================================================= -FROM node:22-alpine AS panel +FROM node:22-alpine3.24 AS panel WORKDIR /panel COPY ["API Server/panel/package.json", "API Server/panel/package-lock.json", "./"] RUN npm ci COPY ["API Server/panel/", "./"] +# vite.config.js writes the build to ../internal/api/dist. RUN npm run build # ============================================================================= -# Stage 2 — build the API Server static binary (go.mod pins go 1.26) +# Stage 2 — the API Server static binary (go.mod pins go 1.26) # ============================================================================= FROM golang:1.26-alpine AS api-build WORKDIR /src @@ -38,113 +49,172 @@ RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" \ -o /out/api-server ./cmd/server # ============================================================================= -# Stage 3 — build the Web App's embedded Vue UI (-> web/) +# Stage 3 — the Web App's Vue UI (Web App/web -> /server/dist) # ============================================================================= -FROM node:22-alpine AS ui -WORKDIR /ui -COPY ["Web App/ui/package.json", "Web App/ui/package-lock.json", "./"] +FROM node:22-alpine3.24 AS web +WORKDIR /web +COPY ["Web App/web/package.json", "Web App/web/package-lock.json", "./"] RUN npm ci -COPY ["Web App/ui/", "./"] +COPY ["Web App/web/", "./"] +# vite.config.js writes the build to ../server/dist. RUN npm run build # ============================================================================= -# Stage 4 — build the Web App static binary (go.mod pins go 1.24) +# Stage 4 — the Web App BFF static binary (Web App/server, go.mod pins go 1.24) # ============================================================================= FROM golang:1.24-alpine AS web-build WORKDIR /src -COPY ["Web App/go.mod", "Web App/go.sum", "./"] +COPY ["Web App/server/go.mod", "Web App/server/go.sum", "./"] RUN go mod download -COPY ["Web App/main.go", "Web App/bff.go", "./"] -# Overlay the freshly built UI so //go:embed web picks it up. -COPY --from=ui /web ./web +COPY ["Web App/server/", "./"] +# Overlay the freshly built UI so //go:embed all:dist picks it up. +COPY --from=web /server/dist ./dist RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" \ - -o /out/dji-web-app . + -o /out/web-app . # ============================================================================= -# Stage 5 — fetch the PocketBase binary +# Stage 5 — runtime: all three under supervisord # ============================================================================= -FROM alpine:latest AS pocketbase -# Override with --build-arg PB_VERSION=x.y.z / PB_ARCH=arm64 as needed. -ARG PB_VERSION=0.22.21 -ARG PB_ARCH=amd64 -RUN apk add --no-cache unzip wget ca-certificates \ - && wget -O /tmp/pb.zip \ - "https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_${PB_ARCH}.zip" \ - && unzip /tmp/pb.zip -d /pb \ - && rm /tmp/pb.zip +FROM alpine:3.24 -# ============================================================================= -# Stage 6 — runtime: alpine:latest running all three under supervisord -# ============================================================================= -FROM alpine:latest -RUN apk add --no-cache ca-certificates tzdata supervisor +# Pinned so a rebuild months from now produces the same PocketBase. It must be +# v0.23 or newer: the bundled migrations use the v0.23+ JSVM API and the +# pocketbase program 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" -WORKDIR /app -COPY --from=api-build /out/api-server ./api-server -COPY --from=web-build /out/dji-web-app ./dji-web-app -COPY --from=pocketbase /pb/pocketbase ./pocketbase -# JS migrations (schema + seed accounts) applied by PocketBase on first serve. +RUN apk add --no-cache ca-certificates tzdata unzip wget supervisor + +# Unprivileged account for every process; supervisord drops to it. Nothing here +# binds a port below 1024, so nothing needs to stay root. +RUN addgroup -S app && adduser -S -G app app + +# PocketBase from the official release (pinned via PB_VERSION, else latest). +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${ver}/pocketbase_${ver}_linux_${TARGETARCH}.zip"; \ + unzip /tmp/pb.zip -d /pb; \ + rm /tmp/pb.zip + +# JS migrations (schema + seed accounts), applied by PocketBase on every serve. COPY ["API Server/pocketbase/pb_migrations/", "/pb/pb_migrations/"] -# --- Runtime configuration (loopback-wired between the three services) --------- -# API Server reads API_ADDR / POCKETBASE_URL / CORS_ALLOW_ORIGINS / POCKETBASE_ADMIN_* -# Web App reads ADDR / API_BASE -# NOTE: these bundle default credentials for convenience — override at `docker run`. -ENV API_ADDR=":8080" \ - POCKETBASE_URL="http://127.0.0.1:8070" \ - CORS_ALLOW_ORIGINS="*" \ - POCKETBASE_ADMIN_EMAIL="admin@dji.local" \ - POCKETBASE_ADMIN_PASSWORD="djiadmin2026!" \ - ADDR=":8090" \ - API_BASE="http://127.0.0.1:8080" +# The two Go binaries. +COPY --from=api-build /out/api-server /usr/local/bin/api-server +COPY --from=web-build /out/web-app /usr/local/bin/web-app -# --- supervisord: PocketBase first, then API Server, then Web App -------------- -RUN cat > /etc/supervisord.conf <<'EOF' +# supervisord runs the three processes and keeps them alive. Priorities only +# order the launches; readiness is the `until wget` loop in front of each +# program that needs another one up: PocketBase → API Server → Web App. +RUN cat > /etc/supervisord.conf <<'SUPERVISOR' [supervisord] nodaemon=true user=root +pidfile=/run/supervisord.pid logfile=/dev/null logfile_maxbytes=0 -pidfile=/run/supervisord.pid +; PocketBase: upsert the superuser (idempotent), then serve with the bundled +; migrations. Runs as the unprivileged app user, which owns /pb/pb_data. [program:pocketbase] +directory=/app +user=app +command=/bin/sh -c '/pb/pocketbase superuser upsert "$POCKETBASE_ADMIN_EMAIL" "$POCKETBASE_ADMIN_PASSWORD" --dir=/pb/pb_data 2>/dev/null || echo "warning: superuser upsert failed" >&2; exec /pb/pocketbase serve --http=0.0.0.0:8070 --dir=/pb/pb_data --migrationsDir=/pb/pb_migrations' priority=10 -directory=/pb -# Ensure the service-account superuser exists, then serve on the internal port. -command=/bin/sh -c "/app/pocketbase superuser upsert \"$POCKETBASE_ADMIN_EMAIL\" \"$POCKETBASE_ADMIN_PASSWORD\" --dir=/pb/pb_data ; exec /app/pocketbase serve --http=0.0.0.0:8070 --dir=/pb/pb_data --migrationsDir=/pb/pb_migrations" +autostart=true autorestart=true -startsecs=3 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 +; API Server: wait for PocketBase to be healthy, then start. It keeps one +; file on disk, plugins.json, on the /app/data volume (PLUGINS_FILE). [program:api-server] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8070/api/health >/dev/null 2>&1; do echo "waiting for pocketbase..."; sleep 1; done; exec /usr/local/bin/api-server' priority=20 -directory=/app -command=/app/api-server +autostart=true autorestart=true -startsecs=3 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 +; Web App: the Go BFF serving the UI on :8090 and proxying /api/* to the API +; Server on loopback. Waits for the API Server so the first page load works. [program:web-app] -priority=30 directory=/app -command=/app/dji-web-app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1; do echo "waiting for api-server..."; sleep 1; done; exec /usr/local/bin/web-app' +priority=30 +autostart=true autorestart=true -startsecs=3 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 -EOF +SUPERVISOR -# PocketBase data (SQLite). Mount a volume here to persist across restarts. -VOLUME ["/pb/pb_data"] +# The entrypoint stays root only long enough to make the data volumes writable +# by the app user, then hands off to supervisord. The chown matters for a host +# bind mount, which arrives owned by root rather than inheriting the image's +# owner. +RUN cat > /entrypoint.sh <<'ENTRY' +#!/bin/sh +set -e +for dir in /pb/pb_data /app/data; do + mkdir -p "$dir" + if [ "$(stat -c %U "$dir" 2>/dev/null)" != "app" ]; then + echo "entrypoint: taking ownership of $dir" + chown -R app:app "$dir" + fi +done +exec supervisord -c /etc/supervisord.conf +ENTRY +RUN chmod +x /entrypoint.sh +# Everything is local to this container. WEBAPP_URL is what the panel status +# page probes. +ENV API_ADDR=:8080 \ + POCKETBASE_URL=http://127.0.0.1:8070 \ + CORS_ALLOW_ORIGINS=http://localhost:8090 \ + WEBAPP_URL=http://127.0.0.1:8090 \ + PLUGINS_FILE=/app/data/plugins.json \ + ADDR=:8090 \ + API_BASE=http://127.0.0.1:8080 + +# Required at runtime (no safe defaults): POCKETBASE_ADMIN_EMAIL, +# POCKETBASE_ADMIN_PASSWORD. Pass them with `docker run -e ...`. + +# Two volumes. /pb/pb_data: the database, the uploaded document blobs and +# PocketBase's own backups. /app/data: the API Server's plugins.json. Both +# pre-created and owned by app so a fresh named volume inherits that ownership. +RUN mkdir -p /pb/pb_data /app/data && chown -R app:app /pb /app +VOLUME ["/pb/pb_data", "/app/data"] +WORKDIR /app +# 8090 = Web App, 8080 = API Server + embedded panel, 8070 = PocketBase admin. EXPOSE 8090 8080 8070 -ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] +# All three processes must answer, so a wedged component shows up in `docker ps` +# instead of a container that looks up while part of it is dead. start-period +# covers the first-boot migrations on a cold database. +HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \ + CMD wget -qO- http://127.0.0.1:8070/api/health >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8090/ >/dev/null 2>&1 \ + || exit 1 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/Docker-AIO/Dockerfile.seaweedfs b/Docker-AIO/Dockerfile.seaweedfs new file mode 100644 index 0000000..4ccee6a --- /dev/null +++ b/Docker-AIO/Dockerfile.seaweedfs @@ -0,0 +1,305 @@ +# syntax=docker/dockerfile:1 +# +# All-in-one PilotVault image WITH the object store inside: PocketBase + API +# Server + Web App, plus SeaweedFS as one `weed server -s3` process — master, +# volume, filer and S3 gateway as goroutines — under supervisord in the same +# container. +# +# This is Dockerfile with the SeaweedFS containers of +# docker-compose.seaweedfs.yml folded in. What it costs: a new SeaweedFS +# means a rebuild (--build-arg SEAWEED_VERSION). For per-role restart, metrics +# and the admin UI, see Dockerfile.seaweedfs.split. +# +# BUILD CONTEXT MUST BE THE REPO ROOT (this file COPYs from "API Server/" and +# "Web App/"). The root .dockerignore keeps the sibling apps out of it. From +# E:\VS Code Projects\PilotVault: +# +# docker build -f "Docker-AIO/Dockerfile.seaweedfs" -t pilotvault-aio-seaweedfs . +# +# Run it (everything starts together): +# +# docker run -d --name pilotvault -p 8090:8090 -p 8080:8080 -p 8070:8070 \ +# -e POCKETBASE_ADMIN_EMAIL=admin@example.com \ +# -e POCKETBASE_ADMIN_PASSWORD=change-me-long-password \ +# -e PB_S3_ACCESS_KEY=pilotvault -e PB_S3_SECRET=change-me \ +# -v pilotvault_pb:/pb/pb_data -v pilotvault_api:/app/data \ +# -v pilotvault_seaweed:/seaweed/data \ +# pilotvault-aio-seaweedfs +# +# Then: web app on http://host:8090/ and PocketBase admin on http://host:8070/_/. +# On first boot PocketBase's program creates the bucket, PocketBase runs its +# migrations, and the API Server points PocketBase's file storage at the bucket. +# +# Port map inside the container (only 8090, 8080 and 8070 are meant to be +# published): +# +# 8070 PocketBase +# 8080 API Server ← which is why the volume server is NOT on its +# 8081 SeaweedFS volume usual 8080 here +# 8090 Web App +# 8333 SeaweedFS S3 gateway (PocketBase's endpoint) +# 8888 SeaweedFS filer +# 9333 SeaweedFS master + +# SeaweedFS release to bake in, pinned like PB_VERSION so a rebuild months from +# now brings up the same one. Same tag the compose SeaweedFS files run as +# SEAWEED_IMAGE. Override with --build-arg SEAWEED_VERSION=... to upgrade. +ARG SEAWEED_VERSION="4.45" + +# ============================================================================= +# Stage 1 — the API Server's embedded Vue panel (-> /internal/api/dist) +# ============================================================================= +FROM node:22-alpine3.24 AS panel +WORKDIR /panel +COPY ["API Server/panel/package.json", "API Server/panel/package-lock.json", "./"] +RUN npm ci +COPY ["API Server/panel/", "./"] +# vite.config.js writes the build to ../internal/api/dist. +RUN npm run build + +# ============================================================================= +# Stage 2 — the API Server static binary (go.mod pins go 1.26) +# ============================================================================= +FROM golang:1.26-alpine AS api-build +WORKDIR /src +COPY ["API Server/go.mod", "API Server/go.sum", "./"] +RUN go mod download +COPY ["API Server/cmd/", "./cmd/"] +COPY ["API Server/internal/", "./internal/"] +# Overlay the freshly built panel so //go:embed all:dist picks it up. +COPY --from=panel /internal/api/dist ./internal/api/dist +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" \ + -o /out/api-server ./cmd/server + +# ============================================================================= +# Stage 3 — the Web App's Vue UI (Web App/web -> /server/dist) +# ============================================================================= +FROM node:22-alpine3.24 AS web +WORKDIR /web +COPY ["Web App/web/package.json", "Web App/web/package-lock.json", "./"] +RUN npm ci +COPY ["Web App/web/", "./"] +# vite.config.js writes the build to ../server/dist. +RUN npm run build + +# ============================================================================= +# Stage 4 — the Web App BFF static binary (Web App/server, go.mod pins go 1.24) +# ============================================================================= +FROM golang:1.24-alpine AS web-build +WORKDIR /src +COPY ["Web App/server/go.mod", "Web App/server/go.sum", "./"] +RUN go mod download +COPY ["Web App/server/", "./"] +# Overlay the freshly built UI so //go:embed all:dist picks it up. +COPY --from=web /server/dist ./dist +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" \ + -o /out/web-app . + +# ============================================================================= +# Stage 5 — SeaweedFS: the one static binary from the official image. +# SEAWEED_VERSION is declared at the top of the file: an ARG used in a FROM has +# to be global, and one declared here would expand to nothing. +# ============================================================================= +FROM chrislusf/seaweedfs:${SEAWEED_VERSION} AS seaweed + +# ============================================================================= +# Stage 6 — runtime: everything under supervisord +# ============================================================================= +FROM alpine:3.24 + +# Pinned so a rebuild months from now produces the same PocketBase. It must be +# v0.23 or newer: the bundled migrations use the v0.23+ JSVM API and the +# pocketbase program 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 supervisor + +# Unprivileged account for every process; supervisord drops to it. Nothing here +# binds a port below 1024, so nothing needs to stay root. +RUN addgroup -S app && adduser -S -G app app + +# PocketBase from the official release (pinned via PB_VERSION, else latest). +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${ver}/pocketbase_${ver}_linux_${TARGETARCH}.zip"; \ + unzip /tmp/pb.zip -d /pb; \ + rm /tmp/pb.zip + +# JS migrations (schema + seed accounts), applied by PocketBase on every serve. +COPY ["API Server/pocketbase/pb_migrations/", "/pb/pb_migrations/"] + +# The two Go binaries. +COPY --from=api-build /out/api-server /usr/local/bin/api-server +COPY --from=web-build /out/web-app /usr/local/bin/web-app +COPY --from=seaweed /usr/bin/weed /usr/local/bin/weed + +# supervisord runs the five processes and keeps them alive. Priorities only +# order the launches; readiness is the `until wget` loop in front of each +# program that needs another one up, the same chain the compose file spells out +# with depends_on + healthchecks: SeaweedFS → bucket → PocketBase → API Server +# → Web App. +RUN cat > /etc/supervisord.conf <<'SUPERVISOR' +[supervisord] +nodaemon=true +user=root +pidfile=/run/supervisord.pid +logfile=/dev/null +logfile_maxbytes=0 + +; SeaweedFS: one process, four roles — master, volume, filer and the S3 +; gateway. -dir is the only state it keeps. Every role advertises and binds +; 127.0.0.1: PocketBase is the only client and lives in here, and the volume +; server (on 8081 because 8080 is the API Server) serves file content by id +; with no authentication at all. +; +; SeaweedFS falls back to AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY when started +; without an -s3.config file, and configuring one identity is what takes the +; gateway out of its default allow-anyone mode. They are the PB_S3_* pair +; PocketBase authenticates with, mapped here so there is one pair to set — and +; an empty pair means no gateway rather than an open one. +[program:seaweedfs] +directory=/app +user=app +command=/bin/sh -c 'if [ -z "$PB_S3_ACCESS_KEY" ] || [ -z "$PB_S3_SECRET" ]; then echo "seaweedfs: PB_S3_ACCESS_KEY and PB_S3_SECRET are required; refusing to start an unauthenticated gateway" >&2; exit 1; fi; export AWS_ACCESS_KEY_ID="$PB_S3_ACCESS_KEY" AWS_SECRET_ACCESS_KEY="$PB_S3_SECRET"; exec /usr/local/bin/weed server -dir=/seaweed/data -ip=127.0.0.1 -ip.bind=127.0.0.1 -volume.port=8081 -s3 -master.volumeSizeLimitMB=1024' +priority=1 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; PocketBase: wait for the S3 gateway — PocketBase is the process that reads +; and writes the objects. Then create the bucket: PocketBase never issues a +; CreateBucket of its own and SeaweedFS will not conjure one on first upload. +; Creating a bucket that already exists is a no-op, and `|| true` keeps a +; restart from being blocked — a genuinely broken gateway is reported by the +; API Server's own S3 check at boot. Then upsert the superuser and serve with +; the bundled migrations. +[program:pocketbase] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8333/healthz >/dev/null 2>&1; do echo "waiting for seaweedfs..."; sleep 1; done; echo "s3.bucket.create -name $PB_S3_BUCKET" | /usr/local/bin/weed shell -master=127.0.0.1:9333 || true; /pb/pocketbase superuser upsert "$POCKETBASE_ADMIN_EMAIL" "$POCKETBASE_ADMIN_PASSWORD" --dir=/pb/pb_data 2>/dev/null || echo "warning: superuser upsert failed" >&2; exec /pb/pocketbase serve --http=0.0.0.0:8070 --dir=/pb/pb_data --migrationsDir=/pb/pb_migrations' +priority=10 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; API Server: wait for PocketBase to be healthy, then start. On boot it +; points PocketBase's file storage at the bucket (PB_S3_*) and asks it to +; prove the gateway is reachable. It keeps one file on disk, plugins.json, on +; the /app/data volume (PLUGINS_FILE). +[program:api-server] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8070/api/health >/dev/null 2>&1; do echo "waiting for pocketbase..."; sleep 1; done; exec /usr/local/bin/api-server' +priority=20 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; Web App: the Go BFF serving the UI on :8090 and proxying /api/* to the API +; Server on loopback. Waits for the API Server so the first page load works. +[program:web-app] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1; do echo "waiting for api-server..."; sleep 1; done; exec /usr/local/bin/web-app' +priority=30 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +SUPERVISOR + +# The entrypoint stays root only long enough to make the data volumes writable +# by the app user, then hands off to supervisord. The chown matters for a host +# bind mount, which arrives owned by root rather than inheriting the image's +# owner. +RUN cat > /entrypoint.sh <<'ENTRY' +#!/bin/sh +set -e +for dir in /pb/pb_data /app/data /seaweed/data; do + mkdir -p "$dir" + if [ "$(stat -c %U "$dir" 2>/dev/null)" != "app" ]; then + echo "entrypoint: taking ownership of $dir" + chown -R app:app "$dir" + fi +done +exec supervisord -c /etc/supervisord.conf +ENTRY +RUN chmod +x /entrypoint.sh + +# Everything is local to this container. WEBAPP_URL is what the panel status +# page probes. +# +# File storage is on by construction: the gateway is in this image, at a fixed +# loopback address, path style because a self-hosted gateway has no per-bucket +# DNS. The region is a formality SeaweedFS ignores and PocketBase insists on. +# supervisord passes these through to the API Server, which writes them into +# PocketBase's settings on every boot. Only record files move — the document +# store's blobs; the database and PocketBase's own backups stay on /pb/pb_data. +ENV API_ADDR=:8080 \ + POCKETBASE_URL=http://127.0.0.1:8070 \ + CORS_ALLOW_ORIGINS=http://localhost:8090 \ + WEBAPP_URL=http://127.0.0.1:8090 \ + PLUGINS_FILE=/app/data/plugins.json \ + ADDR=:8090 \ + API_BASE=http://127.0.0.1:8080 \ + PB_S3_ENABLED=true \ + PB_S3_ENDPOINT=http://127.0.0.1:8333 \ + PB_S3_BUCKET=pilotvault \ + PB_S3_REGION=us-east-1 \ + PB_S3_FORCE_PATH_STYLE=true + +# Required at runtime (no safe defaults): POCKETBASE_ADMIN_EMAIL, +# POCKETBASE_ADMIN_PASSWORD; PB_S3_ACCESS_KEY, PB_S3_SECRET (the gateway's single +# identity AND what PocketBase authenticates with — the gateway refuses to start +# without them). Pass them with `docker run -e ...`. + +# Three volumes. /pb/pb_data: the database, documents uploaded before S3 was on, +# PocketBase's own backups. /app/data: the API Server's plugins.json. +# /seaweed/data: everything SeaweedFS keeps, in the layout `weed server -dir` +# writes — the same one the split image's master, volume and filer share, so a +# SEAWEED_DATA volume from any of the SeaweedFS compose files mounts here +# unchanged, and vice versa. All pre-created and owned by app so a fresh named +# volume inherits that ownership. +RUN mkdir -p /pb/pb_data /app/data /seaweed/data \ + && chown -R app:app /pb /app /seaweed +VOLUME ["/pb/pb_data", "/app/data", "/seaweed/data"] +WORKDIR /app +# 8090 = Web App, 8080 = API Server + embedded panel, 8070 = PocketBase admin. +# Nothing of SeaweedFS is exposed: it binds loopback only. +EXPOSE 8090 8080 8070 + +# Every process must answer, so a wedged component shows up in `docker ps` +# instead of a container that looks up while part of it is dead. start-period +# covers SeaweedFS coming up plus the first-boot migrations on a cold database. +HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \ + CMD wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8333/healthz >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8070/api/health >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8090/ >/dev/null 2>&1 \ + || exit 1 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/Docker-AIO/Dockerfile.seaweedfs.split b/Docker-AIO/Dockerfile.seaweedfs.split new file mode 100644 index 0000000..051b7e4 --- /dev/null +++ b/Docker-AIO/Dockerfile.seaweedfs.split @@ -0,0 +1,405 @@ +# syntax=docker/dockerfile:1 +# +# All-in-one PilotVault image WITH the object store inside: PocketBase + API +# Server + Web App, plus SeaweedFS split into its roles — master, volume, filer, +# S3 gateway and the admin UI — each its own supervisord program in the same +# container. +# +# This is Dockerfile with the SeaweedFS containers of +# docker-compose.seaweedfs.split.yml folded in. What the split still buys in +# here: per-role restart under supervisord, per-role metrics ports, and the +# admin UI, where S3 identities are minted and revoked. What it costs: a new +# SeaweedFS means a rebuild (--build-arg SEAWEED_VERSION). +# +# BUILD CONTEXT MUST BE THE REPO ROOT (this file COPYs from "API Server/" and +# "Web App/"). The root .dockerignore keeps the sibling apps out of it. From +# E:\VS Code Projects\PilotVault: +# +# docker build -f "Docker-AIO/Dockerfile.seaweedfs.split" -t pilotvault-aio-seaweedfs-split . +# +# Run it (everything starts together): +# +# docker run -d --name pilotvault -p 8090:8090 -p 8080:8080 -p 8070:8070 \ +# -e POCKETBASE_ADMIN_EMAIL=admin@example.com \ +# -e POCKETBASE_ADMIN_PASSWORD=change-me-long-password \ +# -p 127.0.0.1:23646:23646 \ +# -e PB_S3_ACCESS_KEY=pilotvault -e PB_S3_SECRET=change-me \ +# -e WEED_ADMIN_PASSWORD=change-me \ +# -v pilotvault_pb:/pb/pb_data -v pilotvault_api:/app/data \ +# -v pilotvault_seaweed:/seaweed/data \ +# -v pilotvault_seaweed_admin:/seaweed/admin \ +# pilotvault-aio-seaweedfs-split +# +# Then: web app on http://host:8090/, PocketBase admin on http://host:8070/_/, +# and the SeaweedFS admin UI on http://127.0.0.1:23646/. On first boot the S3 +# gateway's program creates the bucket and seeds PocketBase's identity, +# PocketBase runs its migrations, and the API Server points PocketBase's file +# storage at the bucket. +# +# Port map inside the container (only 8090, 8080, 8070 and 23646 are meant to +# be published; every SeaweedFS role but the admin UI binds loopback): +# +# 8070 PocketBase +# 8080 API Server ← which is why the volume server is NOT on its +# 8081 SeaweedFS volume usual 8080 here +# 8090 Web App +# 8333 SeaweedFS S3 gateway (PocketBase's endpoint) +# 8888 SeaweedFS filer +# 9333 SeaweedFS master +# 23646 SeaweedFS admin UI (publish on loopback, behind a proxy if remote) + +# SeaweedFS release to bake in, pinned like PB_VERSION so a rebuild months from +# now brings up the same one. Same tag the compose SeaweedFS files run as +# SEAWEED_IMAGE. Override with --build-arg SEAWEED_VERSION=... to upgrade. +ARG SEAWEED_VERSION="4.45" + +# ============================================================================= +# Stage 1 — the API Server's embedded Vue panel (-> /internal/api/dist) +# ============================================================================= +FROM node:22-alpine3.24 AS panel +WORKDIR /panel +COPY ["API Server/panel/package.json", "API Server/panel/package-lock.json", "./"] +RUN npm ci +COPY ["API Server/panel/", "./"] +# vite.config.js writes the build to ../internal/api/dist. +RUN npm run build + +# ============================================================================= +# Stage 2 — the API Server static binary (go.mod pins go 1.26) +# ============================================================================= +FROM golang:1.26-alpine AS api-build +WORKDIR /src +COPY ["API Server/go.mod", "API Server/go.sum", "./"] +RUN go mod download +COPY ["API Server/cmd/", "./cmd/"] +COPY ["API Server/internal/", "./internal/"] +# Overlay the freshly built panel so //go:embed all:dist picks it up. +COPY --from=panel /internal/api/dist ./internal/api/dist +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" \ + -o /out/api-server ./cmd/server + +# ============================================================================= +# Stage 3 — the Web App's Vue UI (Web App/web -> /server/dist) +# ============================================================================= +FROM node:22-alpine3.24 AS web +WORKDIR /web +COPY ["Web App/web/package.json", "Web App/web/package-lock.json", "./"] +RUN npm ci +COPY ["Web App/web/", "./"] +# vite.config.js writes the build to ../server/dist. +RUN npm run build + +# ============================================================================= +# Stage 4 — the Web App BFF static binary (Web App/server, go.mod pins go 1.24) +# ============================================================================= +FROM golang:1.24-alpine AS web-build +WORKDIR /src +COPY ["Web App/server/go.mod", "Web App/server/go.sum", "./"] +RUN go mod download +COPY ["Web App/server/", "./"] +# Overlay the freshly built UI so //go:embed all:dist picks it up. +COPY --from=web /server/dist ./dist +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" \ + -o /out/web-app . + +# ============================================================================= +# Stage 5 — SeaweedFS: the one static binary from the official image. +# SEAWEED_VERSION is declared at the top of the file: an ARG used in a FROM has +# to be global, and one declared here would expand to nothing. +# ============================================================================= +FROM chrislusf/seaweedfs:${SEAWEED_VERSION} AS seaweed + +# ============================================================================= +# Stage 6 — runtime: everything under supervisord +# ============================================================================= +FROM alpine:3.24 + +# Pinned so a rebuild months from now produces the same PocketBase. It must be +# v0.23 or newer: the bundled migrations use the v0.23+ JSVM API and the +# pocketbase program 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 supervisor + +# Unprivileged account for every process; supervisord drops to it. Nothing here +# binds a port below 1024, so nothing needs to stay root. +RUN addgroup -S app && adduser -S -G app app + +# PocketBase from the official release (pinned via PB_VERSION, else latest). +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${ver}/pocketbase_${ver}_linux_${TARGETARCH}.zip"; \ + unzip /tmp/pb.zip -d /pb; \ + rm /tmp/pb.zip + +# JS migrations (schema + seed accounts), applied by PocketBase on every serve. +COPY ["API Server/pocketbase/pb_migrations/", "/pb/pb_migrations/"] + +# The two Go binaries. +COPY --from=api-build /out/api-server /usr/local/bin/api-server +COPY --from=web-build /out/web-app /usr/local/bin/web-app +COPY --from=seaweed /usr/bin/weed /usr/local/bin/weed + +# Bucket and identity seed, run by the S3 gateway's program before it serves. +# Two jobs, both idempotent, so every boot re-applies the values from the +# environment and changes nothing else — which is also how a rotated +# PB_S3_SECRET reaches the gateway: +# +# 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 the gateway below runs with neither an -config file nor +# AWS_ACCESS_KEY_ID: the env vars are the lowest-priority credential source in +# SeaweedFS, 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 +# PocketBase's key shows under Object Store → Users like any other. +# +# 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 +# never starts (supervisord retries it, and the healthcheck stays red). +RUN cat > /usr/local/bin/seaweedfs-seed <<'SEED' +#!/bin/sh +set -e +: "${PB_S3_ACCESS_KEY:?seaweedfs-seed: PB_S3_ACCESS_KEY is required}" +: "${PB_S3_SECRET:?seaweedfs-seed: PB_S3_SECRET is required}" +bucket="${PB_S3_BUCKET:-pilotvault}" +shell() { weed shell -master=127.0.0.1:9333 -filer=127.0.0.1:8888; } +printf '%s\n' \ + "s3.bucket.create -name $bucket" \ + "s3.configure -user pilotvault -access_key $PB_S3_ACCESS_KEY -secret_key $PB_S3_SECRET -actions Admin -apply" \ + | shell +if ! echo "s3.configure" | shell | grep -q "$PB_S3_ACCESS_KEY"; then + echo "seaweedfs-seed: PocketBase's identity is not in the filer's IAM store; refusing to start the gateway" >&2 + exit 1 +fi +SEED +RUN chmod +x /usr/local/bin/seaweedfs-seed + +# supervisord runs the eight processes and keeps them alive. Priorities only +# order the launches; readiness is the `until wget` loop in front of each +# program that needs another one up, the same chain the compose split spells +# out with depends_on + healthchecks: master → volume → filer → seed + S3 → +# PocketBase → API Server → Web App. +RUN cat > /etc/supervisord.conf <<'SUPERVISOR' +[supervisord] +nodaemon=true +user=root +pidfile=/run/supervisord.pid +logfile=/dev/null +logfile_maxbytes=0 + +; SeaweedFS master: volume/topology metadata and file ids. +[program:seaweedfs-master] +directory=/app +user=app +command=/usr/local/bin/weed master -ip=127.0.0.1 -ip.bind=127.0.0.1 -port=9333 -mdir=/seaweed/data -volumeSizeLimitMB=1024 -metricsPort=9324 +priority=1 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; SeaweedFS volume server: where the bytes land. On 8081 because 8080 is the +; API Server in this container. -max=0 sizes itself from free disk rather than +; the default cap of 8 volumes. +[program:seaweedfs-volume] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null 2>&1; do echo "waiting for seaweedfs master..."; sleep 1; done; exec /usr/local/bin/weed volume -master=127.0.0.1:9333 -ip=127.0.0.1 -ip.bind=127.0.0.1 -port=8081 -dir=/seaweed/data -max=0 -metricsPort=9325' +priority=2 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; SeaweedFS filer: the directory tree over the flat volume store — buckets, +; object keys — and the IAM store the S3 identities live in. -defaultStoreDir +; keeps its embedded leveldb on the data volume so they survive a recreate. +[program:seaweedfs-filer] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8081/healthz >/dev/null 2>&1; do echo "waiting for seaweedfs volume..."; sleep 1; done; exec /usr/local/bin/weed filer -master=127.0.0.1:9333 -ip=127.0.0.1 -ip.bind=127.0.0.1 -port=8888 -defaultStoreDir=/seaweed/data -metricsPort=9326' +priority=3 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; SeaweedFS S3 gateway: PocketBase's endpoint. Seeds the bucket and identity +; first (see /usr/local/bin/seaweedfs-seed) and never serves if that fails. 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. +[program:seaweedfs-s3] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8888/healthz >/dev/null 2>&1; do echo "waiting for seaweedfs filer..."; sleep 1; done; /usr/local/bin/seaweedfs-seed && exec /usr/local/bin/weed s3 -filer=127.0.0.1:8888 -ip.bind=127.0.0.1 -port=8333 -metricsPort=9327' +priority=4 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; SeaweedFS admin UI: cluster view, buckets, maintenance, and Object Store → +; Users. It can mint credentials for the bucket, and weed leaves auth off +; entirely when WEED_ADMIN_PASSWORD is empty — so an empty password means no +; panel at all rather than an open one. -dataDir persists the session key and +; the maintenance-task settings. +[program:seaweedfs-admin] +directory=/app +user=app +command=/bin/sh -c 'if [ -z "$WEED_ADMIN_PASSWORD" ]; then echo "seaweedfs-admin: WEED_ADMIN_PASSWORD is empty; refusing to serve an unauthenticated panel" >&2; exit 1; fi; until wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null 2>&1; do echo "waiting for seaweedfs master..."; sleep 1; done; exec /usr/local/bin/weed admin -port=23646 -master=127.0.0.1:9333 -dataDir=/seaweed/admin -metricsPort=9328' +priority=5 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; PocketBase: wait for the S3 gateway — PocketBase is the process that reads +; and writes the objects. Then upsert the superuser and serve with the +; bundled migrations. +[program:pocketbase] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8333/healthz >/dev/null 2>&1; do echo "waiting for seaweedfs s3..."; sleep 1; done; /pb/pocketbase superuser upsert "$POCKETBASE_ADMIN_EMAIL" "$POCKETBASE_ADMIN_PASSWORD" --dir=/pb/pb_data 2>/dev/null || echo "warning: superuser upsert failed" >&2; exec /pb/pocketbase serve --http=0.0.0.0:8070 --dir=/pb/pb_data --migrationsDir=/pb/pb_migrations' +priority=10 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; API Server: wait for PocketBase to be healthy, then start. On boot it +; points PocketBase's file storage at the bucket (PB_S3_*) and asks it to +; prove the gateway is reachable. It keeps one file on disk, plugins.json, on +; the /app/data volume (PLUGINS_FILE). +[program:api-server] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8070/api/health >/dev/null 2>&1; do echo "waiting for pocketbase..."; sleep 1; done; exec /usr/local/bin/api-server' +priority=20 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +; Web App: the Go BFF serving the UI on :8090 and proxying /api/* to the API +; Server on loopback. Waits for the API Server so the first page load works. +[program:web-app] +directory=/app +user=app +command=/bin/sh -c 'until wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1; do echo "waiting for api-server..."; sleep 1; done; exec /usr/local/bin/web-app' +priority=30 +autostart=true +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +SUPERVISOR + +# The entrypoint stays root only long enough to make the data volumes writable +# by the app user, then hands off to supervisord. The chown matters for a host +# bind mount, which arrives owned by root rather than inheriting the image's +# owner. +RUN cat > /entrypoint.sh <<'ENTRY' +#!/bin/sh +set -e +for dir in /pb/pb_data /app/data /seaweed/data /seaweed/admin; do + mkdir -p "$dir" + if [ "$(stat -c %U "$dir" 2>/dev/null)" != "app" ]; then + echo "entrypoint: taking ownership of $dir" + chown -R app:app "$dir" + fi +done +exec supervisord -c /etc/supervisord.conf +ENTRY +RUN chmod +x /entrypoint.sh + +# Everything is local to this container. WEBAPP_URL is what the panel status +# page probes. +# +# File storage is on by construction: the gateway is in this image, at a fixed +# loopback address, path style because a self-hosted gateway has no per-bucket +# DNS. The region is a formality SeaweedFS ignores and PocketBase insists on. +# supervisord passes these through to the API Server, which writes them into +# PocketBase's settings on every boot. Only record files move — the document +# store's blobs; the database and PocketBase's own backups stay on /pb/pb_data. +ENV API_ADDR=:8080 \ + POCKETBASE_URL=http://127.0.0.1:8070 \ + CORS_ALLOW_ORIGINS=http://localhost:8090 \ + WEBAPP_URL=http://127.0.0.1:8090 \ + PLUGINS_FILE=/app/data/plugins.json \ + ADDR=:8090 \ + API_BASE=http://127.0.0.1:8080 \ + PB_S3_ENABLED=true \ + PB_S3_ENDPOINT=http://127.0.0.1:8333 \ + PB_S3_BUCKET=pilotvault \ + PB_S3_REGION=us-east-1 \ + PB_S3_FORCE_PATH_STYLE=true \ + WEED_ADMIN_USER=admin + +# Required at runtime (no safe defaults): POCKETBASE_ADMIN_EMAIL, +# POCKETBASE_ADMIN_PASSWORD; PB_S3_ACCESS_KEY, PB_S3_SECRET (the identity seeded +# into SeaweedFS AND what PocketBase authenticates with — the gateway refuses to +# start without them); WEED_ADMIN_PASSWORD (the admin UI refuses to start +# without it). Optional: WEED_ADMIN_READONLY_USER / _PASSWORD add a view-only +# login to the admin UI. Pass them with `docker run -e ...`. + +# Four volumes. /pb/pb_data: the database, documents uploaded before S3 was on, +# PocketBase's own backups. /app/data: the API Server's plugins.json. +# /seaweed/data: master, volume and filer share it, in exactly the layout +# `weed server -dir` writes, so a SEAWEED_DATA volume from either compose +# SeaweedFS file mounts here unchanged, and vice versa. /seaweed/admin: the admin +# UI's session key and maintenance-task state, small and no part of the object +# store. All pre-created and owned by app so a fresh named volume inherits that +# ownership. +RUN mkdir -p /pb/pb_data /app/data /seaweed/data /seaweed/admin \ + && chown -R app:app /pb /app /seaweed +VOLUME ["/pb/pb_data", "/app/data", "/seaweed/data", "/seaweed/admin"] +WORKDIR /app +# 8090 = Web App, 8080 = API Server + embedded panel, 8070 = PocketBase admin, +# 23646 = SeaweedFS admin UI. +EXPOSE 8090 8080 8070 23646 + +# Every process must answer, so a wedged component shows up in `docker ps` +# instead of a container that looks up while part of it is dead. start-period +# covers the SeaweedFS chain plus the first-boot migrations on a cold database. +HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \ + CMD wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8081/healthz >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8888/healthz >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8333/healthz >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:23646/health >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8070/api/health >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8080/healthz >/dev/null 2>&1 \ + && wget -qO- http://127.0.0.1:8090/ >/dev/null 2>&1 \ + || exit 1 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/Docker-AIO/README.md b/Docker-AIO/README.md new file mode 100644 index 0000000..bd8bcea --- /dev/null +++ b/Docker-AIO/README.md @@ -0,0 +1,211 @@ +# PilotVault — Docker AIO (all-in-one image) + +**PocketBase + API Server + Web App in a single container**, supervised by +`supervisord`. One image, one container, no compose network — the simplest way +to stand PilotVault up on a single host. + +Prefer the three-container stack in [`../Docker`](../Docker) when you want to +scale, upgrade or restart the pieces independently. + +``` +:8090 Web App BFF ──/api/*──► API Server on 127.0.0.1:8080 ─► PocketBase on :8070 +``` + +| File | Use | +|---|---| +| `Dockerfile` | the all-in-one image (build context must be the **repo root**) | +| `Dockerfile.seaweedfs` | the same, with SeaweedFS (`weed server -s3`) baked in — see below | +| `Dockerfile.seaweedfs.split` | the same, with SeaweedFS split into its roles baked in — see below | +| `docker-compose.yml` | **builds from source** — for development and local testing | +| `docker-compose.prod.yml` | **pulls the prebuilt image** from the registry | +| `.env.example` / `.env.prod.example` | copy to `.env` for the matching compose file | +| `docker-compose[.prod].{s3,seaweedfs,seaweedfs.split}.yml` | the same with file storage in S3 — see [File storage](#file-storage-seaweedfs--s3) | + +## Run it + +```bash +cd Docker-AIO +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/_/`. + +## Building by hand + +The build context **must be the repo root** so the Dockerfile can reach both +`API Server/` and `Web App/` (the root `.dockerignore` keeps the Fly/Phone apps +out of it): + +```bash +docker build -f "Docker-AIO/Dockerfile" -t pilotvault-aio . +``` + +The image builds both Vue frontends (the API Server panel and the Web App UI) +and both Go binaries from source. Build arg `PB_VERSION` is pinned in the +Dockerfile (v0.39.11 — it must be v0.23 or newer for the bundled migrations); +override it to build a different PocketBase, or set it to an empty string to +resolve the latest release at build time. + +## First boot + +Identical to the multi-container stack, and idempotent: + +1. PocketBase upserts its superuser from `POCKETBASE_ADMIN_EMAIL` / + `POCKETBASE_ADMIN_PASSWORD` — the API Server then authenticates with the same + credentials. +2. PocketBase runs the bundled JS migrations, which create/reconcile every + collection and seed the baseline org and accounts, including the + `superadmin@pilotvault.local` app login. +3. The API Server waits for PocketBase to report healthy, then starts; the Web + App waits for the API Server. + +The image no longer bakes in default superuser credentials: the compose files +refuse to start without `POCKETBASE_ADMIN_*` in `.env`. + +## Volumes + +| Volume | Holds | +|---|---| +| `/pb/pb_data` (`PB_DATA`) | the PocketBase SQLite database, its backups and — unless S3 is on — the uploaded document blobs | +| `/app/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. Every process runs as the +unprivileged `app` user; the entrypoint stays root only long enough to take +ownership of a root-owned bind mount, then hands off to supervisord. + +> One thing does **not** persist: the API Server panel's *Settings → PocketBase* +> screen applies immediately but only for the life of the container. Set the +> corresponding environment variables to change things permanently. + +## 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** | `docker-compose.prod.seaweedfs.yml` (builds `Dockerfile.seaweedfs`) | `docker-compose.seaweedfs.yml` | +| **SeaweedFS, split into its roles** | `docker-compose.prod.seaweedfs.split.yml` (builds `Dockerfile.seaweedfs.split`) | `docker-compose.seaweedfs.split.yml` | +| **An S3 endpoint elsewhere** | `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 build +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 **from-source SeaweedFS files** run the object store **beside** the + all-in-one: a `seaweedfs` container (master, volume, filer and S3 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 **prod SeaweedFS files** go the other way and **build it into the image**: + `Dockerfile.seaweedfs` runs `weed server -s3` as one more supervisord program + (the `weed` binary is copied from the official image, pinned by the + `SEAWEED_VERSION` build arg) on a `/seaweed/data` volume of its own, with + PocketBase's program creating the bucket before it serves. One container, the + cost being that a new SeaweedFS is a rebuild rather than a tag change. Inside, + the volume server sits on **8081** since 8080 is the API Server, every + SeaweedFS role binds loopback, and nothing of SeaweedFS is published. The + build needs the repo checkout, so either build on the deploy host or + `docker compose push` the image to `AIO_IMAGE` and `pull` it there. +- The **external-S3 files** 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. `docker-compose.seaweedfs.split.yml` runs them as four containers +beside the all-in-one, 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. + +The prod twin builds it in: `docker-compose.prod.seaweedfs.split.yml` **builds +`Dockerfile.seaweedfs.split`**, which bakes all five roles into the all-in-one +image as five more supervisord programs, with the bucket-and-identity seed run +inside the gateway's program instead of a `seaweedfs-init` container. What +survives of "split" in there is per-role restart, per-role metrics ports and the +admin UI; what does not is spreading the roles over hosts. Only the admin UI is +published, on loopback by default. + +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-gateway 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 the split files seed 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. 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 (the baked-in image refuses to start the panel at all without one). +A remote host needs `SEAWEED_ADMIN_BIND=0.0.0.0` behind a reverse proxy. + +Switching between any of the SeaweedFS files needs no migration: master, volume +and filer share one data mount (`/data` in the side containers, `/seaweed/data` +in the baked-in image), which is exactly the layout `weed server -dir` 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), then asks PocketBase to +prove it can reach the bucket: + +``` +[api] storage: ✓ file storage → S3 (pilotvault at http://127.0.0.1:8333) +[api] storage: ✓ S3 storage reachable +``` + +A boot that finds the settings already correct logs +`• file storage already on S3` and writes nothing. + +- **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. Move the files back and turn it + off in PocketBase's own admin UI. 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. + +## Caveats + +- A crash of `supervisord` takes every process down together — that is the trade + for the simplicity. +- Logs from all processes are interleaved on the container's stdout/stderr + (`docker logs pilotvault-aio`). +- The container reports health once every process answers its probe (the Web + App's is its index page), so a wedged component shows up in `docker ps` rather + than looking up. +- Nothing in the image 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-AIO/docker-compose.prod.s3.yml b/Docker-AIO/docker-compose.prod.s3.yml new file mode 100644 index 0000000..d3c9075 --- /dev/null +++ b/Docker-AIO/docker-compose.prod.s3.yml @@ -0,0 +1,87 @@ +name: pilotvault-aio + +# Production all-in-one, with external S3 — pulls the prebuilt image from the +# registry instead of building. 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 container, 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. +# +# On first boot PocketBase upserts the superuser from POCKETBASE_ADMIN_*, and +# runs the bundled migrations (every collection, the baseline org and the +# superadmin@pilotvault.local login). Both steps are idempotent. + +services: + pilotvault: + image: "${AIO_IMAGE:-10.2.1.10:5500/admin/pilotvault-aio:latest}" + container_name: pilotvault-aio + 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: + # Superuser (also used by the API Server to authenticate to PocketBase). + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + # Match CORS to the web origin (only used if a browser calls the API + # directly). + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Probed by the panel status page. The Web App BFF listens on 8090 inside + # this container too. Override WEBAPP_URL in .env to make a change from + # the panel permanent; the panel alone only holds it for the container's + # life. + WEBAPP_URL: "${WEBAPP_URL:-http://127.0.0.1:8090}" + # --- File storage -------------------------------------------------- + # supervisord passes these through to the API Server, which writes them + # into PocketBase's settings on every boot, 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}" + ports: + - "${WEB_PORT:-8090}:8090" # Web App (Go BFF) + - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${API_PORT:-8080}:8080" # API Server + panel (root /) + volumes: + # Named volumes by default; set any of them to a host path in .env for a + # bind mount. PB_DATA: the database and PocketBase's backups. API_DATA: + # the API Server's plugins.json (plugin enable-state + config). + - "${PB_DATA:-pb_data}:/pb/pb_data" + - "${API_DATA:-api_data}:/app/data" + healthcheck: + # All three processes must answer. Declared here as well as in the image + # so the check is visible, and works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health >/dev/null && wget -qO- http://127.0.0.1:8080/healthz >/dev/null && wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 60s + +volumes: + pb_data: + api_data: diff --git a/Docker-AIO/docker-compose.prod.seaweedfs.split.yml b/Docker-AIO/docker-compose.prod.seaweedfs.split.yml new file mode 100644 index 0000000..910aad9 --- /dev/null +++ b/Docker-AIO/docker-compose.prod.seaweedfs.split.yml @@ -0,0 +1,149 @@ +name: pilotvault-aio + +# Production all-in-one with SeaweedFS split into its roles — and, unlike the +# other prod files, built into ONE image here: Dockerfile.seaweedfs.split bakes +# master, volume, filer, S3 gateway and the admin UI into the same container as +# PocketBase, the API Server and the Web App. One service, one container, four +# volumes. 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 build +# 3. docker compose -f docker-compose.prod.seaweedfs.split.yml up -d +# +# The build context is the repo root, so this has to run on a host that has the +# checkout. To deploy elsewhere, `push` the built image to the registry named in +# AIO_IMAGE and `pull` it there — `image:` and `build:` are both set, so the +# same file does either. +# +# What the split buys inside one image: per-role restart under supervisord, +# per-role metrics ports, and the SeaweedFS admin UI (weed admin) — a cluster +# view, and Object Store → Users, where S3 identities are created and revoked +# without touching a file. What it costs against the six-container shape it +# replaces: a new SeaweedFS is a rebuild (SEAWEED_VERSION below), not a tag +# change, and the roles cannot be spread over hosts. If the object store should +# stay outside the app image, use docker-compose.prod.seaweedfs.yml — the S3 +# behaviour is identical. +# +# The on-disk layout is the same as every other SeaweedFS shape here: 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 a SEAWEED_DATA volume from docker-compose.prod.seaweedfs.yml +# mounts here unchanged, and vice versa, with no migration either way. +# +# Inside the container every SeaweedFS role listens on loopback except the admin +# UI. Only the admin UI is published, on loopback by default; PocketBase reaches +# the gateway inside. The volume server serves file content by id with no +# authentication at all, so it is never reachable from outside; the admin UI +# shows what its port would. +# +# Before turning this on for a stack that already has uploads: PocketBase does +# NOT copy existing files into the bucket. See README.md. +# +# On first boot the S3 gateway's program creates the bucket and seeds +# PocketBase's identity into the filer's IAM store, PocketBase upserts the +# superuser from POCKETBASE_ADMIN_*, PocketBase runs its bundled migrations +# (every collection, the baseline org and the superadmin@pilotvault.local +# login), and the API Server points PocketBase's file storage at the bucket. +# Every step is idempotent. + +services: + pilotvault: + build: + # Project root (one level up from this compose file), so the Dockerfile + # can reach both "API Server/" and "Web App/". + context: .. + dockerfile: Docker-AIO/Dockerfile.seaweedfs.split + args: + # Bare names = pass through only when set in the environment, so an + # unset PB_VERSION / SEAWEED_VERSION leaves the Dockerfile pin in place + # instead of overriding it with an empty string (which for PB_VERSION + # would resolve "latest" at build time, and for SEAWEED_VERSION would + # not build at all). + - PB_VERSION + - SEAWEED_VERSION + # Tagged for the registry so `docker compose push` lands it where `pull` on + # the deploy host expects it. + image: "${AIO_IMAGE:-10.2.1.10:5500/admin/pilotvault-aio-seaweedfs-split:latest}" + container_name: pilotvault-aio + restart: unless-stopped + environment: + # Superuser (also used by the API Server to authenticate to PocketBase). + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + # Match CORS to the web origin (only used if a browser calls the API + # directly). + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Probed by the panel status page. The Web App BFF listens on 8090 inside + # this container too. Override WEBAPP_URL in .env to make a change from + # the panel permanent; the panel alone only holds it for the container's + # life. + WEBAPP_URL: "${WEBAPP_URL:-http://127.0.0.1:8090}" + # --- File storage -------------------------------------------------- + # The image fixes the rest (PB_S3_ENABLED, the loopback endpoint, path + # style, the region): the gateway is inside, at an address that cannot + # change. supervisord passes these through to the API Server, which writes + # them into PocketBase's settings on every boot, idempotently. Only record + # files move — the document store's blobs. The database and PocketBase's + # own backups stay on PB_DATA. + # + # The credentials do double duty: the gateway's program seeds them into + # the filer's IAM store as the identity named "pilotvault" (updating it in + # place on every boot — that is how a rotated secret lands) *and* they are + # what PocketBase authenticates with. No safe defaults; the gateway + # refuses to start without them, and with it the whole container. + 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}" + # --- SeaweedFS admin UI -------------------------------------------- + # 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, and the image refuses to + # start the panel at all in that case. Read from WEED_ADMIN_* rather than + # a flag, which keeps it off the process command line. + 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:-}" + ports: + - "${WEB_PORT:-8090}:8090" # Web App (Go BFF) + - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${API_PORT:-8080}:8080" # API Server + panel (root /) + # The S3 gateway is not published: PocketBase reaches it inside the + # container. The admin UI is, on loopback: storage plumbing, not one of + # the app's own panels. On a remote host that means unreachable, so set + # SEAWEED_ADMIN_BIND=0.0.0.0 and put it behind a reverse proxy. + - "${SEAWEED_ADMIN_BIND:-127.0.0.1}:${SEAWEED_ADMIN_PORT:-23646}:23646" + volumes: + # Named volumes by default; set any of them to a host path in .env for a + # bind mount. PB_DATA: the database and PocketBase's backups. API_DATA: + # the API Server's plugins.json (plugin enable-state + config). Back up + # PB_DATA and SEAWEED_DATA together — from here on the documents live in + # the second, not the first. + - "${PB_DATA:-pb_data}:/pb/pb_data" + - "${API_DATA:-api_data}:/app/data" + - "${SEAWEED_DATA:-seaweed_data}:/seaweed/data" + - "${SEAWEED_ADMIN_DATA:-seaweed_admin}:/seaweed/admin" + healthcheck: + # Every process must answer — the five SeaweedFS roles and the three app + # processes. Declared here as well as in the image so the check is + # visible, and works against an older pulled image. start_period covers + # the SeaweedFS chain plus the first-boot migrations. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null && wget -qO- http://127.0.0.1:8081/healthz >/dev/null && wget -qO- http://127.0.0.1:8888/healthz >/dev/null && wget -qO- http://127.0.0.1:8333/healthz >/dev/null && wget -qO- http://127.0.0.1:23646/health >/dev/null && wget -qO- http://127.0.0.1:8070/api/health >/dev/null && wget -qO- http://127.0.0.1:8080/healthz >/dev/null && wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 90s + +volumes: + pb_data: + api_data: + # Master, volume and filer share it — 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-AIO/docker-compose.prod.seaweedfs.yml b/Docker-AIO/docker-compose.prod.seaweedfs.yml new file mode 100644 index 0000000..7510206 --- /dev/null +++ b/Docker-AIO/docker-compose.prod.seaweedfs.yml @@ -0,0 +1,121 @@ +name: pilotvault-aio + +# Production all-in-one with SeaweedFS — and, unlike docker-compose.prod.yml, +# built into ONE image here: Dockerfile.seaweedfs bakes `weed server -s3` +# (master, volume, filer and S3 gateway in one process) into the same container +# as PocketBase, the API Server and the Web App. One service, one container, +# three volumes. 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 build +# 3. docker compose -f docker-compose.prod.seaweedfs.yml up -d +# +# The build context is the repo root, so this has to run on a host that has the +# checkout. To deploy elsewhere, `push` the built image to the registry named in +# AIO_IMAGE and `pull` it there — `image:` and `build:` are both set, so the +# same file does either. +# +# 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. +# +# What baking it in costs against the two-container shape it replaces: a new +# SeaweedFS is a rebuild (SEAWEED_VERSION below), not a tag change. For per-role +# restart, metrics and the SeaweedFS admin UI, see +# docker-compose.prod.seaweedfs.split.yml — the S3 behaviour is identical, and +# the data volume is interchangeable (both write the `weed server -dir` layout). +# +# Before turning this on for a stack that already has uploads: PocketBase does +# NOT copy existing files into the bucket. See README.md. +# +# On first boot PocketBase's program creates the bucket and upserts the +# superuser from POCKETBASE_ADMIN_*, PocketBase runs its bundled migrations +# (every collection, the baseline org and the superadmin@pilotvault.local +# login), and the API Server points PocketBase's file storage at the bucket. +# Every step is idempotent. + +services: + pilotvault: + build: + # Project root (one level up from this compose file), so the Dockerfile + # can reach both "API Server/" and "Web App/". + context: .. + dockerfile: Docker-AIO/Dockerfile.seaweedfs + args: + # Bare names = pass through only when set in the environment, so an + # unset PB_VERSION / SEAWEED_VERSION leaves the Dockerfile pin in place + # instead of overriding it with an empty string (which for PB_VERSION + # would resolve "latest" at build time, and for SEAWEED_VERSION would + # not build at all). + - PB_VERSION + - SEAWEED_VERSION + # Tagged for the registry so `docker compose push` lands it where `pull` on + # the deploy host expects it. + image: "${AIO_IMAGE:-10.2.1.10:5500/admin/pilotvault-aio-seaweedfs:latest}" + container_name: pilotvault-aio + restart: unless-stopped + environment: + # Superuser (also used by the API Server to authenticate to PocketBase). + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + # Match CORS to the web origin (only used if a browser calls the API + # directly). + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Probed by the panel status page. The Web App BFF listens on 8090 inside + # this container too. Override WEBAPP_URL in .env to make a change from + # the panel permanent; the panel alone only holds it for the container's + # life. + WEBAPP_URL: "${WEBAPP_URL:-http://127.0.0.1:8090}" + # --- File storage -------------------------------------------------- + # The image fixes the rest (PB_S3_ENABLED, the loopback endpoint, path + # style, the region): the gateway is inside, at an address that cannot + # change. supervisord passes these through to the API Server, which writes + # them into PocketBase's settings on every boot, idempotently. Only record + # files move — the document store's blobs. The database and PocketBase's + # own backups stay on PB_DATA. + # + # The credentials do double duty: they configure the gateway's single + # identity — which is what takes it out of its default allow-anyone mode — + # *and* they are what PocketBase authenticates with. No safe defaults; the + # gateway refuses to start without them, and with it the whole container. + 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}" + ports: + - "${WEB_PORT:-8090}:8090" # Web App (Go BFF) + - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${API_PORT:-8080}:8080" # API Server + panel (root /) + # Nothing of SeaweedFS is published: PocketBase reaches the S3 gateway + # inside the container, and the volume server (8081 inside) serves file + # content by id with no authentication at all. + volumes: + # Named volumes by default; set any of them to a host path in .env for a + # bind mount. PB_DATA: the database and PocketBase's backups. API_DATA: + # the API Server's plugins.json (plugin enable-state + config). Back up + # PB_DATA and SEAWEED_DATA together — from here on the documents live in + # the second, not the first. + - "${PB_DATA:-pb_data}:/pb/pb_data" + - "${API_DATA:-api_data}:/app/data" + - "${SEAWEED_DATA:-seaweed_data}:/seaweed/data" + healthcheck: + # Every process must answer — SeaweedFS's master and gateway and the three + # app processes. Declared here as well as in the image so the check is + # visible, and works against an older pulled image. start_period covers + # SeaweedFS coming up plus the first-boot migrations. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9333/cluster/status >/dev/null && wget -qO- http://127.0.0.1:8333/healthz >/dev/null && wget -qO- http://127.0.0.1:8070/api/health >/dev/null && wget -qO- http://127.0.0.1:8080/healthz >/dev/null && wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 90s + +volumes: + pb_data: + api_data: + # The `weed server -dir` layout, so this file and its .split. twin can swap + # places on it. + seaweed_data: diff --git a/Docker-AIO/docker-compose.prod.yml b/Docker-AIO/docker-compose.prod.yml index 353a513..f00a7e4 100644 --- a/Docker-AIO/docker-compose.prod.yml +++ b/Docker-AIO/docker-compose.prod.yml @@ -1,17 +1,16 @@ name: pilotvault-aio # Production all-in-one — pulls the prebuilt image from the registry instead of -# building. One container runs PocketBase + API Server + Web App. Everything an -# operator needs to set lives in .env. +# building. One container runs PocketBase + API Server + Web App (Go BFF). +# Everything an operator needs to set lives in .env. # # 1. cp .env.prod.example .env (then edit it) # 2. docker compose -f docker-compose.prod.yml pull # 3. docker compose -f docker-compose.prod.yml up -d # -# On first boot the bundled PocketBase upserts its superuser from -# POCKETBASE_ADMIN_* and runs the JS migrations, which create/reconcile every -# collection and seed the baseline org + accounts (incl. superadmin@pilotvault.local). -# Idempotent, so restarts and upgrades are safe. +# On first boot PocketBase upserts the superuser from POCKETBASE_ADMIN_*, and +# runs the bundled migrations (every collection, the baseline org and the +# superadmin@pilotvault.local login). Both steps are idempotent. services: pilotvault: @@ -19,16 +18,36 @@ services: container_name: pilotvault-aio restart: unless-stopped environment: + # Superuser (also used by the API Server to authenticate to PocketBase). POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + # Match CORS to the web origin (only used if a browser calls the API + # directly). CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Probed by the panel status page. The Web App BFF listens on 8090 inside + # this container too. Override WEBAPP_URL in .env to make a change from + # the panel permanent; the panel alone only holds it for the container's + # life. + WEBAPP_URL: "${WEBAPP_URL:-http://127.0.0.1:8090}" ports: - - "${WEB_PORT:-8090}:8090" # Web App (control panel) - - "${API_PORT:-8080}:8080" # API Server + embedded API web panel (root /) - - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${WEB_PORT:-8090}:8090" # Web App (Go BFF) + - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${API_PORT:-8080}:8080" # API Server + panel (root /) volumes: - # Named volume by default; set PB_DATA to a host path in .env for a bind mount. + # Named volumes by default; set any of them to a host path in .env for a + # bind mount. PB_DATA: the database and PocketBase's backups. API_DATA: + # the API Server's plugins.json (plugin enable-state + config). - "${PB_DATA:-pb_data}:/pb/pb_data" + - "${API_DATA:-api_data}:/app/data" + healthcheck: + # All three processes must answer. Declared here as well as in the image + # so the check is visible, and works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health >/dev/null && wget -qO- http://127.0.0.1:8080/healthz >/dev/null && wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 60s volumes: pb_data: + api_data: diff --git a/Docker-AIO/docker-compose.s3.yml b/Docker-AIO/docker-compose.s3.yml new file mode 100644 index 0000000..61d7b25 --- /dev/null +++ b/Docker-AIO/docker-compose.s3.yml @@ -0,0 +1,92 @@ +name: pilotvault-aio + +# Single all-in-one container, with external S3: PocketBase + API Server + Web +# App (Go BFF) in one image, 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 +# +# The build context is the project root so the Dockerfile can reach both "API +# Server/" and "Web App/". +# +# 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 container, 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: + pilotvault: + build: + # Project root (one level up from this compose file). + context: .. + dockerfile: Docker-AIO/Dockerfile + args: + # Bare name = pass through only when set in the environment, so an unset + # PB_VERSION leaves the Dockerfile pin in place instead of overriding it + # with an empty string (which would resolve "latest" at build time). + - PB_VERSION + image: pilotvault-aio + container_name: pilotvault-aio + 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: + # Superuser (also used by the API Server to authenticate to PocketBase). + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + # Match CORS to the web origin (only used if a browser calls the API + # directly). + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Probed by the panel status page. The Web App BFF listens on 8090 inside + # this container too. Override WEBAPP_URL in .env to make a change from + # the panel permanent; the panel alone only holds it for the container's + # life. + WEBAPP_URL: "${WEBAPP_URL:-http://127.0.0.1:8090}" + # --- File storage -------------------------------------------------- + # supervisord passes these through to the API Server, which writes them + # into PocketBase's settings on every boot, 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}" + ports: + - "${WEB_PORT:-8090}:8090" # Web App (Go BFF) + - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${API_PORT:-8080}:8080" # API Server + panel (root /) + volumes: + # Named volumes by default; set any of them to a host path in .env for a + # bind mount. PB_DATA: the database and PocketBase's backups. API_DATA: + # the API Server's plugins.json (plugin enable-state + config). + - "${PB_DATA:-pb_data}:/pb/pb_data" + - "${API_DATA:-api_data}:/app/data" + healthcheck: + # All three processes must answer. Declared here as well as in the image + # so the check is visible, and works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health >/dev/null && wget -qO- http://127.0.0.1:8080/healthz >/dev/null && wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 60s + +volumes: + pb_data: + api_data: diff --git a/Docker-AIO/docker-compose.seaweedfs.split.yml b/Docker-AIO/docker-compose.seaweedfs.split.yml new file mode 100644 index 0000000..b831178 --- /dev/null +++ b/Docker-AIO/docker-compose.seaweedfs.split.yml @@ -0,0 +1,302 @@ +name: pilotvault-aio + +# Single all-in-one container, with SeaweedFS split into its four roles: +# PocketBase + API Server + Web App (Go BFF) in one image, beside 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 +# +# The build context is the project root so the Dockerfile can reach both "API +# Server/" and "Web App/". +# +# 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 beside the all-in-one 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. +# +# None of them run inside the all-in-one image, for the same reason the single +# gateway does not: keeping the object store in that image, on the volume the +# files are being moved off, would defeat the point and would mean rebuilding. +# +# 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-aio-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-aio-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. + - "${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-aio-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-aio-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-aio-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-aio-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 + + pilotvault: + build: + # Project root (one level up from this compose file). + context: .. + dockerfile: Docker-AIO/Dockerfile + args: + # Bare name = pass through only when set in the environment, so an unset + # PB_VERSION leaves the Dockerfile pin in place instead of overriding it + # with an empty string (which would resolve "latest" at build time). + - PB_VERSION + image: pilotvault-aio + container_name: pilotvault-aio + restart: unless-stopped + depends_on: + # PocketBase — inside this container — is the process that reads and + # writes the objects, so the gateway has to be serving first, and the + # bucket has to exist before the API Server points PocketBase at it. + seaweedfs-s3: + condition: service_healthy + seaweedfs-init: + condition: service_completed_successfully + environment: + # Superuser (also used by the API Server to authenticate to PocketBase). + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + # Match CORS to the web origin (only used if a browser calls the API + # directly). + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Probed by the panel status page. The Web App BFF listens on 8090 inside + # this container too. Override WEBAPP_URL in .env to make a change from + # the panel permanent; the panel alone only holds it for the container's + # life. + WEBAPP_URL: "${WEBAPP_URL:-http://127.0.0.1:8090}" + # --- File storage -------------------------------------------------- + # supervisord passes these through to the API Server, which writes them + # into PocketBase's settings on every boot, 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" + ports: + - "${WEB_PORT:-8090}:8090" # Web App (Go BFF) + - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${API_PORT:-8080}:8080" # API Server + panel (root /) + volumes: + # Named volumes by default; set any of them to a host path in .env for a + # bind mount. PB_DATA: the database and PocketBase's backups. API_DATA: + # the API Server's plugins.json (plugin enable-state + config). Back up + # PB_DATA and SEAWEED_DATA together — from here on the documents live in + # the second, not the first. + - "${PB_DATA:-pb_data}:/pb/pb_data" + - "${API_DATA:-api_data}:/app/data" + healthcheck: + # All three processes must answer. Declared here as well as in the image + # so the check is visible, and works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health >/dev/null && wget -qO- http://127.0.0.1:8080/healthz >/dev/null && wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 60s + +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-AIO/docker-compose.seaweedfs.yml b/Docker-AIO/docker-compose.seaweedfs.yml new file mode 100644 index 0000000..e2f646d --- /dev/null +++ b/Docker-AIO/docker-compose.seaweedfs.yml @@ -0,0 +1,144 @@ +name: pilotvault-aio + +# Single all-in-one container, with SeaweedFS: PocketBase + API Server + Web App +# (Go BFF) in one image, plus an S3 object store beside it. 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 +# +# The build context is the project root so the Dockerfile can reach both "API +# Server/" and "Web App/". +# +# 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. +# +# SeaweedFS runs as a second container beside the all-in-one, not as a fourth +# process inside it: keeping the object store in that image, on the volume the +# files are being moved off, would defeat the point and would mean rebuilding. +# +# 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-aio-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-aio-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' + + pilotvault: + build: + # Project root (one level up from this compose file). + context: .. + dockerfile: Docker-AIO/Dockerfile + args: + # Bare name = pass through only when set in the environment, so an unset + # PB_VERSION leaves the Dockerfile pin in place instead of overriding it + # with an empty string (which would resolve "latest" at build time). + - PB_VERSION + image: pilotvault-aio + container_name: pilotvault-aio + restart: unless-stopped + depends_on: + # PocketBase — inside this container — is the process that reads and + # writes the objects, so the gateway has to be serving first, and the + # bucket has to exist before the API Server points PocketBase at it. + seaweedfs: + condition: service_healthy + seaweedfs-init: + condition: service_completed_successfully + environment: + # Superuser (also used by the API Server to authenticate to PocketBase). + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + # Match CORS to the web origin (only used if a browser calls the API + # directly). + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Probed by the panel status page. The Web App BFF listens on 8090 inside + # this container too. Override WEBAPP_URL in .env to make a change from + # the panel permanent; the panel alone only holds it for the container's + # life. + WEBAPP_URL: "${WEBAPP_URL:-http://127.0.0.1:8090}" + # --- File storage -------------------------------------------------- + # supervisord passes these through to the API Server, which writes them + # into PocketBase's settings on every boot, 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" + ports: + - "${WEB_PORT:-8090}:8090" # Web App (Go BFF) + - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${API_PORT:-8080}:8080" # API Server + panel (root /) + volumes: + # Named volumes by default; set any of them to a host path in .env for a + # bind mount. PB_DATA: the database and PocketBase's backups. API_DATA: + # the API Server's plugins.json (plugin enable-state + config). Back up + # PB_DATA and SEAWEED_DATA together — from here on the documents live in + # the second, not the first. + - "${PB_DATA:-pb_data}:/pb/pb_data" + - "${API_DATA:-api_data}:/app/data" + healthcheck: + # All three processes must answer. Declared here as well as in the image + # so the check is visible, and works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health >/dev/null && wget -qO- http://127.0.0.1:8080/healthz >/dev/null && wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 60s + +volumes: + pb_data: + api_data: + seaweed_data: diff --git a/Docker-AIO/docker-compose.yml b/Docker-AIO/docker-compose.yml index ea594f4..0802e9a 100644 --- a/Docker-AIO/docker-compose.yml +++ b/Docker-AIO/docker-compose.yml @@ -1,42 +1,54 @@ name: pilotvault-aio -# All-in-one PilotVault stack (PocketBase + API Server + Web App) in ONE container. -# Run from this Docker-AIO/ folder: -# -# cp .env.example .env # then edit the credentials/ports -# docker compose up --build -# -# The build context is the repo root (..) because the Dockerfile COPYs from -# "API Server/" and "Web App/". -# -# On first boot the bundled PocketBase upserts its superuser from -# POCKETBASE_ADMIN_* and runs the JS migrations, which create/reconcile every -# collection and seed the baseline org + accounts (incl. superadmin@pilotvault.local). +# Single all-in-one container: PocketBase + API Server + Web App (Go BFF). The +# build context is the project root so the Dockerfile can reach both "API +# Server/" and "Web App/". Copy .env.example to .env before starting. services: pilotvault: build: - context: ".." + # Project root (one level up from this compose file). + context: .. dockerfile: Docker-AIO/Dockerfile - # args: - # PB_VERSION: "0.22.21" # override the bundled PocketBase version - # PB_ARCH: "amd64" # use "arm64" on Apple Silicon + args: + # Bare name = pass through only when set in the environment, so an unset + # PB_VERSION leaves the Dockerfile pin in place instead of overriding it + # with an empty string (which would resolve "latest" at build time). + - PB_VERSION image: pilotvault-aio container_name: pilotvault-aio restart: unless-stopped environment: - # Loopback-wired between the three in-container services. Override the - # bundled default credentials here for anything real. - POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:-admin@dji.local}" - POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:-djiadmin2026!}" - CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-*}" + # Superuser (also used by the API Server to authenticate to PocketBase). + POCKETBASE_ADMIN_EMAIL: "${POCKETBASE_ADMIN_EMAIL:?set POCKETBASE_ADMIN_EMAIL in .env}" + POCKETBASE_ADMIN_PASSWORD: "${POCKETBASE_ADMIN_PASSWORD:?set POCKETBASE_ADMIN_PASSWORD in .env}" + # Match CORS to the web origin (only used if a browser calls the API + # directly). + CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:8090}" + # Probed by the panel status page. The Web App BFF listens on 8090 inside + # this container too. Override WEBAPP_URL in .env to make a change from + # the panel permanent; the panel alone only holds it for the container's + # life. + WEBAPP_URL: "${WEBAPP_URL:-http://127.0.0.1:8090}" ports: - - "${WEB_PORT:-8090}:8090" # Web App (control panel) - - "${API_PORT:-8080}:8080" # API Server - - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${WEB_PORT:-8090}:8090" # Web App (Go BFF) + - "${PB_PORT:-8070}:8070" # PocketBase admin UI / API + - "${API_PORT:-8080}:8080" # API Server + panel (root /) volumes: - # Named volume by default; set PB_DATA to a host path in .env for a bind mount. + # Named volumes by default; set any of them to a host path in .env for a + # bind mount. PB_DATA: the database and PocketBase's backups. API_DATA: + # the API Server's plugins.json (plugin enable-state + config). - "${PB_DATA:-pb_data}:/pb/pb_data" + - "${API_DATA:-api_data}:/app/data" + healthcheck: + # All three processes must answer. Declared here as well as in the image + # so the check is visible, and works against an older pulled image. + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8070/api/health >/dev/null && wget -qO- http://127.0.0.1:8080/healthz >/dev/null && wget -qO- http://127.0.0.1:8090/ >/dev/null || exit 1"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 60s volumes: pb_data: + api_data: