mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
fix: generate bad Dockerfile on given dir (#1980)
This commit is contained in:
parent
8be47b9c99
commit
4d34998338
@ -21,7 +21,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
Cmd.Flags().StringVar(&varStringGo, "go", ".", "The directory that contains main function")
|
||||
Cmd.Flags().StringVar(&varStringGo, "go", "", "The file that contains main function")
|
||||
Cmd.Flags().StringVar(&varStringBase, "base", "scratch", "The base image to build the docker image, default scratch")
|
||||
Cmd.Flags().IntVar(&varIntPort, "port", 0, "The port to expose, default none")
|
||||
Cmd.Flags().StringVar(&varStringHome, "home", "", "The goctl home path of the template, --home and --remote cannot be set at the same time, if they are, --remote has higher priority")
|
||||
|
@ -151,17 +151,12 @@ func generateDockerfile(goFile, base string, port int, version, timezone string,
|
||||
builder.WriteString(`, "` + arg + `"`)
|
||||
}
|
||||
|
||||
absGoPath, err := filepath.Abs(goFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t := template.Must(template.New("dockerfile").Parse(text))
|
||||
return t.Execute(out, Docker{
|
||||
Chinese: env.InChina(),
|
||||
GoRelPath: projPath,
|
||||
GoFile: goFile,
|
||||
ExeFile: filepath.Base(absGoPath),
|
||||
ExeFile: pathx.FileNameWithoutExt(filepath.Base(goFile)),
|
||||
BaseImage: base,
|
||||
HasPort: port > 0,
|
||||
Port: port,
|
||||
|
@ -15,7 +15,7 @@ ADD go.sum .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
{{if .Argument}}COPY {{.GoRelPath}}/etc /app/etc
|
||||
{{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoRelPath}}
|
||||
{{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoRelPath}}/{{.GoFile}}
|
||||
|
||||
|
||||
FROM {{.BaseImage}}
|
||||
|
Loading…
Reference in New Issue
Block a user