feat: 添加后端 Dockerfile

- 多阶段构建:golang:1.24-alpine 编译,alpine:3.20 运行
- CGO_ENABLED=0 静态链接,包含 ca-certificates 和时区数据
This commit is contained in:
hhs
2026-06-14 13:38:25 +08:00
parent 7108d2a58b
commit d75cdf95c8

27
backend/Dockerfile Normal file
View File

@@ -0,0 +1,27 @@
# ---- 构建阶段 ----
FROM golang:1.26-alpine AS builder
WORKDIR /app
# 先复制依赖清单,利用 Docker 缓存层
COPY go.mod go.sum ./
RUN go mod download
# 复制源码并构建
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /camtalk ./cmd/server
# ---- 运行阶段 ----
FROM alpine:3.20
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
# 复制二进制和配置
COPY --from=builder /camtalk .
COPY config.yaml .
EXPOSE 8080
ENTRYPOINT ["./camtalk"]