Files
Edu/services/push-gateway/Dockerfile
SpecialX b745443b6d feat(push-gateway): docker 本地验证通过 + nextstep 上下游依赖文档
- 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)+ 事件投递架构图 + 环境变量清单
2026-07-13 17:56:28 +08:00

44 lines
1.4 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.
# 多阶段构建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 probereadiness 由 /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"]