FROM golang:1.19-alpine as build
WORKDIR /app/kpt-pasture

COPY . .

RUN mkdir -p ./bin

RUN go env -w GO111MODULE=on && \
    go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct && \
    go env -w CGO_ENABLED=0 && \
    go env -w GOARCH=amd64 && \
    go env -w GOOS=linux && \
    go build -o ./kptPasture -ldflags "-X kpt.kptyun.cn:3000/kpt-event/kpt-pasture/pod.appVersion=beef" main.go


FROM alpine:latest
LABEL name="kpt-pasture" \
description="pt service" \
owner="yiping.xu"

WORKDIR /app/kpt-pasture

RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone

COPY --from=0 /app/kpt-pasture/config/ /app/kpt-pasture/config/
COPY --from=0  /app/kpt-pasture/kptPasture /app/kpt-pasture/kptPasture

EXPOSE 8090
VOLUME ["/app/kpt-pasture/logger","/app/kpt-pasture/config","/app/kpt-pasture/files"]

CMD ["/app/kpt-pasture/kptPasture","http"]