FROM  docker-0.unsee.tech/golang:alpine AS builder

WORKDIR /app

ENV GOPROXY=https://goproxy.cn \
    GO111MODULE=on \
    CGO_ENABLED=0 \
    GOCACHE=/root/.cache/go-build \
    GOMODCACHE=/go/pkg/mod

COPY go.mod go.sum ./

RUN go mod download

COPY . .

ARG TARGETOS
ARG TARGETARCH
# 使用 GOOS 和 GOARCH 环境变量来构建不同架构的二进制文件
RUN --mount=type=cache,target=/go/pkg/mod \
    --mount=type=cache,target=/root/.cache/go-build \
    GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-w -s" -o pcm-core-api

FROM --platform=$TARGETPLATFORM docker-0.unsee.tech/alpine:latest
WORKDIR /app

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