# ========== 构建阶段 ==========
FROM golang:1.26-alpine AS builder

RUN apk add --no-cache git ca-certificates

WORKDIR /app

COPY backend/platform-bridge/ ./backend/platform-bridge/

WORKDIR /app/backend/platform-bridge
ENV GOPROXY=https://goproxy.cn,direct
RUN go mod download

RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /platform-bridge ./cmd/main.go

# ========== 运行阶段 ==========
FROM alpine:3.20

RUN apk add --no-cache ca-certificates tzdata && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

WORKDIR /app

COPY --from=builder /platform-bridge .

RUN mkdir -p logs && adduser -D -H cyrene && chown -R cyrene:cyrene /app
USER cyrene

EXPOSE 8095

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost:8095/health || exit 1

ENTRYPOINT ["./platform-bridge"]
