forked from mtusi2026/mtusi2026lab2
141 lines
4.4 KiB
Makefile
141 lines
4.4 KiB
Makefile
SHELL_PORTS := $(foreach v,API_PORT SHORTTTL_PORT,$(if $(filter environment,$(origin $v)),$v=$($v)))
|
|
-include .env
|
|
$(foreach port,$(SHELL_PORTS),$(eval $(port)))
|
|
|
|
PYTHON ?= python3
|
|
BASE_URL ?= http://localhost:$(or $(API_PORT),8080)
|
|
CA_FILE ?=
|
|
ACTION_SCRIPT ?=
|
|
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
|
|
|
VENV ?= .venv
|
|
UV ?= uv
|
|
COMPOSE ?= docker compose
|
|
PSQL = $(COMPOSE) exec -T postgres psql -U messenger -d messenger -X -q
|
|
SHORTTTL_PORT ?= 8082
|
|
PYTEST_ARGS ?=
|
|
TRACK_ARGS ?=
|
|
SHORTTTL_URL ?= http://localhost:$(SHORTTTL_PORT)
|
|
|
|
.PHONY: help check validate test load test-persistence \
|
|
install lint format typecheck student-test \
|
|
secrets up down reset-data migrate ps logs persistence-evidence storage-evidence cache-evidence test-faults seed explain track-bench track-recovery \
|
|
migrations-evidence environment-evidence sigterm-evidence load-evidence toolchain-evidence faults-evidence
|
|
|
|
help:
|
|
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
|
@echo "install/lint/typecheck/student-test: студенческий тулчейн"
|
|
@echo "secrets/up/down/migrate/ps/logs: стенд Docker Compose; reset-data: намеренное удаление volumes"
|
|
|
|
check:
|
|
$(PYTHON) scripts/check_contract.py
|
|
|
|
validate: PYTHON := $(if $(wildcard $(VENV)/bin/python),$(VENV)/bin/python,$(PYTHON))
|
|
validate:
|
|
$(PYTHON) scripts/validate_openapi.py
|
|
|
|
test:
|
|
$(PYTHON) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
load:
|
|
$(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
test-persistence:
|
|
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2)
|
|
$(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
|
|
|
install:
|
|
$(UV) sync --group dev
|
|
|
|
lint:
|
|
$(VENV)/bin/ruff check src student-tests scripts/track.py
|
|
$(VENV)/bin/ruff format --check src student-tests scripts/track.py
|
|
$(VENV)/bin/ty check src student-tests
|
|
|
|
format:
|
|
$(VENV)/bin/ruff check --fix src student-tests scripts/track.py
|
|
$(VENV)/bin/ruff format src student-tests scripts/track.py
|
|
|
|
typecheck:
|
|
$(VENV)/bin/ty check src student-tests
|
|
|
|
student-test:
|
|
$(VENV)/bin/pytest $(PYTEST_ARGS)
|
|
|
|
secrets:
|
|
sh scripts/secrets.sh
|
|
|
|
up: secrets
|
|
$(COMPOSE) up -d --build --wait
|
|
|
|
down:
|
|
$(COMPOSE) --profile faults --profile track down
|
|
|
|
reset-data:
|
|
@echo "Удаляются volumes с учебными данными стенда"
|
|
$(COMPOSE) --profile faults --profile track down -v --remove-orphans
|
|
|
|
migrate:
|
|
$(COMPOSE) run --rm migrate
|
|
|
|
ps:
|
|
$(COMPOSE) ps
|
|
|
|
logs:
|
|
$(COMPOSE) logs --tail 200
|
|
|
|
persistence-evidence:
|
|
sh scripts/persistence-evidence.sh "$(BASE_URL)" > evidence/persistence.txt
|
|
cat evidence/persistence.txt
|
|
|
|
storage-evidence:
|
|
sh scripts/evidence-storage.sh
|
|
|
|
cache-evidence:
|
|
sh scripts/evidence-cache.sh > evidence/cache.txt
|
|
cat evidence/cache.txt
|
|
|
|
migrations-evidence:
|
|
@echo "Удаляются volumes с учебными данными стенда: миграции применяются к пустой БД"
|
|
sh scripts/evidence-migrations.sh "$(BASE_URL)" > evidence/migrations.txt
|
|
cat evidence/migrations.txt
|
|
|
|
environment-evidence:
|
|
sh scripts/evidence-environment.sh > evidence/environment.txt
|
|
cat evidence/environment.txt
|
|
|
|
sigterm-evidence:
|
|
sh scripts/evidence-sigterm.sh "$(BASE_URL)" > evidence/sigterm.txt
|
|
cat evidence/sigterm.txt
|
|
|
|
load-evidence:
|
|
sh scripts/evidence-load.sh "$(BASE_URL)" > evidence/load.txt
|
|
cat evidence/load.txt
|
|
|
|
toolchain-evidence:
|
|
sh scripts/evidence-toolchain.sh "$(BASE_URL)"
|
|
|
|
test-faults:
|
|
$(COMPOSE) --profile faults up -d --wait api-shortttl
|
|
BASE_URL="$(BASE_URL)" SHORTTTL_URL="$(SHORTTTL_URL)" $(VENV)/bin/pytest -m stack -v -s student-tests/stack
|
|
|
|
faults-evidence:
|
|
{ echo "date: $$(date -u +%FT%TZ) commit: $$(git rev-parse --short HEAD)"; echo "\$$ make test-faults"; \
|
|
$(MAKE) --no-print-directory test-faults 2>&1; } > evidence/faults.txt
|
|
cat evidence/faults.txt
|
|
|
|
seed:
|
|
$(PSQL) -f - < scripts/sql/seed-history.sql
|
|
|
|
explain: seed
|
|
{ echo "date: $$(date -u +%FT%TZ) commit: $$(git rev-parse --short HEAD)"; \
|
|
echo "\$$ make explain # scripts/sql/explain-history.sql"; \
|
|
$(PSQL) -f - < scripts/sql/explain-history.sql; } > evidence/explain-history.txt
|
|
cat evidence/explain-history.txt
|
|
|
|
track-bench:
|
|
$(PYTHON) scripts/track.py bench $(TRACK_ARGS)
|
|
|
|
track-recovery:
|
|
$(PYTHON) scripts/track.py recovery $(TRACK_ARGS)
|