GO ?= go PYTHON ?= python3 COMPOSE ?= docker compose ENV_FILE ?= .env BASE_URL ?= http://localhost:8080 CA_FILE ?= ACTION_SCRIPT ?= TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",) COMPOSE_CMD = $(COMPOSE) --env-file "$(ENV_FILE)" .PHONY: \ help \ init-env \ fmt \ fmt-check \ build \ go-test \ go-race \ go-vet \ go-check \ check \ validate \ test \ load \ test-persistence \ test-failover \ compose-config \ compose-build \ compose-up \ compose-down \ compose-ps \ compose-logs help: @echo "init-env: create local .env from .env.example if missing" @echo "fmt: format Go source files" @echo "fmt-check: report unformatted Go source files" @echo "build: compile the API" @echo "go-test: run Go tests" @echo "go-race: run Go tests with race detector" @echo "go-vet: run static Go analysis" @echo "go-check: run formatting, tests, race detector and vet" @echo "check: run offline skeleton checks" @echo "validate: validate the OpenAPI contract" @echo "test: run public smoke test against the LB entrypoint" @echo "load: run synthetic writes against the LB entrypoint" @echo "test-persistence: run persistence test with ACTION_SCRIPT" @echo "test-failover: run replica failover test with ACTION_SCRIPT" @echo "compose-config: validate resolved Compose configuration" @echo "compose-build: build application images" @echo "compose-up: start the stack" @echo "compose-down: stop the stack without deleting volumes" @echo "compose-ps: show stack containers" @echo "compose-logs: follow stack logs" init-env: @if [ -f "$(ENV_FILE)" ]; then \ echo "$(ENV_FILE) already exists; leaving it unchanged"; \ else \ cp .env.example "$(ENV_FILE)"; \ echo "Created $(ENV_FILE) from .env.example"; \ fi fmt: $(GO) fmt ./... fmt-check: @files="$$(find cmd internal student_tests -type f -name '*.go' -print)"; \ unformatted="$$(gofmt -l $$files)"; \ if [ -n "$$unformatted" ]; then \ echo "Unformatted Go files:"; \ echo "$$unformatted"; \ exit 1; \ fi build: $(GO) build ./cmd/server go-test: $(GO) test ./... go-race: $(GO) test -race ./... go-vet: $(GO) vet ./... go-check: fmt-check go-test go-race go-vet check: $(PYTHON) scripts/check_contract.py 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) test-failover: @test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2) $(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS) compose-config: @test -f "$(ENV_FILE)" || \ (echo "$(ENV_FILE) is missing; run: make init-env"; exit 2) $(COMPOSE_CMD) config --quiet compose-build: $(COMPOSE_CMD) build compose-up: $(COMPOSE_CMD) up -d --build compose-down: $(COMPOSE_CMD) down compose-ps: $(COMPOSE_CMD) ps compose-logs: $(COMPOSE_CMD) logs --follow