FROM --platform=$BUILDPLATFORM golang:alpine AS builder

WORKDIR /app
COPY . .

ENV GO111MODULE=on
RUN go mod download

ARG TARGETOS
ARG TARGETARCH
# 使用 GOOS 和 GOARCH 环境变量来构建不同架构的二进制文件
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-w -s" -o pcm-core-api

FROM --platform=$TARGETPLATFORM alpine:latest
WORKDIR /app

#修改alpine源为上海交通大学
RUN apk add --no-cache ca-certificates && update-ca-certificates && \
  apk add --update tzdata && \
  rm -rf /var/cache/apk/*

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

ENV TZ=Asia/Shanghai

EXPOSE 8999

ENTRYPOINT ./pcm-core-api --f pcm.yaml