#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
PRIVATE_ROOT="$TEST_ROOT/private"
TMP_ROOT="$TEST_ROOT/tmp"

compose() {
  if docker compose version >/dev/null 2>&1; then
    docker compose "$@"
  else
    docker-compose "$@"
  fi
}

pushd "$TEST_ROOT" >/dev/null
compose down --remove-orphans
popd >/dev/null

rm -rf "$TMP_ROOT"
rm -rf "$PRIVATE_ROOT"

echo "[INFO] Master E2E environment cleaned up"
