.PHONY: all up-lab1 up-lab2 up-lab5 up-lab6 up-all down clean check-kind check-localstack

COMPOSE = docker compose -f docker-compose.yml

# Start individual labs
up-lab1:
	$(COMPOSE) --profile lab1 up -d
	@echo "[*] LocalStack ready at http://localhost:4566/_localstack/health"
	@echo "[*] Next: awslocal s3 mb s3://ch13-lab"

up-lab2:
	$(COMPOSE) --profile lab2 up -d
	@echo "[*] Vulnerable bucket seeded. Enter the tools container:"
	@echo "    docker exec -it ch13-awslocal-tools bash"

up-lab5:
	$(COMPOSE) --profile lab5 up -d
	@echo "[*] CloudTrail tools ready. Enter the container:"
	@echo "    docker exec -it ch13-cloudtrail-tools bash"
	@echo "    cd /lab5 && python3 investigate.py"

up-lab6:
	$(COMPOSE) --profile lab6 up -d
	@echo "[*] Checkov scan running - check logs:"
	@echo "    docker logs ch13-checkov-tools"

up-all:
	$(COMPOSE) --profile all up -d

# Teardown
down:
	$(COMPOSE) down -v

clean: down
	docker image prune -f

# Verify host prerequisites for KIND-based labs (13.1 KIND, 13.3, 13.4)
check-kind:
	@echo "--- KIND version ---"
	@kind version || echo "MISSING: install KIND from https://kind.sigs.k8s.io/docs/user/quick-start/"
	@echo "--- kubectl ---"
	@kubectl version --client --short 2>/dev/null || kubectl version --client 2>/dev/null || echo "MISSING: install kubectl"
	@echo "--- Helm ---"
	@helm version --short 2>/dev/null || echo "MISSING: install Helm from https://helm.sh/docs/intro/install/"

# Check LocalStack health
check-localstack:
	curl -sf http://localhost:4566/_localstack/health | python3 -m json.tool

# Create KIND cluster for labs 13.1-13.4
kind-create:
	kind create cluster --name ch13 --image kindest/node:v1.36.0
	@echo "[*] Cluster ready. Verify: kubectl --context kind-ch13 get nodes"

kind-delete:
	kind delete cluster --name ch13
