56 lines
1.6 KiB
Bash
Executable File
56 lines
1.6 KiB
Bash
Executable File
#!/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 \
|
|
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}}' who-need-help:load-tools 2>/dev/null); then
|
|
if [ -z "$(docker ps -aq --filter "ancestor=$image_id")" ]; then
|
|
docker image rm who-need-help:load-tools >/dev/null
|
|
fi
|
|
fi
|
|
|
|
echo "Removed the isolated load-profile containers and networks; its named volumes remain."
|