1
0

entrypoint.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/sh
  2. set -eu
  3. mode="${1:-api}"
  4. # Ensure the SQLite data dir exists when DB_SQLITE_PATH is configured.
  5. if [ -n "${DB_SQLITE_PATH:-}" ]; then
  6. sqlite_dir="$(dirname "$DB_SQLITE_PATH")"
  7. mkdir -p "$sqlite_dir"
  8. fi
  9. case "$mode" in
  10. api)
  11. # Provision UI_SERVICE_TOKEN in api_tokens before serving. Idempotent;
  12. # logs a warning and skips if the env var is empty (early bring-up).
  13. cd /app
  14. php bin/console auth:bootstrap-service-token || \
  15. echo "warning: auth:bootstrap-service-token failed; continuing anyway" >&2
  16. exec frankenphp run --config /etc/Caddyfile
  17. ;;
  18. migrate)
  19. cd /app
  20. # Empty migrations dir is fine — phinx exits 0 with "no migrations to run".
  21. exec vendor/bin/phinx migrate --configuration=config/phinx.php
  22. ;;
  23. *)
  24. echo "Unknown mode: $mode" >&2
  25. echo "Usage: entrypoint.sh [api|migrate]" >&2
  26. echo "" >&2
  27. echo "To run an ad-hoc PHP command (e.g. 'php', 'composer', 'vendor/bin/phpunit')," >&2
  28. echo "bypass this dispatcher with '--entrypoint <bin>'. For example:" >&2
  29. echo " docker compose run --rm --entrypoint php api bin/console auth:create-token --kind=admin --role=admin" >&2
  30. exit 1
  31. ;;
  32. esac