# PocketBase 0.40.4 — the schema in pb_migrations is applied automatically on
# first boot, and the admin account is seeded from PB_SUPERUSER_EMAIL /
# PB_SUPERUSER_PASSWORD. Data persists in the mounted /pb_data volume.

FROM alpine:3.20

ARG PB_VERSION=0.40.4
# Docker BuildKit sets TARGETARCH (amd64/arm64) — matches PocketBase release assets.
ARG TARGETARCH

RUN apk add --no-cache curl ca-certificates unzip \
    && curl -fsSL -o /tmp/pocketbase.zip \
       "https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_${TARGETARCH:-amd64}.zip" \
    && unzip /tmp/pocketbase.zip -d /usr/local/bin/ \
    && rm /tmp/pocketbase.zip \
    && chmod +x /usr/local/bin/pocketbase

WORKDIR /pb

COPY pb_migrations ./pb_migrations
# All app logic (validation + email) lives in the Express API, so no runtime
# hooks are required here — an empty hooks dir keeps startup clean.
RUN mkdir -p ./pb_hooks /pb_data

EXPOSE 8090

CMD ["pocketbase", "serve", "--http=0.0.0.0:8090", "--dir=/pb_data", "--migrationsDir=/pb/pb_migrations", "--hooksDir=/pb/pb_hooks", "--encryptionEnv=PB_ENCRYPTION_KEY"]
