177 lines
8.0 KiB
Makefile
177 lines
8.0 KiB
Makefile
SHELL := /usr/bin/env bash
|
|
.DEFAULT_GOAL := help
|
|
|
|
ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
|
|
|
NAMESPACE ?= fch26-onemanarmy
|
|
CONTEXT ?= fch26-onemanarmy-sa-context
|
|
KUBECTL ?= kubectl --context $(CONTEXT) --namespace $(NAMESPACE)
|
|
KUBECONFORM ?= kubeconform
|
|
PYTHON ?= python3
|
|
|
|
REGISTRY ?= git.noelsabia.dev
|
|
OWNER ?= noelsabia
|
|
TAG ?= gate1
|
|
WEB_IMAGE ?= $(REGISTRY)/$(OWNER)/pulsecast-web:$(TAG)
|
|
API_IMAGE ?= $(REGISTRY)/$(OWNER)/pulsecast-api:$(TAG)
|
|
ML_IMAGE ?= $(REGISTRY)/$(OWNER)/pulsecast-ml:$(TAG)
|
|
|
|
# Service checkouts live beside the main checkout or in per-task worktrees:
|
|
# Hackathon_2026/worktrees/<repo>/<branch>
|
|
# Override any *_DIR on the command line when the layout differs.
|
|
SERVICES_ROOT ?= $(if $(wildcard $(abspath $(ROOT)/../../..)/worktrees),$(abspath $(ROOT)/../../..),$(abspath $(ROOT)/..))
|
|
WEB_DIR ?= $(or $(firstword $(wildcard $(SERVICES_ROOT)/worktrees/web-nuxt/*) $(wildcard $(SERVICES_ROOT)/web-nuxt)),$(SERVICES_ROOT)/web-nuxt)
|
|
API_DIR ?= $(or $(firstword $(wildcard $(SERVICES_ROOT)/worktrees/api-go/*) $(wildcard $(SERVICES_ROOT)/api-go)),$(SERVICES_ROOT)/api-go)
|
|
ML_DIR ?= $(or $(firstword $(wildcard $(SERVICES_ROOT)/worktrees/ML-py/*) $(wildcard $(SERVICES_ROOT)/ML-py)),$(SERVICES_ROOT)/ML-py)
|
|
|
|
WEB_URL ?= https://pulse.noelsabia.dev
|
|
API_URL ?= https://api.pulse.noelsabia.dev
|
|
ML_URL ?=
|
|
LOAD_API_URL ?= $(API_URL)
|
|
SMOKE_SSE ?= 0
|
|
SKIP_ML ?= 0
|
|
|
|
SSE_VUS ?= 120
|
|
SSE_HOLD_PINGS ?= 20
|
|
SSE_MAX_DURATION ?= 6m
|
|
K6 ?=
|
|
K6_BIN ?= $(ROOT)/k6/k6-sse
|
|
K6_SCRIPT := $(ROOT)/k6/sse.js
|
|
K6_RESULTS := $(ROOT)/k6/results
|
|
|
|
.PHONY: help validate validate-kubeconform build build-web build-api build-ml push push-web push-api push-ml set-image deploy deploy-check status logs smoke smoke-local load k6-build secret-commands clean
|
|
|
|
help: ## Show available targets
|
|
@awk 'BEGIN {FS = ":.*## "} /^[a-zA-Z0-9_-]+:.*## / {printf " %-22s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
|
|
|
validate: ## Validate deploy/k8s read-only (schema when possible, never applies)
|
|
@set -e; \
|
|
if command -v "$(KUBECONFORM)" >/dev/null 2>&1; then \
|
|
echo "== kubeconform (strict, offline schemas)"; \
|
|
"$(KUBECONFORM)" -strict -summary -ignore-missing-schemas "$(ROOT)/deploy/k8s"; \
|
|
elif command -v kubectl >/dev/null 2>&1 && kubectl cluster-info >/dev/null 2>&1; then \
|
|
echo "== kubectl client dry-run (read-only)"; \
|
|
kubectl apply --dry-run=client -f "$(ROOT)/deploy/k8s"; \
|
|
else \
|
|
echo "== YAML syntax only: kubeconform is not installed and no cluster is reachable"; \
|
|
"$(PYTHON)" -c "import glob, yaml; docs=[d for f in sorted(glob.glob('$(ROOT)/deploy/k8s/*.yaml')) for d in yaml.safe_load_all(open(f)) if d]; assert all(isinstance(d, dict) and d.get('apiVersion') and d.get('kind') for d in docs), 'manifest missing apiVersion/kind'; print(f'{len(docs)} manifests parsed')"; \
|
|
echo "Install kubeconform for schema validation: go install github.com/yannh/kubeconform/cmd/kubeconform@latest"; \
|
|
fi
|
|
|
|
validate-kubeconform: ## Validate schemas with kubeconform (must be installed)
|
|
@command -v "$(KUBECONFORM)" >/dev/null 2>&1 || { echo "kubeconform not found; go install github.com/yannh/kubeconform/cmd/kubeconform@latest"; exit 1; }
|
|
"$(KUBECONFORM)" -strict -summary -ignore-missing-schemas "$(ROOT)/deploy/k8s"
|
|
|
|
build: build-web build-api build-ml ## Build all three images locally
|
|
|
|
build-web: ## Build the web image
|
|
@test -n "$(WEB_DIR)" || { echo "WEB_DIR is empty"; exit 1; }
|
|
@test -f "$(WEB_DIR)/Dockerfile" || { echo "missing $(WEB_DIR)/Dockerfile (see docs/deploy.md, Dockerfile contract)"; exit 1; }
|
|
docker build -t "$(WEB_IMAGE)" "$(WEB_DIR)"
|
|
|
|
build-api: ## Build the api image
|
|
@test -n "$(API_DIR)" || { echo "API_DIR is empty"; exit 1; }
|
|
@test -f "$(API_DIR)/Dockerfile" || { echo "missing $(API_DIR)/Dockerfile (see docs/deploy.md, Dockerfile contract)"; exit 1; }
|
|
docker build -t "$(API_IMAGE)" "$(API_DIR)"
|
|
|
|
build-ml: ## Build the ml image
|
|
@test -n "$(ML_DIR)" || { echo "ML_DIR is empty"; exit 1; }
|
|
@test -f "$(ML_DIR)/Dockerfile" || { echo "missing $(ML_DIR)/Dockerfile (see docs/deploy.md, Dockerfile contract)"; exit 1; }
|
|
docker build -t "$(ML_IMAGE)" "$(ML_DIR)"
|
|
|
|
push: push-web push-api push-ml ## Push all three images to Gitea
|
|
|
|
push-web: ## Push the web image
|
|
docker push "$(WEB_IMAGE)"
|
|
|
|
push-api: ## Push the api image
|
|
docker push "$(API_IMAGE)"
|
|
|
|
push-ml: ## Push the ml image
|
|
docker push "$(ML_IMAGE)"
|
|
|
|
set-image: ## Update live Deployments to TAG (guarded; human only)
|
|
@test "$(CONFIRM)" = "yes" || { echo "Refusing: re-run with CONFIRM=yes (cluster mutation)"; exit 1; }
|
|
$(KUBECTL) set image deployment/web web="$(WEB_IMAGE)"
|
|
$(KUBECTL) set image deployment/api api="$(API_IMAGE)"
|
|
$(KUBECTL) set image deployment/ml ml="$(ML_IMAGE)"
|
|
$(KUBECTL) rollout status deployment/web deployment/api deployment/ml --timeout=180s
|
|
|
|
deploy-check: ## Verify required Secrets exist (read-only)
|
|
@for s in gitea-regcred cloudflared control-auth; do \
|
|
$(KUBECTL) get secret "$$s" >/dev/null 2>&1 || { \
|
|
echo "Missing Secret $$s in $(NAMESPACE); see docs/deploy.md"; exit 1; }; \
|
|
done
|
|
@echo "required Secrets present"
|
|
|
|
deploy: ## Apply manifests (guarded; human only)
|
|
@test "$(CONFIRM)" = "yes" || { echo "Refusing: re-run with CONFIRM=yes (cluster mutation)"; exit 1; }
|
|
@$(MAKE) --no-print-directory deploy-check
|
|
$(KUBECTL) apply -f "$(ROOT)/deploy/k8s"
|
|
$(KUBECTL) rollout status deployment/ml --timeout=180s
|
|
$(KUBECTL) rollout status deployment/api --timeout=180s
|
|
$(KUBECTL) rollout status deployment/web --timeout=180s
|
|
$(KUBECTL) rollout status deployment/cloudflared --timeout=120s
|
|
@echo
|
|
@echo "Deployed. Now run: make smoke SMOKE_SSE=1"
|
|
|
|
status: ## Show deployments, pods, services, and secrets
|
|
$(KUBECTL) get deploy,pods,svc,secrets
|
|
|
|
logs: ## Follow cloudflared logs
|
|
$(KUBECTL) logs -f deployment/cloudflared
|
|
|
|
smoke: ## Public HTTPS + API + ML health checks
|
|
WEB_URL="$(WEB_URL)" API_URL="$(API_URL)" ML_URL="$(ML_URL)" \
|
|
NS="$(NAMESPACE)" CONTEXT="$(CONTEXT)" \
|
|
SMOKE_SSE="$(SMOKE_SSE)" SKIP_ML="$(SKIP_ML)" \
|
|
"$(ROOT)/scripts/smoke.sh"
|
|
|
|
smoke-local: ## Smoke the three local dev servers
|
|
WEB_URL="http://localhost:3000" API_URL="http://localhost:8080" \
|
|
ML_URL="http://localhost:8000" \
|
|
SMOKE_SSE="$(SMOKE_SSE)" SKIP_ML="$(SKIP_ML)" \
|
|
"$(ROOT)/scripts/smoke.sh"
|
|
|
|
load: ## Run the 120-client / 5-minute SSE load test
|
|
@mkdir -p "$(K6_RESULTS)"
|
|
@set -e; \
|
|
if [ -n "$(K6)" ]; then \
|
|
runner="$(K6)"; \
|
|
elif [ -x "$(K6_BIN)" ]; then \
|
|
runner="$(K6_BIN)"; \
|
|
elif command -v k6 >/dev/null 2>&1; then \
|
|
runner="$$(command -v k6)"; \
|
|
else \
|
|
echo "No k6 binary. Run 'make k6-build' once (needs Go), then retry."; \
|
|
exit 1; \
|
|
fi; \
|
|
export API_URL="$(LOAD_API_URL)" SSE_VUS="$(SSE_VUS)" SSE_HOLD_PINGS="$(SSE_HOLD_PINGS)" SSE_MAX_DURATION="$(SSE_MAX_DURATION)"; \
|
|
stamp=$$(date +%Y%m%dT%H%M%S); \
|
|
echo "Using $$runner"; \
|
|
"$$runner" run --summary-export="$(K6_RESULTS)/summary-$$stamp.json" "$(K6_SCRIPT)"
|
|
|
|
k6-build: ## Build a k6 binary with the SSE extension (k6/k6-sse)
|
|
@command -v go >/dev/null 2>&1 || { echo "Go is required to build xk6"; exit 1; }
|
|
@cd "$(ROOT)/k6" && GOBIN="$(ROOT)/k6" go install go.k6.io/xk6/cmd/xk6@latest
|
|
@cd "$(ROOT)/k6" && "$(ROOT)/k6/xk6" build --with github.com/phymbert/xk6-sse@latest --output "$(ROOT)/k6/k6-sse"
|
|
@echo "Built $(ROOT)/k6/k6-sse"
|
|
|
|
secret-commands: ## Print the exact Secret creation commands (creates nothing)
|
|
@echo "kubectl --context $(CONTEXT) -n $(NAMESPACE) create secret generic cloudflared \\"
|
|
@echo " --from-literal=TUNNEL_TOKEN='<cloudflare tunnel token>'"
|
|
@echo
|
|
@echo "kubectl --context $(CONTEXT) -n $(NAMESPACE) create secret generic control-auth \\"
|
|
@echo " --from-literal=CONTROL_USER='<control user>' \\"
|
|
@echo " --from-literal=CONTROL_PASS='<strong password>'"
|
|
@echo
|
|
@echo "kubectl --context $(CONTEXT) -n $(NAMESPACE) create secret docker-registry gitea-regcred \\"
|
|
@echo " --docker-server=$(REGISTRY) \\"
|
|
@echo " --docker-username='<gitea user>' \\"
|
|
@echo " --docker-password='<read-only package token>'"
|
|
|
|
clean: ## Remove local k6 build artifacts and results
|
|
rm -f "$(K6_BIN)" "$(ROOT)/k6/xk6"
|
|
rm -rf "$(K6_RESULTS)"
|
|
@mkdir -p "$(K6_RESULTS)" && touch "$(K6_RESULTS)/.gitkeep"
|