#!/bin/sh set -eu ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) ENV_FILE=${WNH_LOAD_ENV_FILE:-"$ROOT/.env.load"} LOAD_TOOLS_IMAGE=${WNH_LOAD_TOOLS_IMAGE:-who-need-help:load-tools} 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 \ down --remove-orphans # Optional observability and backup overlays create additional networks which # are not present in the base load Compose file. Remove only unattached # networks carrying this exact isolated project label. for network_id in $(docker network ls -q \ --filter "label=com.docker.compose.project=$LOAD_PROJECT"); do observed_project=$(docker network inspect --format \ '{{index .Labels "com.docker.compose.project"}}' "$network_id") endpoints=$(docker network inspect --format '{{len .Containers}}' "$network_id") if [ "$observed_project" != "$LOAD_PROJECT" ] || [ "$endpoints" != 0 ]; then echo "Refusing unexpected or connected load-profile network: $network_id" >&2 exit 1 fi docker network rm "$network_id" >/dev/null done if image_id=$(docker image inspect --format '{{.Id}}' "$LOAD_TOOLS_IMAGE" 2>/dev/null); then if [ -z "$(docker ps -aq --filter "ancestor=$image_id")" ]; then docker image rm "$LOAD_TOOLS_IMAGE" >/dev/null fi fi echo "Removed the isolated load-profile containers and networks; its named volumes remain."