77 lines
3.0 KiB
Bash
Executable File
77 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
suffix="$(date -u +%Y%m%d%H%M%S)-$(od -An -N4 -tx1 /dev/urandom | tr -d ' \n')"
|
|
project="heimdall-live-source-change-${suffix}"
|
|
temp_dir="$(mktemp -d "${TMPDIR:-/tmp}/${project}.XXXXXX")"
|
|
compose_file="${temp_dir}/compose.json"
|
|
source_archive="${temp_dir}/source.tar"
|
|
local_image_tags=()
|
|
|
|
if ! command -v docker >/dev/null 2>&1 || ! docker compose version >/dev/null 2>&1; then
|
|
printf 'Docker Compose is required for live source-change acceptance.\n' >&2
|
|
rmdir -- "$temp_dir"
|
|
exit 2
|
|
fi
|
|
|
|
cleanup() {
|
|
status=$?
|
|
trap - EXIT
|
|
cleanup_failed=0
|
|
if [[ -f "$compose_file" ]]; then
|
|
docker compose -p "$project" -f "$compose_file" down --volumes --remove-orphans >/dev/null 2>&1 || cleanup_failed=1
|
|
fi
|
|
containers="$(docker ps -aq --filter "label=com.docker.compose.project=${project}")" || cleanup_failed=1
|
|
volumes="$(docker volume ls -q --filter "label=com.docker.compose.project=${project}")" || cleanup_failed=1
|
|
networks="$(docker network ls -q --filter "label=com.docker.compose.project=${project}")" || cleanup_failed=1
|
|
[[ -z "$containers" && -z "$volumes" && -z "$networks" ]] || cleanup_failed=1
|
|
for tag in "${local_image_tags[@]}"; do
|
|
docker image rm "$tag" >/dev/null 2>&1 || true
|
|
docker image inspect "$tag" >/dev/null 2>&1 && cleanup_failed=1
|
|
done
|
|
rm -f -- "$compose_file" "$source_archive" || cleanup_failed=1
|
|
rmdir -- "$temp_dir" || cleanup_failed=1
|
|
if (( cleanup_failed )); then
|
|
printf 'Disposable acceptance cleanup failed for project %s\n' "$project" >&2
|
|
status=1
|
|
fi
|
|
exit "$status"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
python3 - "$compose_file" "$source_archive" <<'PY'
|
|
import json
|
|
import sys
|
|
|
|
compose_path, archive_path = sys.argv[1:]
|
|
test_command = """set -euo pipefail
|
|
mkdir -p /tmp/heimdall-source
|
|
tar -xf /source.tar -C /tmp/heimdall-source
|
|
cd /tmp/heimdall-source
|
|
dotnet restore tests/Heimdall.Agent.Tests/Heimdall.Agent.Tests.csproj --locked-mode
|
|
dotnet test tests/Heimdall.Agent.Tests/Heimdall.Agent.Tests.csproj --no-restore --configuration Release -m:1 --filter FullyQualifiedName~LiveCameraRelayServiceTests
|
|
"""
|
|
document = {
|
|
"services": {
|
|
"source-change-tests": {
|
|
"image": "mcr.microsoft.com/dotnet/sdk:10.0",
|
|
"entrypoint": ["bash", "-euc"],
|
|
"command": [test_command],
|
|
"volumes": [f"{archive_path}:/source.tar:ro"],
|
|
}
|
|
}
|
|
}
|
|
with open(compose_path, "w", encoding="utf-8") as compose_file:
|
|
json.dump(document, compose_file)
|
|
PY
|
|
|
|
# Archive only tracked and non-ignored working files; exclude multi-gigabyte
|
|
# ignored build/model outputs from the disposable SDK container.
|
|
git -C "$repo_root" ls-files -z --cached --others --exclude-standard |
|
|
tar -C "$repo_root" --null -T - -cf "$source_archive"
|
|
|
|
printf 'Project: %s\n' "$project"
|
|
printf 'Local images built: none (upstream .NET SDK image only)\n'
|
|
docker compose -p "$project" -f "$compose_file" up --abort-on-container-exit --exit-code-from source-change-tests
|