diff --git a/README.md b/README.md index fa10d1c..5256676 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,20 @@ Node >= 22.12. | ---------------- | -------------------------------------------- | ------------------------------------ | | `POCKETBASE_URL` | URL of the PocketBase backend (auth + data) | `https://pokeshare.namarusaja.me` | +PocketBase container (compose only): + +| Variable | Description | +| ------------------------------------ | ------------------------------------------------- | +| `PB_SUPERUSER_EMAIL` / `_PASSWORD` | Create/update the admin account on boot | +| `PB_APP_URL` | Public app URL used in transactional email links | +| `SMTP_HOST` / `SMTP_PORT` | Mail server (mail disabled if `SMTP_HOST` empty) | +| `SMTP_USERNAME` / `SMTP_PASSWORD` | Mail server credentials | +| `SMTP_TLS` | `true` (default) / `false` | +| `SMTP_SENDER_NAME` / `_ADDRESS` | From header of transactional emails | + +SMTP settings are applied on every boot by `pocketbase/pb_hooks/main.pb.js` +from these env vars, so they can be changed without touching the admin UI. + Read at **runtime** (`process.env`), so the same Docker image can be deployed against different PocketBase instances. For local dev, copy `.env.example` to `.env`. `HOST` and `PORT` are also honored by the standalone server. diff --git a/docker-compose.yml b/docker-compose.yml index 369634d..02a97e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,17 @@ services: # Optional: create/update the admin account on boot (min 8 chars) PB_SUPERUSER_EMAIL: ${PB_SUPERUSER_EMAIL:-} PB_SUPERUSER_PASSWORD: ${PB_SUPERUSER_PASSWORD:-} + # Optional: app URL used in transactional emails (reset links...) + PB_APP_URL: ${PB_APP_URL:-} + # Optional: SMTP for transactional emails. If SMTP_HOST is empty, + # mail stays disabled (the rest is ignored). + SMTP_HOST: ${SMTP_HOST:-} + SMTP_PORT: ${SMTP_PORT:-587} + SMTP_USERNAME: ${SMTP_USERNAME:-} + SMTP_PASSWORD: ${SMTP_PASSWORD:-} + SMTP_TLS: ${SMTP_TLS:-true} + SMTP_SENDER_NAME: ${SMTP_SENDER_NAME:-PokeShare} + SMTP_SENDER_ADDRESS: ${SMTP_SENDER_ADDRESS:-} volumes: - pb_data:/pb/pb_data diff --git a/pocketbase/Dockerfile b/pocketbase/Dockerfile index e79b877..9c1f10a 100644 --- a/pocketbase/Dockerfile +++ b/pocketbase/Dockerfile @@ -12,6 +12,7 @@ RUN curl -fsSL "https://github.com/pocketbase/pocketbase/releases/download/v${PB && rm pb.zip COPY pb_migrations ./pb_migrations +COPY pb_hooks ./pb_hooks COPY entrypoint.sh ./ RUN chmod +x entrypoint.sh pocketbase diff --git a/pocketbase/pb_hooks/main.pb.js b/pocketbase/pb_hooks/main.pb.js new file mode 100644 index 0000000..a44df34 --- /dev/null +++ b/pocketbase/pb_hooks/main.pb.js @@ -0,0 +1,36 @@ +/** + * Apply app identity and SMTP settings from environment variables on every + * boot, so mail config stays declarative (docker-compose / Coolify env vars). + * These values win over the admin UI (Settings → Mail) — change them via env. + */ +onBootstrap((e) => { + e.next(); + + const settings = $app.settings(); + + // App identity, used in transactional emails (verification, reset, etc.) + settings.meta.appName = "PokeShare"; + const appUrl = $os.getenv("PB_APP_URL"); + if (appUrl) settings.meta.appUrl = appUrl; + + const host = $os.getenv("SMTP_HOST"); + if (!host) { + // No SMTP configured — save identity settings and keep mail disabled + $app.save(settings); + return; + } + + const senderAddress = $os.getenv("SMTP_SENDER_ADDRESS"); + const senderName = $os.getenv("SMTP_SENDER_NAME"); + if (senderAddress) settings.meta.senderAddress = senderAddress; + if (senderName) settings.meta.senderName = senderName; + + settings.smtp.enabled = true; + settings.smtp.host = host; + settings.smtp.port = parseInt($os.getenv("SMTP_PORT") || "587", 10); + settings.smtp.username = $os.getenv("SMTP_USERNAME") || ""; + settings.smtp.password = $os.getenv("SMTP_PASSWORD") || ""; + settings.smtp.tls = ($os.getenv("SMTP_TLS") || "true") === "true"; + + $app.save(settings); +});