- k8s helm values.yaml: notificationService/moderationService healthPath 改 /health
(原 /healthz 与 pkg/health 实际注册路径不一致);
- 删除 k8s helm starbookservice template (服务已删, 部署已无效);
- docker-compose.{local,prod}.yml: 删 starbookService 服务块 + URL env + depends_on;
- Dockerfile.services: 删 starbookService 构建 Stage;
- build.sh + deploy.sh: 删 starbookService 引用 + ALL_SERVICES_NAME 帮助文本。
Co-Authored-By: Claude <noreply@anthropic.com>
246 lines
8.1 KiB
Docker
246 lines
8.1 KiB
Docker
# ===================================================================
|
|
# TopFans - Multi-stage Build for Go Services
|
|
# Stage 1: Build all services in parallel
|
|
# Stage 2: Create minimal runtime image for each service
|
|
# ===================================================================
|
|
|
|
# ---- Build Stage ----
|
|
FROM --platform=linux/amd64 golang:1.25-alpine AS builder
|
|
|
|
# Install build dependencies
|
|
RUN apk add --no-cache git make
|
|
|
|
# Set working directory
|
|
WORKDIR /build
|
|
|
|
# Copy go mod files first for better caching
|
|
COPY backend/go.mod backend/go.sum ./
|
|
|
|
# 配置 Go 模块代理,解决网络问题
|
|
RUN go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/go-proxy/,direct && \
|
|
go env -w GOSUMDB=off && \
|
|
go mod download
|
|
|
|
# Copy source code
|
|
COPY backend/ ./
|
|
|
|
# Build all services with optimization flags
|
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/gateway gateway/main.go && \
|
|
echo "Built gateway" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/userservice services/userService/main.go && \
|
|
echo "Built userservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/socialservice services/socialService/main.go && \
|
|
echo "Built socialservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/assetservice services/assetService/main.go && \
|
|
echo "Built assetservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/galleryservice services/galleryService/main.go && \
|
|
echo "Built galleryservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/activityservice services/activityService/main.go && \
|
|
echo "Built activityservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/taskservice services/taskService/main.go && \
|
|
echo "Built taskservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/aichatservice services/aiChatService/main.go && \
|
|
echo "Built aichatservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/statisticservice services/statisticService/main.go && \
|
|
echo "Built statisticservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/notificationservice services/notificationService/main.go && \
|
|
echo "Built notificationservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/moderationservice services/moderationService/main.go && \
|
|
echo "Built moderationservice" && \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" \
|
|
-o /tmp/set-oss-cors scripts/set-oss-cors/main.go && \
|
|
echo "Built set-oss-cors"
|
|
|
|
# ---- Runtime Stage: Gateway ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS gateway
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/gateway /app/gateway
|
|
|
|
ENV GIN_MODE=release
|
|
EXPOSE 8080
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=15s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
|
|
|
|
ENTRYPOINT ["/app/gateway"]
|
|
CMD ["-port=8080"]
|
|
|
|
# ---- Runtime Stage: UserService ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS userservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/userservice /app/userservice
|
|
|
|
EXPOSE 20000
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:20000 || exit 1
|
|
|
|
ENTRYPOINT ["/app/userservice"]
|
|
|
|
# ---- Runtime Stage: SocialService ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS socialservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/socialservice /app/socialservice
|
|
|
|
EXPOSE 20002
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:20002 || exit 1
|
|
|
|
ENTRYPOINT ["/app/socialservice"]
|
|
|
|
# ---- Runtime Stage: AssetService ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS assetservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/assetservice /app/assetservice
|
|
|
|
EXPOSE 20003
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:20003 || exit 1
|
|
|
|
ENTRYPOINT ["/app/assetservice"]
|
|
|
|
# ---- Runtime Stage: GalleryService ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS galleryservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/galleryservice /app/galleryservice
|
|
|
|
EXPOSE 20001
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:21001 || exit 1
|
|
|
|
ENTRYPOINT ["/app/galleryservice"]
|
|
|
|
# ---- Runtime Stage: ActivityService ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS activityservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/activityservice /app/activityservice
|
|
|
|
EXPOSE 20004
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:21004 || exit 1
|
|
|
|
ENTRYPOINT ["/app/activityservice"]
|
|
|
|
# ---- Runtime Stage: TaskService ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS taskservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/taskservice /app/taskservice
|
|
|
|
EXPOSE 20006
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:21006 || exit 1
|
|
|
|
ENTRYPOINT ["/app/taskservice"]
|
|
|
|
# ---- Runtime Stage: AIChatService ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS aichatservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/aichatservice /app/aichatservice
|
|
|
|
EXPOSE 20008
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:21008 || exit 1
|
|
|
|
ENTRYPOINT ["/app/aichatservice"]
|
|
|
|
|
|
|
|
# ---- Runtime Stage: StatisticService (数据看板微服务) ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS statisticservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/statisticservice /app/statisticservice
|
|
|
|
EXPOSE 20009
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=15s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:21009/healthz || exit 1
|
|
|
|
ENTRYPOINT ["/app/statisticservice"]
|
|
|
|
# ---- Runtime Stage: NotificationService (通知 + uniCloud 推送) ----
|
|
# health 端点路径是 /health(不是 /healthz),见 backend/pkg/health/health.go:29
|
|
FROM --platform=linux/amd64 alpine:3.19 AS notificationservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/notificationservice /app/notificationservice
|
|
|
|
EXPOSE 20010
|
|
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=15s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:21010/health || exit 1
|
|
|
|
ENTRYPOINT ["/app/notificationservice"]
|
|
|
|
# ---- Runtime Stage: ModerationService (举报 / 反馈 / 自动隐藏) ----
|
|
# moderationService main.go 没启 health server(只暴露 Dubbo Triple 协议),
|
|
# image-level HEALTHCHECK NONE 防 rebuild 后回退到错误的 20011 HEALTHCHECK。
|
|
# 运行时 compose 用 healthcheck: test: ["NONE"] 显式覆盖,这里 NONE 是双保险。
|
|
FROM --platform=linux/amd64 alpine:3.19 AS moderationservice
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/moderationservice /app/moderationservice
|
|
|
|
EXPOSE 20011
|
|
|
|
HEALTHCHECK NONE
|
|
|
|
ENTRYPOINT ["/app/moderationservice"]
|
|
|
|
# ---- Runtime Stage: OSS CORS Init (一次性,跑完即退,设置 bucket CORS) ----
|
|
FROM --platform=linux/amd64 alpine:3.19 AS oss-cors-init
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /tmp/set-oss-cors /app/set-oss-cors
|
|
|
|
ENTRYPOINT ["/app/set-oss-cors"]
|