97 lines
4.0 KiB
Bash
97 lines
4.0 KiB
Bash
#!/bin/sh
|
|
# P05-CI-03: disposable Gitea runner only. CI source, not a local developer command.
|
|
set -eu
|
|
|
|
: "${GITHUB_RUN_ID:?Gitea run ID is required for isolated project ownership}"
|
|
case "$GITHUB_RUN_ID" in
|
|
*[!0-9]*|'') echo 'Invalid numeric Gitea run ID' >&2; exit 1 ;;
|
|
esac
|
|
|
|
project="zitplane-p05-$GITHUB_RUN_ID"
|
|
network="zitplane-backend-dev-internal"
|
|
marker=".p05-ci-owned"
|
|
|
|
dc() {
|
|
docker compose --env-file .env -p "$project" \
|
|
-f deployment/docker/compose.backend.dev.yaml \
|
|
-f tests/ci/compose.portless.override.yaml "$@"
|
|
}
|
|
|
|
echo "ZITPLANE_BACKEND_PROJECT=$project"
|
|
docker --version
|
|
docker compose version
|
|
docker info --format 'Docker driver={{.Driver}}' >/dev/null
|
|
echo 'ZITPLANE_DOCKER_DAEMON_PREFLIGHT_PASS'
|
|
|
|
# Never take over an existing named network, project, or persistent volume.
|
|
if docker network inspect "$network" >/dev/null 2>&1; then
|
|
echo '::error::Fixed P02 network already exists; refusing to touch another stack'
|
|
exit 1
|
|
fi
|
|
if [ -n "$(docker ps -a -q --filter "label=com.docker.compose.project=$project")" ] ||
|
|
[ -n "$(docker volume ls -q --filter "label=com.docker.compose.project=$project")" ]; then
|
|
echo '::error::CI project containers/volumes already exist; refusing takeover'
|
|
exit 1
|
|
fi
|
|
for volume in "${project}_postgres-data" "${project}_zitadel-bootstrap"; do
|
|
if docker volume inspect "$volume" >/dev/null 2>&1; then
|
|
echo '::error::Existing CI-named volume; refusing takeover'
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# On a clean checkout the generated env must not already exist.
|
|
if [ -e .env ] || [ -e "$marker" ]; then
|
|
echo '::error::CI credentials or project marker already exist; refusing overwrite'
|
|
exit 1
|
|
fi
|
|
|
|
python3 -m unittest discover -s tests -p test_backend_dev.py -v
|
|
echo 'ZITPLANE_P02_BACKEND_CONTRACTS_PASS'
|
|
python3 core/backend/zitadel/dev.py init
|
|
dc config --quiet
|
|
dc config --format json |
|
|
python3 -c 'import json,sys; d=json.load(sys.stdin); required={"postgres","zitadel-api","zitadel-login","proxy"}; assert required==set(d["services"]), "Unexpected disposable services"; assert not d["services"]["proxy"].get("ports"), "CI proxy unexpectedly publishes host ports"; print("ZITPLANE_CI_PORTLESS_CONFIG_PASS")'
|
|
|
|
# Created only after the absence and effective-portless-config checks passed.
|
|
# The always() cleanup step must NEVER touch an unowned network.
|
|
touch "$marker"
|
|
dc up -d --wait
|
|
for service in postgres zitadel-api zitadel-login proxy; do
|
|
cid="$(dc ps -q "$service")"
|
|
if [ -z "$cid" ] || [ "$(docker inspect -f '{{.State.Running}}' "$cid")" != true ]; then
|
|
echo "::error::CI service not running: $service"
|
|
exit 1
|
|
fi
|
|
if [ "$service" != proxy ] &&
|
|
[ "$(docker inspect -f '{{.State.Health.Status}}' "$cid")" != healthy ]; then
|
|
echo "::error::CI service unhealthy: $service"
|
|
exit 1
|
|
fi
|
|
echo "ZITPLANE_SERVICE_RUNNING_PASS=$service"
|
|
done
|
|
echo 'ZITPLANE_FOUR_SERVICES_READY_PASS'
|
|
|
|
# Isolated persistence marker: disposable default 'postgres' database only.
|
|
dc exec -T postgres psql -U zitadel -d postgres -v ON_ERROR_STOP=1 \
|
|
-c 'CREATE TABLE IF NOT EXISTS public.zitplane_ci_persist(marker text PRIMARY KEY)'
|
|
dc exec -T postgres psql -U zitadel -d postgres -v ON_ERROR_STOP=1 \
|
|
-c "INSERT INTO public.zitplane_ci_persist(marker) VALUES ('p05-$project') ON CONFLICT DO NOTHING"
|
|
|
|
dc restart postgres
|
|
dc up -d --wait
|
|
result="$(dc exec -T postgres psql -U zitadel -d postgres -tAc \
|
|
"SELECT marker FROM public.zitplane_ci_persist WHERE marker = 'p05-$project' LIMIT 1")"
|
|
if [ "$result" != "p05-$project" ]; then
|
|
echo '::error::Postgres marker not retained across database restart'
|
|
exit 1
|
|
fi
|
|
echo 'ZITPLANE_POSTGRES_RESTART_PERSISTENCE_PASS'
|
|
|
|
# Read-only smoke inside the owned network; never publish a host HTTP port.
|
|
docker run --rm --network "$network" -e ZITPLANE_CI_PROXY=http://proxy \
|
|
python:3.12-alpine python -c "$(cat tests/ci/oidc_discovery.py)"
|
|
echo 'ZITPLANE_BACKEND_OIDC_READY_DISCOVERY_JWKS_PASS'
|
|
echo '::warning::Real user login, OIDC callback, Admin Console and MFA E2E remain DEFERRED'
|
|
echo 'ZITPLANE_BACKEND_ACCEPTANCE_CHECKS_PASS'
|