mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
f997aee3ba
* simplify code, format makefile * simplify code * some optimize by kevwan and benying (#240) Co-authored-by: 杨志泉 <zhiquan.yang@yiducloud.cn> * optimization (#241) * optimize docker file generation, make docker build faster Co-authored-by: benying <31179034+benyingY@users.noreply.github.com> Co-authored-by: 杨志泉 <zhiquan.yang@yiducloud.cn> Co-authored-by: bittoy <bittoy@qq.com>
49 lines
956 B
Go
49 lines
956 B
Go
package docker
|
|
|
|
import (
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
const (
|
|
category = "docker"
|
|
dockerTemplateFile = "docker.tpl"
|
|
dockerTemplate = `FROM golang:alpine AS builder
|
|
|
|
LABEL stage=gobuilder
|
|
|
|
ENV CGO_ENABLED 0
|
|
ENV GOOS linux
|
|
{{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct{{end}}
|
|
|
|
WORKDIR /build/zero
|
|
|
|
ADD go.mod .
|
|
ADD go.sum .
|
|
RUN go mod download
|
|
COPY . .
|
|
COPY {{.GoRelPath}}/etc /app/etc
|
|
RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoRelPath}}/{{.GoFile}}
|
|
|
|
|
|
FROM alpine
|
|
|
|
RUN apk update --no-cache
|
|
RUN apk add --no-cache ca-certificates
|
|
RUN apk add --no-cache tzdata
|
|
ENV TZ Asia/Shanghai
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /app/{{.ExeFile}} /app/{{.ExeFile}}
|
|
COPY --from=builder /app/etc /app/etc
|
|
|
|
CMD ["./{{.ExeFile}}"{{.Argument}}]
|
|
`
|
|
)
|
|
|
|
func GenTemplates(_ *cli.Context) error {
|
|
return util.InitTemplates(category, map[string]string{
|
|
dockerTemplateFile: dockerTemplate,
|
|
})
|
|
}
|