# syntax=docker/dockerfile:1 # # 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 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 . # # 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 — 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 — runtime: all three 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 # 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 ; 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 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. 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; 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 # 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"]