FROM golang:1.20-alpine AS builder LABEL stage=gobuilder ARG APP_NAME ENV CGO_ENABLED 0 ENV GOPROXY https://goproxy.cn,direct RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN apk update --no-cache && apk add --no-cache tzdata WORKDIR /build COPY . . RUN pwd && go mod download RUN go build -ldflags="-s -w" -o /${APP_NAME} app/cmd/${APP_NAME}/${APP_NAME}.go FROM scratch ARG APP_NAME ENV APP_NAME ${APP_NAME} COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai ENV TZ Asia/Shanghai WORKDIR /${APP_NAME} COPY --from=builder /${APP_NAME} /${APP_NAME} COPY --from=builder /build/app/cmd/${APP_NAME}/etc /${APP_NAME}/etc CMD ["./${APP_NAME}", "-f", "etc/${APP_NAME}.yaml"]