forked from mtusi2026/mtusi2026lab3
Lab3: track-1 results, failure/rolling/container evidence, report draft
This commit is contained in:
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/bin/sh
|
||||
# Build and test the committed revision from a separate clone with empty
|
||||
# volumes, then remove only that clone's containers, volumes, network and image.
|
||||
# The main stand is stopped (data kept) for the duration to avoid resource
|
||||
# contention, and restarted afterwards by the operator.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
root=$(pwd)
|
||||
revision=$(git rev-parse HEAD)
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "clean-clone-check: working tree is dirty; commit first" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
tmp=$(mktemp -d /tmp/mtusi-lab3-clean.XXXXXX)
|
||||
project=mtusi-lab3-melnikov-clean
|
||||
image=$project:local
|
||||
port=8084
|
||||
cleanup() {
|
||||
if [ -d "$tmp" ]; then
|
||||
(cd "$tmp" && COMPOSE_PROJECT_NAME=$project LB_PORT=$port IMAGE=$image \
|
||||
./scripts/compose.sh --env-file .env down -v --remove-orphans >/dev/null 2>&1 || true)
|
||||
docker image rm -f "$image" >/dev/null 2>&1 || true
|
||||
rm -rf "$tmp"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
echo "== clean clone =="
|
||||
echo "source revision: $revision"
|
||||
echo "clone: $tmp"
|
||||
echo "project: $project; LB port: $port"
|
||||
git clone --quiet "$root" "$tmp"
|
||||
cd "$tmp"
|
||||
test "$(git rev-parse HEAD)" = "$revision"
|
||||
|
||||
echo "== environment and validation =="
|
||||
./scripts/init-env.sh
|
||||
python3 - "$tmp/.env" "$port" <<'PY'
|
||||
import sys
|
||||
path, port = sys.argv[1], sys.argv[2]
|
||||
lines = []
|
||||
for line in open(path):
|
||||
if line.startswith('LB_PORT='):
|
||||
line = 'LB_PORT=%s\n' % port
|
||||
lines.append(line)
|
||||
open(path, 'w').writelines(lines)
|
||||
PY
|
||||
export COMPOSE_PROJECT_NAME=$project
|
||||
export LB_PORT=$port
|
||||
export IMAGE=$image
|
||||
export BASE_URL=http://127.0.0.1:$port
|
||||
export PYTHON=/usr/bin/python3
|
||||
make check
|
||||
/usr/bin/python3 -m venv .venv
|
||||
.venv/bin/python -m pip install -q -r requirements-dev.txt
|
||||
make validate PYTHON=.venv/bin/python
|
||||
|
||||
echo "== build and start from empty named volumes =="
|
||||
make up
|
||||
postgres=$(./scripts/compose.sh --env-file .env ps -q postgres)
|
||||
set -a; . ./.env; set +a
|
||||
docker exec -i "$postgres" psql -X -A -t -U "$POSTGRES_USER" -d "$POSTGRES_DB" \
|
||||
-c "SELECT 'users=' || count(*) FROM users;" \
|
||||
-c "SELECT 'migrations=' || string_agg(version::text, ',' ORDER BY version) FROM schema_migrations;"
|
||||
./scripts/compose.sh --env-file .env ps --format 'table {{.Name}}\t{{.Status}}'
|
||||
|
||||
echo "== public and own tests on the clean stand =="
|
||||
make test
|
||||
make test-student
|
||||
make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
||||
|
||||
echo "== intentional cleanup of this temporary clone's resources =="
|
||||
./scripts/compose.sh --env-file .env ps -q | wc -l
|
||||
make purge
|
||||
docker image rm -f "$image" >/dev/null 2>&1 || true
|
||||
if docker ps -aq --filter label=com.docker.compose.project=$project | grep -q .; then
|
||||
echo "clean-clone-check: containers remain" >&2
|
||||
exit 1
|
||||
fi
|
||||
if docker volume ls -q | grep -q "^${project}-"; then
|
||||
echo "clean-clone-check: volumes remain" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: clean clone built, migrated, tested and removed; main stand untouched"
|
||||
Reference in New Issue
Block a user