Files
ss-tools/docker/backend.entrypoint.sh
busya 9228d071ef fix(translate): fix batch sizing — use real available input budget, respect job.batch_size, lazy playwright in docker
- _batch_sizer.py: compute per_batch_budget from actual available_input_budget
  (context_window - max_output_tokens) instead of sum of first N rows
- _batch_sizer.py: cap max_rows_hard_cap with job.batch_size (user config)
- _token_budget.py: add available_input_budget and max_output_tokens to return
- preview.py: validate required config fields before preview
- requirements-docker.txt: add playwright pip package (~5 MB)
- backend.entrypoint.sh: lazy playwright install chromium on first start
- build.sh: switch tar to tar.xz (-T0 -9), 5.5x smaller bundles
- README.md: add offline bundle deployment instructions
- playwright.config.js: add testMatch for *.e2e.js files
- frontend: preview tab config validation, i18n keys, translationRun store
2026-05-17 23:32:00 +03:00

79 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# [DEF:docker.backend.entrypoint:Module]
# @TIER: STANDARD
# @SEMANTICS: docker, entrypoint, admin-bootstrap, runtime, backend
# @PURPOSE: Container entrypoint that performs optional idempotent admin bootstrap before starting backend runtime.
# @LAYER: Infra
# @RELATION: DEPENDS_ON -> backend/src/scripts/create_admin.py
# @INVARIANT: Existing admin account must never be overwritten during container restarts.
# [/DEF:docker.backend.entrypoint:Module]
# [DEF:docker.backend.entrypoint.bootstrap_admin:Function]
# @PURPOSE: Execute optional initial admin bootstrap from runtime environment variables.
# @PRE: Python runtime and backend sources are available inside /app/backend.
# @POST: Admin is created only when INITIAL_ADMIN_CREATE=true and required credentials are present.
bootstrap_admin() {
local create_flag="${INITIAL_ADMIN_CREATE:-false}"
local username="${INITIAL_ADMIN_USERNAME:-}"
local password="${INITIAL_ADMIN_PASSWORD:-}"
local email="${INITIAL_ADMIN_EMAIL:-}"
case "${create_flag,,}" in
true|1|yes|y)
;;
*)
echo "[entrypoint] INITIAL_ADMIN_CREATE is disabled; skipping admin bootstrap"
return 0
;;
esac
if [[ -z "${username}" ]]; then
echo "[entrypoint] INITIAL_ADMIN_USERNAME is required when INITIAL_ADMIN_CREATE=true" >&2
return 1
fi
if [[ -z "${password}" ]]; then
echo "[entrypoint] INITIAL_ADMIN_PASSWORD is required when INITIAL_ADMIN_CREATE=true" >&2
return 1
fi
echo "[entrypoint] initializing auth database"
python3 src/scripts/init_auth_db.py
echo "[entrypoint] running idempotent admin bootstrap for user '${username}'"
if [[ -n "${email}" ]]; then
python3 src/scripts/create_admin.py --username "${username}" --password "${password}" --email "${email}"
else
python3 src/scripts/create_admin.py --username "${username}" --password "${password}"
fi
}
# [/DEF:docker.backend.entrypoint.bootstrap_admin:Function]
# [DEF:docker.backend.entrypoint.install_playwright:Function]
# @PURPOSE: Lazily install Playwright Chromium browser on first container start.
# Browser binaries (~377 MB) are downloaded only once and cached in
# PLAYWRIGHT_BROWSERS_PATH (default: ~/.cache/ms-playwright).
# Use a Docker volume or bind mount to persist across restarts:
# -v playwright_cache:/root/.cache/ms-playwright
install_playwright() {
local pw_dir="${PLAYWRIGHT_BROWSERS_PATH:-$HOME/.cache/ms-playwright}"
if [ -f "${pw_dir}/chromium-*/chrome-linux64/chrome" ]; then
echo "[entrypoint] Playwright Chromium already installed at ${pw_dir}"
return 0
fi
echo "[entrypoint] Installing Playwright Chromium browser (first start only)..."
echo "[entrypoint] This downloads ~377 MB. Use a volume to cache:"
echo " -v playwright_cache:/root/.cache/ms-playwright"
python3 -m playwright install chromium --with-deps 2>&1
echo "[entrypoint] Playwright Chromium installed successfully"
}
# [/DEF:docker.backend.entrypoint.install_playwright:Function]
install_playwright
bootstrap_admin
echo "[entrypoint] starting backend: $*"
exec "$@"