feat: 三种部署方式 — embed单容器 + 二进制部署 + K8s
新增三种部署方式(原有 docker-compose 不受影响): 1. Docker embed 单容器 (docker-compose.embed.yml): - go:embed 前端嵌入后端二进制 - 不需要 nginx 容器,3容器→2容器 - 镜像仅 54.8MB (vs 原来 1.16GB) - 用法: make docker-embed 2. 二进制部署 (deploy/binary/): - make build-binary 生成单二进制 - install.sh 自动创建 systemd 服务 - 适合无 Docker 环境 - 用法: scp aiops + install.sh, bash install.sh install 3. Kubernetes 部署 (deploy/k8s/): - devops 命名空间全套 yaml - MySQL StatefulSet + Redis StatefulSet + Backend Deployment - ConfigMap + Secret + Ingress - 用法: kubectl apply -f deploy/k8s/ 核心改动: - backend/cmd/embed.go: go:embed 前端 + SPA fallback 路由 - backend/Dockerfile.embed: 四阶段构建 (前端→后端embed→agent→runtime) - Makefile: build-binary + docker-embed 目标 - deploy/README.md: 四种部署方式对比文档
This commit is contained in:
1 parent
24f955832e
commit
4631b02f13
15 files changed
+1218
-3
No files matched your search
@@ -0,0 +1,91 @@
|
||||
# ============================================================
|
||||
# AIOps 单容器 Dockerfile(embed 模式)
|
||||
# 前端嵌入后端二进制,一个容器搞定前后端
|
||||
# 用法: docker build -f backend/Dockerfile.embed -t aiops-embed .
|
||||
# 署名 Logan.Li
|
||||
# ============================================================
|
||||
|
||||
ARG VERSION=dev
|
||||
ARG BUILD_TIME=unknown
|
||||
|
||||
# ==================== Stage 1: Frontend Builder ====================
|
||||
FROM node:20-alpine AS frontend-builder
|
||||
|
||||
WORKDIR /app
|
||||
ENV NODE_OPTIONS=--max-old-space-size=4096
|
||||
|
||||
# 使用国内 npm 镜像
|
||||
RUN npm config set registry https://registry.npmmirror.com
|
||||
|
||||
COPY frontend/package.json frontend/package-lock.json ./
|
||||
RUN npm ci --prefer-offline 2>/dev/null || npm install
|
||||
|
||||
COPY frontend/ ./
|
||||
RUN npm run build
|
||||
|
||||
# ==================== Stage 2: Backend Builder ====================
|
||||
FROM golang:1.24-alpine AS backend-builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
|
||||
RUN apk add --no-cache git ca-certificates tzdata
|
||||
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
ENV GOSUMDB=off
|
||||
|
||||
COPY backend/go.mod backend/go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY backend/ ./
|
||||
|
||||
# 复制前端构建产物到 static 目录(供 go:embed 嵌入)
|
||||
COPY --from=frontend-builder /app/dist ./cmd/static/
|
||||
|
||||
# 构建(前端已嵌入)
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
||||
-ldflags="-w -s -X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME}" \
|
||||
-o aiops ./cmd/
|
||||
|
||||
# ==================== Stage 3: Agent Builder ====================
|
||||
FROM golang:1.24-alpine AS agent-builder
|
||||
|
||||
WORKDIR /agent
|
||||
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
||||
ENV GOSUMDB=off
|
||||
|
||||
COPY agent/go.mod agent/go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY 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 4: Runtime ====================
|
||||
FROM alpine:latest
|
||||
|
||||
RUN sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
|
||||
RUN apk --no-cache add ca-certificates tzdata curl
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
WORKDIR /app
|
||||
|
||||
# 单个二进制(前端已嵌入)
|
||||
COPY --from=backend-builder /app/aiops .
|
||||
|
||||
# Agent 二进制 + 安装脚本
|
||||
RUN mkdir -p /app/agent/bin /app/agent/deploy
|
||||
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/
|
||||
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 ["./aiops"]
|
||||
Reference in new issue
Block a user