Dockerfile 727 B

12345678910111213141516171819202122232425262728293031
  1. FROM golang:1.20-alpine AS builder
  2. LABEL stage=gobuilder
  3. ARG APP_NAME
  4. ENV CGO_ENABLED 0
  5. ENV GOPROXY https://goproxy.cn,direct
  6. RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
  7. RUN apk update --no-cache && apk add --no-cache tzdata
  8. WORKDIR /build
  9. COPY . .
  10. RUN pwd && go mod download
  11. RUN go build -ldflags="-s -w" -o /${APP_NAME} app/cmd/${APP_NAME}/${APP_NAME}.go
  12. FROM scratch
  13. ARG APP_NAME
  14. COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
  15. ENV TZ Asia/Shanghai
  16. WORKDIR /${APP_NAME}
  17. COPY --from=builder /${APP_NAME} /${APP_NAME}
  18. COPY --from=builder /build/app/cmd/${APP_NAME}/etc /${APP_NAME}/etc
  19. CMD ["./${APP_NAME}", "-f", "etc/${APP_NAME}.yaml"]