- Add comments about D-06 load order and YAML config path - Add warning if backend.yaml is missing - Remove any implied inventory.env dependencies
46 lines
2.0 KiB
Bash
Executable File
46 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# =============================================================================
|
|
# backend/entrypoint.sh
|
|
# =============================================================================
|
|
# Docker container entrypoint for TFM aInventory backend.
|
|
# Runs first-run initialization then starts the application server.
|
|
#
|
|
# This script is the ENTRYPOINT defined in backend/Dockerfile.
|
|
# DATA_DIR and LOGS_DIR are set via docker-compose.yml environment section.
|
|
# =============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
echo "🐳 [Docker] Backend container starting..."
|
|
echo "🐳 [Docker] DATA_DIR=${DATA_DIR:-/app/data}"
|
|
echo "🐳 [Docker] LOGS_DIR=${LOGS_DIR:-/app/logs}"
|
|
|
|
# Export defaults if not already set by docker-compose
|
|
export DATA_DIR="${DATA_DIR:-/app/data}"
|
|
export LOGS_DIR="${LOGS_DIR:-/app/logs}"
|
|
|
|
# [D-06] Configuration - Config is loaded from /app/config/ (YAML format)
|
|
# System environment variables override YAML config (D-06 load order).
|
|
# No inventory.env fallback is used by the backend application.
|
|
if [ ! -f "/app/config/backend.yaml" ]; then
|
|
echo "⚠️ [Docker] WARNING: /app/config/backend.yaml not found! Using defaults."
|
|
fi
|
|
|
|
# Run shared first-run initialization
|
|
echo "🐳 [Docker] Running data initialization..."
|
|
bash /app/scripts/init_data.sh
|
|
|
|
# Fix permissions for mounted volumes (which might be root-owned by the host)
|
|
echo "🐳 [Docker] Fixing volume permissions..."
|
|
chown -R appuser:appuser "${DATA_DIR}" "${LOGS_DIR}"
|
|
chmod -R 770 "${DATA_DIR}" "${LOGS_DIR}"
|
|
|
|
# Verify logic: Ensure appuser can actually write before we hand off
|
|
echo "🐳 [Docker] Verifying directory writability..."
|
|
gosu appuser touch "${LOGS_DIR}/.startup_test" && rm "${LOGS_DIR}/.startup_test"
|
|
gosu appuser touch "${DATA_DIR}/.startup_test" && rm "${DATA_DIR}/.startup_test"
|
|
|
|
# Hand off to the application server as non-root user
|
|
echo "🐳 [Docker] Starting uvicorn as appuser..."
|
|
exec gosu appuser python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000
|