-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
215 lines (177 loc) · 6 KB
/
Copy pathMakefile
File metadata and controls
215 lines (177 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
.PHONY: help build run test clean docker-build-app docker-build-docreader docker-build-frontend docker-build-all 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 check-env list-containers pull-images show-platform
# Show help
help:
@echo "WeKnora Makefile 帮助"
@echo ""
@echo "基础命令:"
@echo " build 构建应用"
@echo " run 运行应用"
@echo " test 运行测试"
@echo " clean 清理构建文件"
@echo ""
@echo "Docker 命令:"
@echo " docker-build-app 构建应用 Docker 镜像 (wechatopenai/weknora-app)"
@echo " docker-build-docreader 构建文档读取器镜像 (wechatopenai/weknora-docreader)"
@echo " docker-build-frontend 构建前端镜像 (wechatopenai/weknora-ui)"
@echo " docker-build-all 构建所有 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 文档"
@echo ""
@echo "环境检查:"
@echo " check-env 检查环境配置"
@echo " list-containers 列出运行中的容器"
@echo " pull-images 拉取最新镜像"
@echo " show-platform 显示当前构建平台"
# Go related variables
BINARY_NAME=WeKnora
MAIN_PATH=./cmd/server
# Docker related variables
DOCKER_IMAGE=wechatopenai/weknora-app
DOCKER_TAG=latest
# Platform detection
ifeq ($(shell uname -m),x86_64)
PLATFORM=linux/amd64
else ifeq ($(shell uname -m),aarch64)
PLATFORM=linux/arm64
else ifeq ($(shell uname -m),arm64)
PLATFORM=linux/arm64
else
PLATFORM=linux/amd64
endif
# 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-app:
@echo "获取版本信息..."
@eval $$(./scripts/get_version.sh env); \
./scripts/get_version.sh info; \
docker build --platform $(PLATFORM) \
--build-arg VERSION_ARG="$$VERSION" \
--build-arg COMMIT_ID_ARG="$$COMMIT_ID" \
--build-arg BUILD_TIME_ARG="$$BUILD_TIME" \
--build-arg GO_VERSION_ARG="$$GO_VERSION" \
-f docker/Dockerfile.app -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
# Build docreader Docker image
docker-build-docreader:
docker build --platform $(PLATFORM) -f docker/Dockerfile.docreader -t wechatopenai/weknora-docreader:latest .
# Build frontend Docker image
docker-build-frontend:
docker build --platform $(PLATFORM) -f frontend/Dockerfile -t wechatopenai/weknora-ui:latest frontend/
# Build all Docker images
docker-build-all: docker-build-app docker-build-docreader docker-build-frontend
# Run Docker container (传统方式)
docker-run:
docker-compose up
# 使用新脚本启动所有服务
start-all:
./scripts/start_all.sh --no-pull
# 使用新脚本仅启动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, start)
docker-restart:
docker-compose stop -t 60
docker-compose up
# 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:
VERSION=$${VERSION:-unknown}; \
COMMIT_ID=$${COMMIT_ID:-unknown}; \
BUILD_TIME=$${BUILD_TIME:-unknown}; \
GO_VERSION=$${GO_VERSION:-unknown}; \
LDFLAGS="-X 'github.com/Tencent/WeKnora/internal/handler.Version=$$VERSION' -X 'github.com/Tencent/WeKnora/internal/handler.CommitID=$$COMMIT_ID' -X 'github.com/Tencent/WeKnora/internal/handler.BuildTime=$$BUILD_TIME' -X 'github.com/Tencent/WeKnora/internal/handler.GoVersion=$$GO_VERSION'"; \
go build -ldflags="-w -s $$LDFLAGS" -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
# Environment check
check-env:
./scripts/start_all.sh --check
# List containers
list-containers:
./scripts/start_all.sh --list
# Pull latest images
pull-images:
./scripts/start_all.sh --pull
# Show current platform
show-platform:
@echo "当前系统架构: $(shell uname -m)"
@echo "Docker构建平台: $(PLATFORM)"