🚀 主要功能: - 完善后端API服务层,实现完整的CRUD操作 - 开发管理后台所有核心页面 (仪表板、照片、分类、标签、用户、设置) - 完成前后端完全集成,所有API接口正常对接 - 配置完整的CI/CD流水线,支持自动化部署 🎯 后端完善: - 实现PhotoService, CategoryService, TagService, UserService - 添加完整的API处理器和路由配置 - 支持Docker容器化部署 - 添加数据库迁移和健康检查 🎨 管理后台完成: - 仪表板: 实时统计数据展示 - 照片管理: 完整的CRUD操作,支持批量处理 - 分类管理: 树形结构展示和管理 - 标签管理: 颜色标签和统计信息 - 用户管理: 角色权限控制 - 系统设置: 多标签配置界面 - 添加pre-commit代码质量检查 🔧 部署配置: - Docker Compose完整配置 - 后端CI/CD流水线 (Docker部署) - 管理后台CI/CD流水线 (静态文件部署) - 前端CI/CD流水线优化 - 自动化脚本: 部署、备份、监控 - 完整的部署文档和运维指南 ✅ 集成完成: - 所有API接口正常连接 - 认证系统完整集成 - 数据获取和状态管理 - 错误处理和用户反馈 - 响应式设计优化
165 lines
6.2 KiB
Makefile
165 lines
6.2 KiB
Makefile
# Photography Backend Makefile
|
|
# Simple and functional Makefile for Go backend project with Docker support
|
|
|
|
.PHONY: help dev dev-up dev-down build clean docker-build docker-run prod-up prod-down status health fmt mod
|
|
|
|
# Color definitions
|
|
GREEN := \033[0;32m
|
|
YELLOW := \033[1;33m
|
|
BLUE := \033[0;34m
|
|
RED := \033[0;31m
|
|
NC := \033[0m # No Color
|
|
|
|
# Application configuration
|
|
APP_NAME := photography-backend
|
|
VERSION := 1.0.0
|
|
BUILD_TIME := $(shell date +%Y%m%d_%H%M%S)
|
|
LDFLAGS := -X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)
|
|
|
|
# Build configuration
|
|
BUILD_DIR := bin
|
|
MAIN_FILE := cmd/server/main.go
|
|
|
|
# Database configuration
|
|
DB_URL := postgres://postgres:password@localhost:5432/photography?sslmode=disable
|
|
MIGRATION_DIR := migrations
|
|
|
|
# Default target
|
|
.DEFAULT_GOAL := help
|
|
|
|
##@ Development Environment Commands
|
|
|
|
dev: ## Start development server with hot reload
|
|
@printf "$(GREEN)🚀 Starting development server...\n$(NC)"
|
|
@air -c .air.toml || go run $(MAIN_FILE)
|
|
|
|
dev-up: ## Start development environment with Docker
|
|
@printf "$(GREEN)🐳 Starting development environment...\n$(NC)"
|
|
@docker-compose -f docker-compose.dev.yml up -d
|
|
@printf "$(GREEN)✅ Development environment started successfully!\n$(NC)"
|
|
|
|
dev-down: ## Stop development environment
|
|
@printf "$(GREEN)🛑 Stopping development environment...\n$(NC)"
|
|
@docker-compose -f docker-compose.dev.yml down
|
|
@printf "$(GREEN)✅ Development environment stopped!\n$(NC)"
|
|
|
|
##@ Build Commands
|
|
|
|
build: ## Build the Go application
|
|
@printf "$(GREEN)🔨 Building $(APP_NAME)...\n$(NC)"
|
|
@mkdir -p $(BUILD_DIR)
|
|
@CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(APP_NAME) $(MAIN_FILE)
|
|
@printf "$(GREEN)✅ Build completed: $(BUILD_DIR)/$(APP_NAME)\n$(NC)"
|
|
|
|
clean: ## Clean build artifacts
|
|
@printf "$(GREEN)🧹 Cleaning build files...\n$(NC)"
|
|
@rm -rf $(BUILD_DIR)
|
|
@rm -f coverage.out coverage.html
|
|
@printf "$(GREEN)✅ Clean completed!\n$(NC)"
|
|
|
|
##@ Docker Commands
|
|
|
|
docker-build: ## Build Docker image
|
|
@printf "$(GREEN)🐳 Building Docker image...\n$(NC)"
|
|
@docker build -t $(APP_NAME):$(VERSION) .
|
|
@docker tag $(APP_NAME):$(VERSION) $(APP_NAME):latest
|
|
@printf "$(GREEN)✅ Docker image built: $(APP_NAME):$(VERSION)\n$(NC)"
|
|
|
|
docker-run: ## Run application in Docker container
|
|
@printf "$(GREEN)🐳 Running Docker container...\n$(NC)"
|
|
@docker-compose up -d
|
|
@printf "$(GREEN)✅ Docker container started!\n$(NC)"
|
|
|
|
##@ Production Commands
|
|
|
|
prod-up: ## Start production environment
|
|
@printf "$(GREEN)🚀 Starting production environment...\n$(NC)"
|
|
@docker-compose up -d
|
|
@printf "$(GREEN)✅ Production environment started!\n$(NC)"
|
|
|
|
prod-down: ## Stop production environment
|
|
@printf "$(GREEN)🛑 Stopping production environment...\n$(NC)"
|
|
@docker-compose down
|
|
@printf "$(GREEN)✅ Production environment stopped!\n$(NC)"
|
|
|
|
##@ Health Check & Status Commands
|
|
|
|
status: ## Check application and services status
|
|
@printf "$(GREEN)📊 Checking application status...\n$(NC)"
|
|
@printf "$(BLUE)Docker containers:$(NC)\n"
|
|
@docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "($(APP_NAME)|postgres|redis)" || echo "No containers running"
|
|
@printf "$(BLUE)Application build:$(NC)\n"
|
|
@if [ -f "$(BUILD_DIR)/$(APP_NAME)" ]; then \
|
|
printf "$(GREEN)✅ Binary exists: $(BUILD_DIR)/$(APP_NAME)\n$(NC)"; \
|
|
ls -lh $(BUILD_DIR)/$(APP_NAME); \
|
|
else \
|
|
printf "$(RED)❌ Binary not found. Run 'make build' first.\n$(NC)"; \
|
|
fi
|
|
|
|
health: ## Check health of running services
|
|
@printf "$(GREEN)🏥 Checking service health...\n$(NC)"
|
|
@printf "$(BLUE)Testing application endpoint...\n$(NC)"
|
|
@curl -f http://localhost:8080/health 2>/dev/null && printf "$(GREEN)✅ Application is healthy\n$(NC)" || printf "$(RED)❌ Application is not responding\n$(NC)"
|
|
@printf "$(BLUE)Database connection...\n$(NC)"
|
|
@docker exec photography-postgres pg_isready -U postgres 2>/dev/null && printf "$(GREEN)✅ Database is ready\n$(NC)" || printf "$(RED)❌ Database is not ready\n$(NC)"
|
|
|
|
##@ Code Quality Commands
|
|
|
|
fmt: ## Format Go code
|
|
@printf "$(GREEN)🎨 Formatting Go code...\n$(NC)"
|
|
@go fmt ./...
|
|
@printf "$(GREEN)✅ Code formatted!\n$(NC)"
|
|
|
|
mod: ## Tidy Go modules
|
|
@printf "$(GREEN)📦 Tidying Go modules...\n$(NC)"
|
|
@go mod tidy
|
|
@go mod download
|
|
@printf "$(GREEN)✅ Modules tidied!\n$(NC)"
|
|
|
|
lint: ## Run code linter
|
|
@printf "$(GREEN)🔍 Running linter...\n$(NC)"
|
|
@golangci-lint run
|
|
@printf "$(GREEN)✅ Linting completed!\n$(NC)"
|
|
|
|
test: ## Run tests
|
|
@printf "$(GREEN)🧪 Running tests...\n$(NC)"
|
|
@go test -v ./...
|
|
@printf "$(GREEN)✅ Tests completed!\n$(NC)"
|
|
|
|
##@ Utility Commands
|
|
|
|
install: ## Install dependencies
|
|
@printf "$(GREEN)📦 Installing dependencies...\n$(NC)"
|
|
@go mod download
|
|
@go mod tidy
|
|
@printf "$(GREEN)✅ Dependencies installed!\n$(NC)"
|
|
|
|
logs: ## Show application logs
|
|
@printf "$(GREEN)📄 Showing application logs...\n$(NC)"
|
|
@docker-compose logs -f $(APP_NAME)
|
|
|
|
migrate-up: ## Run database migrations
|
|
@printf "$(GREEN)🗄️ Running database migrations...\n$(NC)"
|
|
@migrate -path $(MIGRATION_DIR) -database "$(DB_URL)" up
|
|
@printf "$(GREEN)✅ Migrations completed!\n$(NC)"
|
|
|
|
migrate-down: ## Rollback database migrations
|
|
@printf "$(GREEN)🗄️ Rolling back database migrations...\n$(NC)"
|
|
@migrate -path $(MIGRATION_DIR) -database "$(DB_URL)" down
|
|
@printf "$(GREEN)✅ Migrations rolled back!\n$(NC)"
|
|
|
|
##@ Help
|
|
|
|
help: ## Display this help message
|
|
@printf "$(GREEN)Photography Backend Makefile\n$(NC)"
|
|
@printf "$(GREEN)============================\n$(NC)"
|
|
@printf "$(YELLOW)Simple and functional Makefile for Go backend project with Docker support\n$(NC)\n"
|
|
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*?##/ { printf "$(BLUE)%-15s$(NC) %s\n", $$1, $$2 } /^##@/ { printf "\n$(GREEN)%s\n$(NC)", substr($$0, 5) } ' $(MAKEFILE_LIST)
|
|
@printf "\n$(YELLOW)Examples:\n$(NC)"
|
|
@printf "$(BLUE) make dev$(NC) - Start development server\n"
|
|
@printf "$(BLUE) make dev-up$(NC) - Start development environment\n"
|
|
@printf "$(BLUE) make build$(NC) - Build the application\n"
|
|
@printf "$(BLUE) make docker-build$(NC) - Build Docker image\n"
|
|
@printf "$(BLUE) make status$(NC) - Check application status\n"
|
|
@printf "$(BLUE) make health$(NC) - Check service health\n"
|
|
@printf "\n$(GREEN)For more information, visit: https://github.com/iriver/photography\n$(NC)"
|