Files
mtusi2026lab6/Makefile
T
2026-11-17 13:08:13 +03:00

139 lines
4.0 KiB
Makefile

SHELL := /bin/bash
GO ?= go
PYTHON ?= python3
BASE_URL ?= http://localhost:18086
CA_FILE ?=
ACTION_SCRIPT ?=
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
OPENAPI_SPEC := contracts/openapi.json
GEN_OUTPUT := service/internal/gen/contracts/types.gen.go
GEN_PACKAGE := contracts
OAPI_CODEGEN ?= $(shell $(GO) env GOPATH)/bin/oapi-codegen
.PHONY: help check validate test load test-persistence test-failover openapi-generate certs key-gen create-dir gen-private-key gen-public-key gen-key gen-crt
help:
@echo "observe/prove-correlation/experiment-slo: telemetry evidence and SLO research"
@echo "up/down: lab6 async image pipeline; build/vet: Go checks"
@echo "test: lab6 API smoke; test-go/test-storage: Go checks"
@echo "restart/restore/rolling-update: infrastructure actions; benchmark/load: synthetic traffic"
@echo "check/validate: lab6 contracts; test-persistence/test-failover: explicit ACTION_SCRIPT hooks"
@echo "reconcile/reconcile-apply: storage consistency"
@echo "openapi-generate: generate types from lab6 contract; key-gen/certs: local keys"
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)
openapi-generate:
@mkdir -p $(dir $(GEN_OUTPUT))
@echo "Generating Go types from $(OPENAPI_SPEC)..."
@set -o pipefail; \
$(PYTHON) scripts/generate-types.py | \
$(OAPI_CODEGEN) -generate types -package $(GEN_PACKAGE) -o $(GEN_OUTPUT) /dev/stdin
key-gen: gen-public-key
create-dir:
@mkdir -p certs
gen-private-key: | create-dir
@openssl genrsa -out certs/private_key.pem 2048
gen-public-key: gen-private-key
@openssl rsa -in certs/private_key.pem -pubout -outform PEM -out certs/public_key.pem
certs: gen-crt
gen-key: | create-dir
@openssl genrsa -out ./certs/server.key 2048
gen-crt: gen-key
@openssl req -new -x509 -key ./certs/server.key -out ./certs/server.crt -days 365
.PHONY: up down test-go
up:
./scripts/bootstrap.sh
./scripts/compose.sh up -d --build --wait --wait-timeout 120
$(PYTHON) scripts/wait-ready.py
down:
./scripts/compose.sh down
test-go:
cd service && TEST_BASE_URL="$(BASE_URL)" $(GO) test -race -count=1 -v ./...
RATE ?= 100
DURATION ?= 30s
BENCH_ARGS ?=
.PHONY: build vet restart restore rolling-update benchmark test-storage
build:
cd service && $(GO) build ./...
@mkdir -p bin
cd service && $(GO) build -o ../bin/benchmark ./cmd/benchmark
vet:
cd service && $(GO) vet ./...
restart:
./scripts/restart.sh
restore:
./scripts/compose.sh up -d --wait --wait-timeout 90 --no-recreate api lb
rolling-update:
./scripts/rolling-update.sh
benchmark: build
./bin/benchmark -base-url "$(BASE_URL)" -rate "$(RATE)" -duration "$(DURATION)" $(BENCH_ARGS)
test-storage:
./scripts/test-storage.sh
.PHONY: reconcile reconcile-apply
reconcile:
./scripts/compose.sh run --rm -T operator storage reconcile
reconcile-apply:
./scripts/compose.sh run --rm -T operator storage reconcile --apply
.PHONY: test-pipeline
test-pipeline:
$(PYTHON) student-tests/pipeline.py --base-url "$(BASE_URL)" --repeats 3 --output evidence/pipeline.json
.PHONY: test-images test-staging
test-images:
$(PYTHON) student-tests/images.py
test-staging:
$(PYTHON) student-tests/storage.py
.PHONY: test-broker-persistence
test-broker-persistence:
$(PYTHON) student-tests/broker_persistence.py
.PHONY: observe prove-correlation experiment-slo
observe:
$(PYTHON) scripts/observations.py
prove-correlation:
$(PYTHON) scripts/prove-correlation.py
experiment-slo:
$(PYTHON) scripts/experiment-slo.py