Files
aiops/backend/Dockerfile
T

101 lines
3.6 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
1|# ============================================================
2|# AIOps Backend + Agent 多阶段 Dockerfile
3|# Stage 1: 编译后端 (Go 1.21)
4|# Stage 2: 交叉编译 Agent (Go 1.24, linux-amd64/arm64 + darwin-arm64)
5|# Stage 3: 运行时 (Alpine)
6|# 署名 Logan.Li
7|# ============================================================
8|
9|# ==================== Stage 1: Backend Builder ====================
10|FROM golang:1.21-alpine AS builder
11|
12|WORKDIR /app
13|
14|<<<<<<< HEAD
15|=======
16|# 使用国内 Alpine 镜像源加速
17|RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
18|
19|# 安装构建依赖
20|>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
21|RUN apk add --no-cache git ca-certificates tzdata
22|
23|ENV TZ=Asia/Shanghai
24|ENV GOPROXY=https://goproxy.cn,direct
25|# 跳过 toolchain 校验(GOTOOLCHAIN 自动下载 Go 1.22)
26|ENV GONOSUMCHECK=*
27|# 自动下载 Go 1.22 工具链(Redka 需要)
28|ENV GOTOOLCHAIN=go1.22.2
29|
30|# 复制后端 go.mod(利用 Docker 层缓存)
31|COPY backend/go.mod backend/go.sum ./
32|RUN go mod download
33|
34|# 复制后端源码
35|COPY backend/ ./
36|
37|# 构建后端二进制
38|RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
39| -ldflags="-w -s" \
40| -o ezops ./cmd/
41|
42|# ==================== Stage 2: Agent Builder ====================
43|FROM golang:1.24-alpine AS agent-builder
44|
45|WORKDIR /agent
46|
47|ENV GOPROXY=https://goproxy.cn,direct
48|ENV GOSUMDB=off
49|
50|# 复制 agent go.mod
51|COPY agent/go.mod agent/go.sum ./
52|RUN go mod download
53|
54|# 复制 agent 源码
55|COPY agent/ ./
56|
57|# 交叉编译三个平台的 agent 二进制
58|RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/aiops-agent-linux-amd64 . && \
59| CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o bin/aiops-agent-linux-arm64 . && \
60| CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o bin/aiops-agent-darwin-arm64 .
61|
62|# ==================== Stage 3: Runtime ====================
63|FROM alpine:latest
64|
65|<<<<<<< HEAD
66|# 安装运行时依赖(curl=健康检查,openssh-client=SSH远程安装agent)
67|RUN apk --no-cache add ca-certificates tzdata curl openssh-client
68|=======
69|# 使用国内 Alpine 镜像源加速
70|RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
71|
72|# 安装运行时依赖
73|RUN apk --no-cache add ca-certificates tzdata curl
74|>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
75|
76|ENV TZ=Asia/Shanghai
77|
78|WORKDIR /app
79|
80|# 复制后端二进制
81|COPY --from=builder /app/ezops .
82|
83|# 创建运行时目录
84|RUN mkdir -p /app/logs /app/uploads /app/agent/bin /app/agent/deploy
85|
86|# 复制 agent 二进制(三个平台)
87|COPY --from=agent-builder /agent/bin/aiops-agent-linux-amd64 /app/agent/bin/
88|COPY --from=agent-builder /agent/bin/aiops-agent-linux-arm64 /app/agent/bin/
89|COPY --from=agent-builder /agent/bin/aiops-agent-darwin-arm64 /app/agent/bin/
90|
91|# 复制 agent 安装脚本和 systemd service 模板
92|COPY agent/deploy/install.sh /app/agent/deploy/
93|COPY agent/deploy/aiops-agent.service /app/agent/deploy/
94|
95|EXPOSE 8080
96|
97|HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
98| CMD curl -f http://localhost:8080/health || exit 1
99|
100|CMD ["./ezops"]
101|