feat: add dev and prod deployment scaffolding
This commit is contained in:
37
scripts/deploy_stack.sh
Executable file
37
scripts/deploy_stack.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user