docker.tpl 770 B

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