docker.tpl 888 B

1234567891011121314151617181920212223242526272829303132
  1. FROM golang:{{.Version}}alpine AS builder
  2. LABEL stage=gobuilder
  3. ENV CGO_ENABLED 0
  4. {{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct
  5. {{end}}{{if .HasTimezone}}
  6. RUN apk update --no-cache && apk add --no-cache tzdata
  7. {{end}}
  8. WORKDIR /build
  9. ADD go.mod .
  10. ADD go.sum .
  11. RUN go mod download
  12. COPY . .
  13. {{if .Argument}}COPY {{.GoRelPath}}/etc /app/etc
  14. {{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoRelPath}}/{{.GoFile}}
  15. FROM {{.BaseImage}}
  16. COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
  17. {{if .HasTimezone}}COPY --from=builder /usr/share/zoneinfo/{{.Timezone}} /usr/share/zoneinfo/{{.Timezone}}
  18. ENV TZ {{.Timezone}}
  19. {{end}}
  20. WORKDIR /app
  21. COPY --from=builder /app/{{.ExeFile}} /app/{{.ExeFile}}{{if .Argument}}
  22. COPY --from=builder /app/etc /app/etc{{end}}
  23. {{if .HasPort}}
  24. EXPOSE {{.Port}}
  25. {{end}}
  26. CMD ["./{{.ExeFile}}"{{.Argument}}]