forked from mtusi2026/mtusi2026lab7
Перенесены cmd/internal/config, compose.yaml, Dockerfile, скрипты, student-tests и evidence из mtusi-messenger (master, lab6). Skeleton lab7 (openapi/infrastructure 1.7.0, trust-matrix.md, security/THREAT_MODEL.md, infra/openbao, tests/security.py) сохранён; make test-security добавлен в Makefile.
205 lines
7.4 KiB
Makefile
205 lines
7.4 KiB
Makefile
PYTHON ?= python3
|
||
VERSION ?= $(shell git describe --always --dirty 2>/dev/null || echo dev)
|
||
export VERSION
|
||
# Lab1–lab6 base still serves plain HTTP on 8080; the lab7 implementation moves
|
||
# the stand to the contract default https://localhost:8443.
|
||
BASE_URL ?= http://localhost:8080
|
||
CA_FILE ?=
|
||
ACTION_SCRIPT ?=
|
||
PIPELINE ?= 2
|
||
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
|
||
PYTHON_LOCAL = env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 $(PYTHON)
|
||
|
||
.PHONY: help check validate test test-attachments test-presign load test-persistence test-failover test-security smoke-local load-local test-idempotency test-lb-readiness test-observability test-slo up up-base init-secrets down ps logs
|
||
|
||
help:
|
||
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
|
||
@echo "up: lab6 stand with telemetry profile; up-base: lab5 regression without telemetry"
|
||
@echo "down/ps/logs: same profile; test-observability/test-slo: lab6 checks"
|
||
|
||
check:
|
||
$(PYTHON) scripts/check_contract.py
|
||
$(PYTHON) scripts/check_s3_creds.py
|
||
|
||
validate:
|
||
$(PYTHON) scripts/validate_openapi.py
|
||
|
||
test:
|
||
$(PYTHON_LOCAL) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
test-attachments:
|
||
$(PYTHON_LOCAL) student-tests/attachments_negative.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
test-presign:
|
||
$(PYTHON_LOCAL) student-tests/presign_flow.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
test-queue:
|
||
$(PYTHON_LOCAL) student-tests/lab5_async.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
test-faults:
|
||
$(PYTHON_LOCAL) student-tests/lab5_faults.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
test-track2:
|
||
$(PYTHON_LOCAL) scripts/lab5_track2.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
# Lab6 observability and SLO checks (stand must be running with the telemetry profile).
|
||
test-observability:
|
||
$(PYTHON_LOCAL) scripts/check_evidence.py
|
||
$(PYTHON_LOCAL) scripts/lab6_verify.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
test-slo:
|
||
$(PYTHON_LOCAL) scripts/lab6_track2.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
load:
|
||
$(PYTHON_LOCAL) 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_LOCAL) 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_LOCAL) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
# Lab7: external endpoint must reject an untrusted CA; internal mTLS is checked
|
||
# by the student's own tests per contracts/trust-matrix.md.
|
||
test-security:
|
||
$(PYTHON_LOCAL) tests/security.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
# Локальный запуск без прокси: в окружении автора HTTP(S)_PROXY ломает localhost.
|
||
smoke-local:
|
||
$(PYTHON_LOCAL) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
load-local:
|
||
$(PYTHON_LOCAL) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
# Собственная проверка уровня 4: параллельные повторы одного Idempotency-Key
|
||
# через LB обязаны создать ровно одно сообщение.
|
||
test-idempotency:
|
||
$(PYTHON_LOCAL) student-tests/idempotency_parallel.py --base-url "$(BASE_URL)" $(TLS_ARGS)
|
||
|
||
# Собственная проверка уровня 4: LB обязан убрать из ротации реплику, которая
|
||
# осталась доступной, но потеряла БД (readiness 503).
|
||
test-lb-readiness:
|
||
scripts/lb_readiness_check.sh
|
||
|
||
COMPOSE_BIN ?= docker compose
|
||
COMPOSE_FILE ?= compose.yaml
|
||
ENV_FILE ?= .env
|
||
|
||
TELEMETRY_PROFILE ?= telemetry
|
||
|
||
up: init-secrets
|
||
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) --profile $(TELEMETRY_PROFILE) up -d --build
|
||
|
||
# Lab5 regression without the telemetry profile.
|
||
up-base: init-secrets
|
||
TELEMETRY_ENABLED=0 $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) up -d --build
|
||
|
||
init-secrets:
|
||
./scripts/init-secrets.sh
|
||
|
||
down:
|
||
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) --profile $(TELEMETRY_PROFILE) down
|
||
|
||
ps:
|
||
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) --profile $(TELEMETRY_PROFILE) ps
|
||
|
||
logs:
|
||
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) --profile $(TELEMETRY_PROFILE) logs -f --tail 100
|
||
|
||
# Operator views: the failed registry is PostgreSQL, the DLQ is a backstop.
|
||
jobs-failed:
|
||
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker failed
|
||
|
||
replay:
|
||
@test -n "$(JOB)" || (echo "Set JOB=<job_id>"; exit 2)
|
||
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker replay -job "$(JOB)"
|
||
|
||
reprocess:
|
||
@test -n "$(ATTACHMENT)" || (echo "Set ATTACHMENT=<attachment_id>"; exit 2)
|
||
$(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker reprocess -attachment "$(ATTACHMENT)" -pipeline "$(PIPELINE)"
|
||
|
||
.DEFAULT_GOAL := help
|
||
GO ?= go
|
||
APP_NAME ?= messenger
|
||
CMD_PKG := ./cmd/$(APP_NAME)
|
||
LOCAL_BIN := $(CURDIR)/bin
|
||
GOLANGCI_LINT_VERSION ?= v2.13.2
|
||
GOLANGCI_LINT := $(LOCAL_BIN)/golangci-lint
|
||
OPENAPI_SPEC := contracts/openapi.json
|
||
OGEN_CONFIG := .ogen.yml
|
||
OAS_DIR := internal/transport/rest/internal/oas
|
||
|
||
-include .env
|
||
export
|
||
|
||
# .env feeds local tooling, but its application variables must not leak into the
|
||
# Go test process: the config tests assert defaults and the dev YAML, so an
|
||
# ambient REDIS_ENABLED/CACHE_ENABLED would fail them.
|
||
ENV_KEYS := $(shell sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p' .env 2>/dev/null)
|
||
CLEAN_ENV = env $(addprefix -u ,$(ENV_KEYS))
|
||
|
||
.PHONY: unit-test
|
||
unit-test:
|
||
$(CLEAN_ENV) $(GO) test -race -shuffle=on -count=1 -timeout=5m ./...
|
||
|
||
.PHONY: integration-test
|
||
integration-test:
|
||
$(GO) test -tags=integration -p 1 -count=1 -timeout=15m ./internal/storage/postgres ./internal/storage/redis
|
||
|
||
.PHONY: test-db-up test-db-down
|
||
test-db-up:
|
||
@docker-compose -f docker-compose.local.yaml up -d --wait postgres redis
|
||
|
||
test-db-down:
|
||
@docker-compose -f docker-compose.local.yaml down
|
||
|
||
# не учитываем генеренные файлы, также cmd в подсчете покрытия
|
||
COVER_EXCLUDE ?= /(mocks|oas)/|/cmd/
|
||
|
||
.PHONY: cover
|
||
cover:
|
||
$(CLEAN_ENV) $(GO) test -race -shuffle=on -count=1 -timeout=5m \
|
||
-covermode=atomic -coverprofile=coverage.out.tmp ./...
|
||
@grep -Ev '$(COVER_EXCLUDE)' coverage.out.tmp > coverage.out
|
||
@rm coverage.out.tmp
|
||
$(GO) tool cover -func=coverage.out | tail -n 1
|
||
$(GO) tool cover -html=coverage.out
|
||
|
||
.PHONY: generate
|
||
generate: generate-api generate-mocks sqlc
|
||
|
||
.PHONY: generate-api
|
||
generate-api:
|
||
$(GO) run ./tools/specgen
|
||
$(GO) tool ogen --config $(OGEN_CONFIG) --target $(OAS_DIR) --package oas --clean .cache/openapi.codegen.json
|
||
|
||
.PHONY: generate-mocks
|
||
generate-mocks:
|
||
$(GO) tool mockery
|
||
|
||
.PHONY: sqlc
|
||
sqlc:
|
||
$(GO) tool sqlc generate
|
||
|
||
.PHONY: dev-up dev-down dev-reload
|
||
dev-up:
|
||
@docker-compose -f docker-compose.local.yaml up -d --build
|
||
|
||
dev-down:
|
||
@docker-compose -f docker-compose.local.yaml down
|
||
|
||
dev-reload:
|
||
@docker-compose -f docker-compose.local.yaml up -d --build --force-recreate
|
||
|
||
.PHONY: migrate
|
||
migrate:
|
||
$(GO) run ./cmd/migrate up
|
||
|
||
$(GOLANGCI_LINT):
|
||
GOBIN=$(LOCAL_BIN) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
|
||
|
||
lint: $(GOLANGCI_LINT)
|
||
$(GOLANGCI_LINT) run -v
|