FROM golang:1.21.2-alpine3.18 AS builder

LABEL stage=gobuilder

ENV CGO_ENABLED 0
ENV GOARCH amd64
ENV GOPROXY https://goproxy.cn,direct

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

WORKDIR /app

ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .
COPY api/etc/ /app/
RUN go build -o pcm-coordinator-api /app/api/pcm.go


FROM alpine:3.16.2
WORKDIR /app

 #修改alpine源为上海交通大学
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repositories && \
  apk update && \
  apk upgrade && \
  apk add --no-cache ca-certificates && update-ca-certificates && \
  apk add --update tzdata && \
  rm -rf /var/cache/apk/*

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

ENV TZ=Asia/Shanghai

EXPOSE 8999

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