#!/bin/sh
set -eu

ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
ENV_FILE="$ROOT/.env.load"

if [ ! -f "$ENV_FILE" ]; then
  echo "Missing $ENV_FILE; no load-profile project was selected." >&2
  exit 1
fi

set -a
# shellcheck source=/dev/null
. "$ENV_FILE"
set +a

: "${LOAD_PROJECT:?LOAD_PROJECT is missing from .env.load}"

if [ "$LOAD_PROJECT" = who_need_help ]; then
  echo "Refusing to stop the staging Compose project." >&2
  exit 1
fi

cd "$ROOT"
docker compose \
  --env-file "$ENV_FILE" \
  -p "$LOAD_PROJECT" \
  -f compose.yaml \
  -f compose.load.yaml \
  stop

echo "Stopped the isolated load-profile containers; its database volume remains."
