FROM golang:1.21.2-alpine3.18 AS builder

WORKDIR /app

COPY . .

RUN go env -w GO111MODULE=on \
&& go env -w GOPROXY=https://goproxy.cn,direct \
&& go env -w CGO_ENABLED=0
RUN go build -o pcm-coordinator-api /app/api/pcm.go

FROM alpine:3.18

WORKDIR /app

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repositories && \
    apk add --no-cache ca-certificates tzdata && \
    update-ca-certificates && \
    rm -rf /var/cache/apk/*

COPY --from=builder /app/pcm-coordinator-api /app/
COPY --from=builder /app/api/etc/pcm.yaml /app/

ENV TZ=Asia/Shanghai

EXPOSE 8999

ENTRYPOINT ["./pcm-coordinator-api", "-f", "pcm.yaml"]