- Dockerfile 修复:GOPROXY 国内镜像 + go.mod 路径修正 + 构建目录
- docker-compose.deploy.yml 补全 push-gateway 全部 12 个环境变量
- deploy.env.example 新增 push-gateway 段(INTERNAL_API_TOKEN/WS_ALLOWED_ORIGINS)
- 本地 Docker 验证通过(非 mock):
- /healthz + /readyz(Redis + Kafka 健康)
- WebSocket /ws + dev-token 鉴权
- /internal/push HTTP API 投递 3 类考试事件
- Kafka → push-gateway → WebSocket 全链路透传
ExamExtended / ExamForceSubmitted / ExamQuestionReordered
- 新增 docs/nextstep.md:上游依赖(iam/Redis/Kafka)+
下游依赖(4 portal + msg)+ 事件投递架构图 + 环境变量清单
44 lines
1.4 KiB
Docker
44 lines
1.4 KiB
Docker
# 多阶段构建:push-gateway 生产镜像
|
||
# 用法:docker build -t edu/push-gateway:latest -f services/push-gateway/Dockerfile .
|
||
|
||
# ============ Builder ============
|
||
FROM golang:1.25-alpine AS builder
|
||
WORKDIR /app
|
||
|
||
# git 与 ca-certificates 为 go mod 下载所需
|
||
RUN apk add --no-cache git ca-certificates
|
||
|
||
# 拷贝 shared-go 和 push-gateway 的 go.mod(用于 go mod download 缓存层)
|
||
COPY packages/shared-go/go.mod ./packages/shared-go/
|
||
COPY services/push-gateway/go.mod services/push-gateway/go.sum ./services/push-gateway/
|
||
ENV GOPROXY=https://goproxy.cn,direct
|
||
RUN cd services/push-gateway && go mod download
|
||
|
||
# 拷源码并构建(静态编译便于 alpine 运行)
|
||
COPY services/push-gateway ./services/push-gateway
|
||
COPY packages/shared-go ./packages/shared-go
|
||
RUN cd services/push-gateway && CGO_ENABLED=0 GOOS=linux go build \
|
||
-ldflags="-s -w -X main.serviceName=push-gateway" \
|
||
-o /app/bin/push-gateway \
|
||
.
|
||
|
||
# ============ Runtime ============
|
||
FROM alpine:3.20 AS runner
|
||
WORKDIR /app
|
||
|
||
RUN apk add --no-cache ca-certificates tzdata wget
|
||
|
||
# 非 root 用户
|
||
RUN addgroup -g 1001 -S app && adduser -S app -u 1001 -G app
|
||
|
||
COPY --from=builder /app/bin/push-gateway /app/push-gateway
|
||
|
||
USER app
|
||
EXPOSE 8081
|
||
|
||
# 健康检查(liveness probe;readiness 由 /readyz 单独探活)
|
||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||
CMD wget --quiet --spider http://localhost:8081/healthz || exit 1
|
||
|
||
ENTRYPOINT ["/app/push-gateway"]
|