Files
aiops/backend/Dockerfile
T

101 lines
3.3 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.
# ============================================================
# AIOps Backend + Agent 多阶段 Dockerfile
# Stage 1: 编译后端 (Go 1.21)
# Stage 2: 交叉编译 Agent (Go 1.24, linux-amd64/arm64 + darwin-arm64)
# Stage 3: 运行时 (Alpine)
# 署名 Logan.Li
# ============================================================
# ==================== Stage 1: Backend Builder ====================
FROM golang:1.21-alpine AS builder
WORKDIR /app
<<<<<<< HEAD
=======
# 使用国内 Alpine 镜像源加速
RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
# 安装构建依赖
>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
RUN apk add --no-cache git ca-certificates tzdata
ENV TZ=Asia/Shanghai
ENV GOPROXY=https://goproxy.cn,direct
# 跳过 toolchain 校验(GOTOOLCHAIN 自动下载 Go 1.22)
ENV GONOSUMCHECK=*
# 自动下载 Go 1.22 工具链(Redka 需要)
ENV GOTOOLCHAIN=go1.22.2
# 复制后端 go.mod(利用 Docker 层缓存)
COPY backend/go.mod backend/go.sum ./
RUN go mod download
# 复制后端源码
COPY backend/ ./
# 构建后端二进制
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s" \
-o ezops ./cmd/
# ==================== Stage 2: Agent Builder ====================
FROM golang:1.24-alpine AS agent-builder
WORKDIR /agent
ENV GOPROXY=https://goproxy.cn,direct
ENV GOSUMDB=off
# 复制 agent go.mod
COPY agent/go.mod agent/go.sum ./
RUN go mod download
# 复制 agent 源码
COPY agent/ ./
# 交叉编译三个平台的 agent 二进制
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/aiops-agent-linux-amd64 . && \
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o bin/aiops-agent-linux-arm64 . && \
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o bin/aiops-agent-darwin-arm64 .
# ==================== Stage 3: Runtime ====================
FROM alpine:latest
<<<<<<< HEAD
# 安装运行时依赖(curl=健康检查,openssh-client=SSH远程安装agent)
RUN apk --no-cache add ca-certificates tzdata curl openssh-client
=======
# 使用国内 Alpine 镜像源加速
RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
# 安装运行时依赖
RUN apk --no-cache add ca-certificates tzdata curl
>>>>>>> ca18ead (feat: run.sh四模式(dev/docker/build/binary) + CLI flags + Redka内嵌Redis + Agent复制修复 + 服务器编辑IP字段 + 安装Agent按钮)
ENV TZ=Asia/Shanghai
WORKDIR /app
# 复制后端二进制
COPY --from=builder /app/ezops .
# 创建运行时目录
RUN mkdir -p /app/logs /app/uploads /app/agent/bin /app/agent/deploy
# 复制 agent 二进制(三个平台)
COPY --from=agent-builder /agent/bin/aiops-agent-linux-amd64 /app/agent/bin/
COPY --from=agent-builder /agent/bin/aiops-agent-linux-arm64 /app/agent/bin/
COPY --from=agent-builder /agent/bin/aiops-agent-darwin-arm64 /app/agent/bin/
# 复制 agent 安装脚本和 systemd service 模板
COPY agent/deploy/install.sh /app/agent/deploy/
COPY agent/deploy/aiops-agent.service /app/agent/deploy/
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
CMD ["./ezops"]