-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
95 lines (72 loc) · 2.49 KB
/
Copy pathDockerfile
File metadata and controls
95 lines (72 loc) · 2.49 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
# 多阶段构建 Dockerfile
# 构建阶段
FROM golang:alpine AS builder
# 获取版本号(通过 build-args 传递,或使用默认值)
ARG VERSION=unknown
# 安装构建依赖(包括 Node.js 和 corepack/yarn 用于构建前端)
RUN apk add --no-cache git make gcc musl-dev nodejs npm && \
corepack enable
# 设置工作目录
WORKDIR /build
# 设置 GOTOOLCHAIN 环境变量,让 Go 自动下载所需的工具链版本
ENV GOTOOLCHAIN=auto
# 复制 go mod 文件
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download
# 复制源代码
COPY . .
# 构建前端(如果需要)
RUN if [ -d "webui" ] && [ -f "webui/package.json" ]; then \
cd webui && \
yarn install --immutable && \
yarn build && \
cd .. && \
mkdir -p web/dist && \
if [ -d "webui/dist" ] && [ "$$(ls -A webui/dist 2>/dev/null)" ]; then \
cp -r webui/dist/* web/dist/ || true; \
fi; \
else \
mkdir -p web/dist && \
echo "# Placeholder" > web/dist/.gitkeep; \
fi
# 构建应用(排除工具文件,避免 main 函数冲突)
RUN mkdir -p .tools_backup && \
for file in analyze_market_data.go run_1m_backtest.go run_3m_backtest.go run_eth_backtest.go test_intrabar_backtest.go test_intrabar_quick.go test_license_validation.go test_plugin_detailed.go test_plugin_loading.go test_zero_fee.go; do \
if [ -f "$$file" ]; then mv "$$file" .tools_backup/ || true; fi \
done && \
echo "Building version: $VERSION" && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w -X main.Version=$VERSION" \
-o quantmesh . && \
rm -rf .tools_backup
# 运行阶段
FROM alpine:latest
# 安装运行时依赖
RUN apk add --no-cache \
ca-certificates \
tzdata \
sqlite
# 创建非 root 用户
RUN addgroup -g 1000 quantmesh && \
adduser -D -u 1000 -G quantmesh quantmesh
# 设置工作目录
WORKDIR /app
# 从构建阶段复制二进制文件
COPY --from=builder /build/quantmesh .
# 复制配置文件示例
COPY docs/config/examples/config.example.yaml ./config.example.yaml
# 创建数据目录
RUN mkdir -p /app/data /app/logs /app/backups && \
chown -R quantmesh:quantmesh /app
# 切换到非 root 用户
USER quantmesh
# 暴露端口
EXPOSE 28888
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:28888/api/status || exit 1
# 设置环境变量
ENV TZ=Asia/Shanghai
# 启动应用
ENTRYPOINT ["/app/quantmesh"]