template.go 887 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package docker
  2. import (
  3. "github.com/tal-tech/go-zero/tools/goctl/util"
  4. "github.com/urfave/cli"
  5. )
  6. const (
  7. category = "docker"
  8. dockerTemplateFile = "docker.tpl"
  9. dockerTemplate = `FROM golang:alpine AS builder
  10. LABEL stage=gobuilder
  11. ENV CGO_ENABLED 0
  12. ENV GOOS linux
  13. ENV GOPROXY https://goproxy.cn,direct
  14. WORKDIR /build/zero
  15. COPY . .
  16. COPY {{.goRelPath}}/etc /app/etc
  17. RUN go build -ldflags="-s -w" -o /app/{{.exeFile}} {{.goRelPath}}/{{.goFile}}
  18. FROM alpine
  19. RUN apk update --no-cache
  20. RUN apk add --no-cache ca-certificates
  21. RUN apk add --no-cache tzdata
  22. ENV TZ Asia/Shanghai
  23. WORKDIR /app
  24. COPY --from=builder /app/{{.exeFile}} /app/{{.exeFile}}
  25. COPY --from=builder /app/etc /app/etc
  26. CMD ["./{{.exeFile}}"{{.argument}}]
  27. `
  28. )
  29. func GenTemplates(_ *cli.Context) error {
  30. return util.InitTemplates(category, map[string]string{
  31. dockerTemplateFile: dockerTemplate,
  32. })
  33. }