forked from mtusi2026/mtusi2026lab4
Preserve evidence runs and volumes while propagating failures
This commit is contained in:
+49
-51
@@ -1,55 +1,53 @@
|
||||
#!/bin/sh
|
||||
set -u
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
repo=$PWD
|
||||
dir="${CLONE_DIR:-$(dirname "$repo")/mtusi2026lab4-clean}"
|
||||
out="$repo/evidence/clean-clone.txt"
|
||||
branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
project=$(basename "$dir")
|
||||
[ -e "$dir" ] && { echo "$dir уже существует" >&2; exit 2; }
|
||||
step() {
|
||||
echo "\$ $*"
|
||||
sh -c "$*" 2>&1 | sed "s#$dir#<clone>#g"
|
||||
}
|
||||
look() {
|
||||
echo "\$ $* # наблюдение, не шаг инструкции"
|
||||
sh -c "$*" 2>&1 | sed "s#$dir#<clone>#g"
|
||||
}
|
||||
{
|
||||
echo "date: $(date -u +%FT%TZ) commit: $(git rev-parse --short HEAD) dir: $project (свой compose-проект и volumes)"
|
||||
echo "# make clean-clone-evidence (scripts/clean-clone.sh): команды блока «Запуск из чистого clone» REPORT.md по очереди"
|
||||
echo "# с сырым выводом; строки «наблюдение» — проверки между шагами"
|
||||
echo "\$ git clone <repo> $project && cd $project && git checkout $branch"
|
||||
git clone -q "$repo" "$dir" && cd "$dir" && git checkout -q "$branch" && git log -1 --format='HEAD %h %s'
|
||||
look "docker volume ls -q --filter label=com.docker.compose.project=$project | wc -l | tr -d ' '"
|
||||
step "make secrets"
|
||||
if [ -n "${LB_HTTP_PORT:-}" ]; then
|
||||
echo "\$ sed LB_HTTP_PORT=$LB_HTTP_PORT LB_STATS_PORT=${LB_STATS_PORT:-8404} .env # отступление: 8080 занят стендами других лаб"
|
||||
sed -i.bak "s/^LB_HTTP_PORT=.*/LB_HTTP_PORT=$LB_HTTP_PORT/; s/^LB_STATS_PORT=.*/LB_STATS_PORT=${LB_STATS_PORT:-8404}/" .env && rm -f .env.bak
|
||||
project="hlpipe-lab4-clean-$(date -u +%Y%m%d%H%M%S)"
|
||||
dir="$repo/.verification/$project"
|
||||
out="$repo/${EVIDENCE_DIR:-evidence}/clean-clone.txt"
|
||||
sha=$(git rev-parse HEAD)
|
||||
[ ! -e "$out" ] || { echo "Choose a new EVIDENCE_DIR" >&2; exit 2; }
|
||||
mkdir -p "$(dirname "$dir")" "$(dirname "$out")"
|
||||
exec 3>&1
|
||||
exec > "$out" 2>&1
|
||||
cleanup() {
|
||||
status=$?
|
||||
trap - EXIT HUP INT TERM
|
||||
if [ -d "$dir/.git" ]; then
|
||||
cd "$dir"
|
||||
docker compose --profile bench --profile tools --profile reconcile down || status=1
|
||||
docker volume ls --filter "label=com.docker.compose.project=$project"
|
||||
fi
|
||||
look "git status --short --ignored secrets .env"
|
||||
step "docker compose --env-file .env config --quiet && echo valid"
|
||||
started=$(date +%s)
|
||||
step "make up"
|
||||
echo "make up: $(( $(date +%s) - started )) s"
|
||||
look "docker compose ps -a --format '{{.Service}} {{.State}} {{.Status}} {{.Ports}}'"
|
||||
look "docker compose logs --no-log-prefix migrate s3-init | grep -v '^\$' | tail -6"
|
||||
look "curl -s \"http://\$(docker compose port lb 8404)/stats;csv\" | awk -F, '\$1 == \"api\" && \$2 != \"BACKEND\" {print \$2, \$18}' | grep -v MAINT"
|
||||
step "make test"
|
||||
step "make test-persistence ACTION_SCRIPT=scripts/restart.sh"
|
||||
look "docker compose ps -a --format '{{.Service}} {{.State}} {{.RunningFor}} {{.Status}}'"
|
||||
step "make test-failover ACTION_SCRIPT=scripts/stop-one.sh"
|
||||
look "docker compose ps -a --format '{{.Service}} {{.Name}} {{.State}} {{.Status}}' api"
|
||||
step "make restore"
|
||||
step "make scenario SCENARIO=failover-upload"
|
||||
step "make scenario SCENARIO=s3-outage"
|
||||
step "make s3-check"
|
||||
step "make reconcile"
|
||||
step "make migrate"
|
||||
look "docker volume ls --format '{{.Name}}' --filter label=com.docker.compose.project=$project"
|
||||
step "make down"
|
||||
look "docker volume ls --format '{{.Name}}' --filter label=com.docker.compose.project=$project"
|
||||
step "make reset-data"
|
||||
look "docker volume ls -q --filter label=com.docker.compose.project=$project | wc -l | tr -d ' '"
|
||||
} > "$out"
|
||||
cat "$out"
|
||||
echo "exit_code: $status; volumes retained"
|
||||
sed "s#$repo#<repo>#g" "$out" >&3
|
||||
exit "$status"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
trap 'exit 130' HUP INT TERM
|
||||
step() { echo "\$ $*"; "$@"; }
|
||||
export COMPOSE_PROJECT_NAME="$project" COMPOSE_FILE=compose.yaml
|
||||
export LB_HTTP_PORT=18084 LB_STATS_PORT=24845 BASE_URL=http://127.0.0.1:18084
|
||||
export NO_PROXY=localhost,127.0.0.1,::1
|
||||
unset API_IMAGE
|
||||
echo "date: $(date -u +%FT%TZ) commit: $sha project: $project"
|
||||
echo "HTTP=$LB_HTTP_PORT stats=$LB_STATS_PORT"
|
||||
step git clone --quiet --no-hardlinks "$repo" "$dir"
|
||||
cd "$dir"
|
||||
step git checkout --quiet --detach "$sha"
|
||||
step make secrets
|
||||
step docker compose --env-file .env config --quiet
|
||||
step make up
|
||||
step docker compose ps -a --format '{{.Service}} {{.State}} {{.Status}} {{.Ports}}'
|
||||
step make test
|
||||
step make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
||||
step make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
step docker compose ps -a --format '{{.Service}} {{.Name}} {{.State}}' api
|
||||
step make restore
|
||||
step make scenario SCENARIO=failover-upload
|
||||
step make restore
|
||||
step make scenario SCENARIO=s3-outage
|
||||
step sh scripts/s3-check.sh
|
||||
step make reconcile
|
||||
step make migrate
|
||||
step make down
|
||||
step docker volume ls --filter "label=com.docker.compose.project=$project"
|
||||
|
||||
Reference in New Issue
Block a user