template.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package gen
  2. const (
  3. dockerTemplate = `FROM golang:alpine AS builder
  4. LABEL stage=gobuilder
  5. ENV CGO_ENABLED 0
  6. ENV GOOS linux
  7. ENV GOPROXY https://goproxy.cn,direct
  8. WORKDIR $GOPATH/src/{{.projectName}}
  9. COPY . .
  10. RUN go build -ldflags="-s -w" -o /app/{{.exeFile}} {{.goRelPath}}/{{.goFile}}
  11. FROM alpine
  12. RUN apk update --no-cache
  13. RUN apk add --no-cache ca-certificates
  14. RUN apk add --no-cache tzdata
  15. ENV TZ Asia/Shanghai
  16. WORKDIR /app
  17. COPY --from=builder /app/{{.exeFile}} /app/{{.exeFile}}
  18. CMD ["./{{.exeFile}}"{{.argument}}]
  19. `
  20. makefileTemplate = `version := v$(shell /bin/date "+%y%m%d%H%M%S")
  21. build:
  22. docker pull alpine
  23. docker pull golang:alpine
  24. cd $(GOPATH)/src/xiao && docker build -t registry.cn-hangzhou.aliyuncs.com/xapp/{{.exeFile}}:$(version) . -f {{.relPath}}/Dockerfile
  25. docker image prune --filter label=stage=gobuilder -f
  26. push: build
  27. docker push registry.cn-hangzhou.aliyuncs.com/xapp/{{.exeFile}}:$(version)
  28. deploy: push
  29. kubectl -n {{.namespace}} set image deployment/{{.exeFile}}-deployment {{.exeFile}}=registry-vpc.cn-hangzhou.aliyuncs.com/xapp/{{.exeFile}}:$(version)
  30. `
  31. )