osint-dashboard/scripts/compose-reup.sh

75 lines
2.2 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
# Recreate selected OSINT compose services WITHOUT bouncing Postgres.
#
# The old path was `compose down` + up, which stopped osint-db on every merge
# even when Dockerfile.pg did not change. Name-pinned leftovers are still
# removed, but only for the services we are actually replacing.
#
# Usage: scripts/compose-reup.sh [compose-service ...]
# (default: app ingester camera-service news-scraper news-summarizer)
# Env: COMPOSE_PROJECT_NAME (default osint-dashboard)
# COMPOSE_PROFILES (default ingest)
# FORCE_RECREATE_DB=1 also recreate db
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
export COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-osint-dashboard}"
PROFILE="${COMPOSE_PROFILES:-ingest}"
DEFAULT_SVCS=(app ingester camera-service news-scraper news-summarizer)
if [ "$#" -gt 0 ]; then
SVCS=("$@")
else
SVCS=("${DEFAULT_SVCS[@]}")
fi
if [ "${FORCE_RECREATE_DB:-0}" = "1" ]; then
SVCS+=(db)
fi
# Never recreate db unless it was requested.
FILTERED=()
for svc in "${SVCS[@]}"; do
if [ "$svc" = "db" ] && [ "${FORCE_RECREATE_DB:-0}" != "1" ]; then
echo "compose-reup: skipping db (set FORCE_RECREATE_DB=1 to bounce Postgres)"
continue
fi
FILTERED+=("$svc")
done
SVCS=("${FILTERED[@]}")
declare -A CONTAINER_NAME=(
[app]=osint-dashboard
[ingester]=osint-ingester
[camera-service]=osint-camera-scraper
[news-scraper]=osint-news-scraper
[news-summarizer]=osint-news-summarizer
[db]=osint-db
[nats]=osint-nats
[titiler]=osint-titiler
)
echo "compose-reup: project=${COMPOSE_PROJECT_NAME} profile=${PROFILE} dir=${ROOT}"
echo "compose-reup: recreate=${SVCS[*]:-none}"
# Keep data-plane containers running (db / nats / titiler).
docker compose --profile "${PROFILE}" up -d --no-build --no-recreate db nats titiler || true
if [ "${#SVCS[@]}" -eq 0 ]; then
docker compose --profile "${PROFILE}" ps
exit 0
fi
for svc in "${SVCS[@]}"; do
c="${CONTAINER_NAME[$svc]:-}"
if [ -n "$c" ] && docker inspect "$c" >/dev/null 2>&1; then
echo "compose-reup: replacing ${c}"
docker rm -f "$c" >/dev/null
fi
done
docker compose --profile "${PROFILE}" up -d --no-build --no-deps "${SVCS[@]}"
docker compose --profile "${PROFILE}" ps