155 lines
3.7 KiB
Makefile
155 lines
3.7 KiB
Makefile
.PHONY: help build run test clean docker-build docker-run migrate-up migrate-down docker-restart docker-stop start-all stop-all start-ollama stop-ollama build-images build-images-app build-images-docreader build-images-frontend clean-images
|
|
|
|
# Show help
|
|
help:
|
|
@echo "WeKnora Makefile 帮助"
|
|
@echo ""
|
|
@echo "基础命令:"
|
|
@echo " build 构建应用"
|
|
@echo " run 运行应用"
|
|
@echo " test 运行测试"
|
|
@echo " clean 清理构建文件"
|
|
@echo ""
|
|
@echo "Docker 命令:"
|
|
@echo " docker-build 构建 Docker 镜像"
|
|
@echo " docker-run 运行 Docker 容器"
|
|
@echo " docker-stop 停止 Docker 容器"
|
|
@echo " docker-restart 重启 Docker 容器"
|
|
@echo ""
|
|
@echo "服务管理:"
|
|
@echo " start-all 启动所有服务"
|
|
@echo " stop-all 停止所有服务"
|
|
@echo " start-ollama 仅启动 Ollama 服务"
|
|
@echo ""
|
|
@echo "镜像构建:"
|
|
@echo " build-images 从源码构建所有镜像"
|
|
@echo " build-images-app 从源码构建应用镜像"
|
|
@echo " build-images-docreader 从源码构建文档读取器镜像"
|
|
@echo " build-images-frontend 从源码构建前端镜像"
|
|
@echo " clean-images 清理本地镜像"
|
|
@echo ""
|
|
@echo "数据库:"
|
|
@echo " migrate-up 执行数据库迁移"
|
|
@echo " migrate-down 回滚数据库迁移"
|
|
@echo ""
|
|
@echo "开发工具:"
|
|
@echo " fmt 格式化代码"
|
|
@echo " lint 代码检查"
|
|
@echo " deps 安装依赖"
|
|
@echo " docs 生成 API 文档"
|
|
|
|
# Go related variables
|
|
BINARY_NAME=WeKnora
|
|
MAIN_PATH=./cmd/server
|
|
|
|
# Docker related variables
|
|
DOCKER_IMAGE=WeKnora
|
|
DOCKER_TAG=latest
|
|
|
|
# Build the application
|
|
build:
|
|
go build -o $(BINARY_NAME) $(MAIN_PATH)
|
|
|
|
# Run the application
|
|
run: build
|
|
./$(BINARY_NAME)
|
|
|
|
# Run tests
|
|
test:
|
|
go test -v ./...
|
|
|
|
# Clean build artifacts
|
|
clean:
|
|
go clean
|
|
rm -f $(BINARY_NAME)
|
|
|
|
# Build Docker image
|
|
docker-build:
|
|
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
|
|
|
|
# Run Docker container (传统方式)
|
|
docker-run:
|
|
docker-compose up
|
|
|
|
# 使用新脚本启动所有服务
|
|
start-all:
|
|
./scripts/start_all.sh
|
|
|
|
# 使用新脚本仅启动Ollama服务
|
|
start-ollama:
|
|
./scripts/start_all.sh --ollama
|
|
|
|
# 使用新脚本仅启动Docker容器
|
|
start-docker:
|
|
./scripts/start_all.sh --docker
|
|
|
|
# 使用新脚本停止所有服务
|
|
stop-all:
|
|
./scripts/start_all.sh --stop
|
|
|
|
# Stop Docker container (传统方式)
|
|
docker-stop:
|
|
docker-compose down
|
|
|
|
# 从源码构建镜像相关命令
|
|
build-images:
|
|
./scripts/build_images.sh
|
|
|
|
build-images-app:
|
|
./scripts/build_images.sh --app
|
|
|
|
build-images-docreader:
|
|
./scripts/build_images.sh --docreader
|
|
|
|
build-images-frontend:
|
|
./scripts/build_images.sh --frontend
|
|
|
|
clean-images:
|
|
./scripts/build_images.sh --clean
|
|
|
|
# Restart Docker container (stop, rebuild, start)
|
|
docker-restart:
|
|
docker-compose stop -t 60
|
|
docker-compose up --build
|
|
|
|
# Database migrations
|
|
migrate-up:
|
|
./scripts/migrate.sh up
|
|
|
|
migrate-down:
|
|
./scripts/migrate.sh down
|
|
|
|
# Generate API documentation
|
|
docs:
|
|
swag init -g $(MAIN_PATH)/main.go -o ./docs
|
|
|
|
# Format code
|
|
fmt:
|
|
go fmt ./...
|
|
|
|
# Lint code
|
|
lint:
|
|
golangci-lint run
|
|
|
|
# Install dependencies
|
|
deps:
|
|
go mod download
|
|
|
|
# Build for production
|
|
build-prod:
|
|
GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o $(BINARY_NAME) $(MAIN_PATH)
|
|
|
|
clean-db:
|
|
@echo "Cleaning database..."
|
|
@if [ $$(docker volume ls -q -f name=weknora_postgres-data) ]; then \
|
|
docker volume rm weknora_postgres-data; \
|
|
fi
|
|
@if [ $$(docker volume ls -q -f name=weknora_minio_data) ]; then \
|
|
docker volume rm weknora_minio_data; \
|
|
fi
|
|
@if [ $$(docker volume ls -q -f name=weknora_redis_data) ]; then \
|
|
docker volume rm weknora_redis_data; \
|
|
fi
|
|
|
|
|