Files
xk-ai-agent/manifest/docker/Dockerfile
2026-08-14 21:50:48 +08:00

43 lines
858 B
Docker
Raw Permalink 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构建
FROM golang:1.22-alpine AS builder
WORKDIR /build
# 复制go.mod和go.sum
COPY go.mod go.sum ./
RUN go mod download
# 复制源代码
COPY . .
# 编译静态链接不依赖glibc
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o tcm-agent main.go
# 阶段2运行
FROM alpine:3.19
# 安装CA证书HTTPS请求需要
RUN apk --no-cache add ca-certificates tzdata
# 设置时区
ENV TZ=Asia/Shanghai
WORKDIR /app
# 从构建阶段复制二进制
COPY --from=builder /build/tcm-agent .
# 复制配置文件
COPY manifest/config/config.yaml ./manifest/config/config.yaml
# 暴露端口
EXPOSE 8080
# 健康检查
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget -qO- http://localhost:8080/health || exit 1
# 启动
CMD ["./tcm-agent"]