# Build stage FROM golang:1.21-alpine AS builder # Use Aliyun mirror for Alpine packages (China acceleration) RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN apk add --no-cache git ca-certificates # Set Go proxy for China ARG GOPROXY=https://goproxy.cn,https://goproxy.io,direct ENV GOPROXY=${GOPROXY} ENV GOSUMDB=sum.golang.google.cn WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ -ldflags="-w -s" \ -o /bin/message-router \ ./services/message-router/cmd/server # Final stage FROM alpine:3.18 # Use Aliyun mirror for Alpine packages (China acceleration) RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN apk --no-cache add ca-certificates curl RUN adduser -D -s /bin/sh mpc COPY --from=builder /bin/message-router /bin/message-router USER mpc EXPOSE 50051 8080 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -sf http://localhost:8080/health || exit 1 ENTRYPOINT ["/bin/message-router"]