Files
workdock-platform/scripts/deploy_stack.sh
2026-03-28 20:45:07 +01:00

38 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${1:-.env.prod}"
COMPOSE_FILE="${2:-docker-compose.prod.yml}"
HEALTH_URL="${DEPLOY_HEALTH_URL:-http://127.0.0.1:${APP_PORT:-8088}/healthz/}"
RUN_DJANGO_CHECK="${RUN_DJANGO_CHECK:-1}"
export APP_ENV_FILE="$ENV_FILE"
COMPOSE=(docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE")
if [[ ! -f "$ENV_FILE" ]]; then
echo "Missing env file: $ENV_FILE" >&2
exit 1
fi
"${COMPOSE[@]}" build web worker caddy
"${COMPOSE[@]}" up -d db redis
"${COMPOSE[@]}" run --rm web python manage.py migrate --noinput
"${COMPOSE[@]}" run --rm web python manage.py bootstrap_initial_users
"${COMPOSE[@]}" run --rm web python manage.py collectstatic --noinput
if [[ "$RUN_DJANGO_CHECK" == "1" ]]; then
"${COMPOSE[@]}" run --rm web python manage.py check
fi
"${COMPOSE[@]}" up -d web worker caddy
for i in $(seq 1 30); do
if curl --fail --silent --show-error --max-time 5 "$HEALTH_URL" >/dev/null; then
echo "Deployment healthy: $HEALTH_URL"
exit 0
fi
sleep 2
done
echo "Health check did not become ready in time: $HEALTH_URL" >&2
exit 1