Files
Docwell/Docker-AIO/start.sh
T
tajniak81andClaude Opus 5.5 b9be8be156
CI / go (Server) (push) Failing after 22m50s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 8m47s
CI / desktop (ubuntu-latest) (push) Successful in 2h56m50s
CI / mobile (push) Failing after 5m33s
CI / docker (push) Successful in 1h43m8s
Docs / build (push) Successful in 16m2s
Docs / deploy (push) Skipped
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Run docwell-db as a stock PocketBase and let the server set it up
docwell-db no longer needs a Docwell image: the stack runs
tajniak81/pocketbase-docker-root as it is, and docwell-server does what
the migrations and pb_hooks used to do inside PocketBase.

On start, docwell-server now:
- waits for PocketBase and imports Docwell's collections from an
  embedded snapshot (internal/pbschema). Existing collections and
  fields are matched by name, so their data is kept; the admin-managed
  users options (OAuth2 providers, magic link) are left untouched.
- writes the DOCWELL_APP_NAME, DOCWELL_WEB_URL, DOCWELL_MAIL_FROM,
  DOCWELL_SMTP_* and DOCWELL_S3_* settings into PocketBase, as the
  boot hook did.

It also replaces the hook's two routes: token checks use PocketBase's
auth-refresh (the organization name is read as the superuser), and
Docwell's own emails go out over SMTP from the server. PocketBase never
returns the SMTP password, so the server keeps a copy in the
superuser-only instance_settings collection; a password saved before
this change has to be entered once more in the admin panel.

Database/ keeps pb_migrations as the source of the schema;
export-schema.sh regenerates the snapshot from them. Database/Dockerfile
and pb_hooks are removed, the release no longer builds docwell-db, the
AIO image runs PocketBase without migrations or hooks, and the compose
files default DB_IMAGE to the stock image and pass the settings to the
server instead of the database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 20:09:38 +01:00

55 lines
1.7 KiB
Bash

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-or-later
# Starts PocketBase, docwell-server and docwell-web; exits when any of them stops.
set -eu
: "${PB_ADMIN_EMAIL:?PB_ADMIN_EMAIL is required}"
: "${PB_ADMIN_PASSWORD:?PB_ADMIN_PASSWORD is required}"
# Optional settings encryption; PocketBase needs exactly 32 characters.
ENC=""
if [ -n "${PB_ENCRYPTION_KEY:-}" ]; then
if [ "${#PB_ENCRYPTION_KEY}" -ne 32 ]; then
echo "PB_ENCRYPTION_KEY must be exactly 32 characters (got ${#PB_ENCRYPTION_KEY})" >&2
exit 1
fi
ENC="--encryptionEnv=PB_ENCRYPTION_KEY"
fi
# PocketBase runs stock: docwell-server applies Docwell's collections and the
# DOCWELL_* settings to it when it starts.
# shellcheck disable=SC2086 # $ENC is empty or one flag
pocketbase superuser upsert "$PB_ADMIN_EMAIL" "$PB_ADMIN_PASSWORD" --dir /pb_data $ENC
# shellcheck disable=SC2086
pocketbase serve --http 127.0.0.1:8070 --dir /pb_data $ENC &
PB_PID=$!
i=0
until wget -qO- http://127.0.0.1:8070/api/health >/dev/null 2>&1; do
i=$((i + 1))
[ "$i" -gt 50 ] && echo "PocketBase did not start" >&2 && exit 1
sleep 0.2
done
DOCWELL_ADDR=127.0.0.1:8080 \
DOCWELL_PB_URL=http://127.0.0.1:8070 \
DOCWELL_PB_EMAIL="$PB_ADMIN_EMAIL" \
DOCWELL_PB_PASSWORD="$PB_ADMIN_PASSWORD" \
docwell-server &
SERVER_PID=$!
# The web service proxies /api, /collab and /admin to the server, so only
# port 3000 is exposed.
DOCWELL_WEB_ADDR=0.0.0.0:3000 DOCWELL_PROXY_TARGET=http://127.0.0.1:8080 docwell-web &
WEB_PID=$!
trap 'kill $WEB_PID $SERVER_PID $PB_PID 2>/dev/null' INT TERM
# Exit as soon as any process dies so the container restarts as a whole.
while kill -0 $PB_PID && kill -0 $SERVER_PID && kill -0 $WEB_PID; do
sleep 2
done 2>/dev/null
kill $WEB_PID $SERVER_PID $PB_PID 2>/dev/null || true
exit 1