Dockerfile 752 B

1234567891011121314151617181920212223242526272829303132
  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. ENV APP_NAME ${APP_NAME}
  15. COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai
  16. ENV TZ Asia/Shanghai
  17. WORKDIR /${APP_NAME}
  18. COPY --from=builder /${APP_NAME} /${APP_NAME}
  19. COPY --from=builder /build/app/cmd/${APP_NAME}/etc /${APP_NAME}/etc
  20. CMD ["./${APP_NAME}", "-f", "etc/${APP_NAME}.yaml"]