# 项目管理 Makefile

.PHONY: help setup init plan apply destroy clean test lint docs

# 默认目标
help: ## 显示帮助信息
	@echo "可用的命令："
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

# 环境设置
setup: ## 设置开发环境
	@echo "🚀 设置开发环境..."
	@bash scripts/setup/setup-environment.sh

# OpenTofu 操作
init: ## 初始化 OpenTofu
	@echo "🏗️  初始化 OpenTofu..."
	@cd infrastructure/environments/dev && tofu init

plan: ## 生成执行计划
	@echo "📋 生成执行计划..."
	@cd infrastructure/environments/dev && tofu plan -var-file="terraform.tfvars"

apply: ## 应用基础设施变更
	@echo "🚀 应用基础设施变更..."
	@cd infrastructure/environments/dev && tofu apply -var-file="terraform.tfvars"

destroy: ## 销毁基础设施
	@echo "💥 销毁基础设施..."
	@cd infrastructure/environments/dev && tofu destroy -var-file="terraform.tfvars"

# Ansible 操作
ansible-check: ## 检查 Ansible 配置
	@echo "🔍 检查 Ansible 配置..."
	@cd configuration && ansible-playbook --syntax-check playbooks/bootstrap/main.yml

ansible-deploy: ## 部署应用
	@echo "📦 部署应用..."
	@cd configuration && ansible-playbook -i inventories/production/inventory.ini playbooks/bootstrap/main.yml

# Podman 操作
podman-build: ## 构建 Podman 镜像
	@echo "📦 构建 Podman 镜像..."
	@podman-compose -f containers/compose/development/docker-compose.yml build

podman-up: ## 启动开发环境
	@echo "🚀 启动开发环境..."
	@podman-compose -f containers/compose/development/docker-compose.yml up -d

podman-down: ## 停止开发环境
	@echo "🛑 停止开发环境..."
	@podman-compose -f containers/compose/development/docker-compose.yml down

# 测试
test: ## 运行测试
	@echo "🧪 运行测试..."
	@bash scripts/utilities/run-tests.sh

lint: ## 代码检查
	@echo "🔍 代码检查..."
	@bash scripts/utilities/lint.sh

# 文档
docs: ## 生成文档
	@echo "📚 生成文档..."
	@bash scripts/utilities/generate-docs.sh

# 清理
clean: ## 清理临时文件
	@echo "🧹 清理临时文件..."
	@find . -name "*.tfstate*" -delete
	@find . -name ".terraform" -type d -exec rm -rf {} + 2>/dev/null || true
	@podman system prune -f

# 备份
backup: ## 创建备份
	@echo "💾 创建备份..."
	@bash scripts/utilities/backup.sh

# 监控
monitor: ## 启动监控
	@echo "📊 启动监控..."
	@podman-compose -f containers/compose/production/monitoring.yml up -d

# 安全扫描
security-scan: ## 安全扫描
	@echo "🔒 安全扫描..."
	@bash scripts/utilities/security-scan.sh