# syntax=docker/dockerfile:1
#
# PocketBase for PilotVault, built from the official release binary on alpine.
#
# It bundles the JS migrations from "API Server/pocketbase/pb_migrations" so that
# on first serve PocketBase creates/reconciles every collection and seeds the
# baseline organization + accounts (including the superadmin@pilotvault.local app
# login). Together with the `superuser upsert` in the entrypoint, THIS is where
# PilotVault "checks" that the schema and the super-admin exist — all idempotent,
# so restarts and upgrades are safe.
#
# BUILD CONTEXT IS THE REPO ROOT (the migrations live under "API Server/"). It is
# built for you by Docker/docker-compose.yml; to build it by hand run from
# E:\VS Code Projects\PilotVault:
#
#   docker build -f Docker/pocketbase/Dockerfile -t pilotvault-pocketbase .

FROM alpine:latest

# Pin the version to match the rest of PilotVault; override with --build-arg.
# PB_ARCH is "amd64" (default) or "arm64" (e.g. Apple Silicon).
ARG PB_VERSION=0.22.21
ARG PB_ARCH=amd64

RUN apk add --no-cache ca-certificates tzdata unzip wget

WORKDIR /pb
RUN set -eux; \
    wget -q -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

# Schema + seed migrations (single source of truth in the API Server tree).
COPY ["API Server/pocketbase/pb_migrations/", "/pb/pb_migrations/"]

COPY ["Docker/pocketbase/entrypoint.sh", "/entrypoint.sh"]
RUN chmod +x /entrypoint.sh

# pb_data holds the SQLite database and uploads — mount a volume here.
VOLUME ["/pb/pb_data"]
EXPOSE 8070

ENTRYPOINT ["/entrypoint.sh"]
