chore: refine docker for better compatible with package main (#1944)

* chore: refine docker for better compatible with package main

* chore: default to current dir on goctl docker command
master
Kevin Wan 2 years ago committed by GitHub
parent 3fbe0f87b7
commit 289a325757
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,7 +21,7 @@ var (
) )
func init() { func init() {
Cmd.Flags().StringVar(&varStringGo, "go", "", "The file that contains main function") Cmd.Flags().StringVar(&varStringGo, "go", ".", "The directory that contains main function")
Cmd.Flags().StringVar(&varStringBase, "base", "scratch", "The base image to build the docker image, default scratch") 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().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") 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,12 +151,17 @@ func generateDockerfile(goFile, base string, port int, version, timezone string,
builder.WriteString(`, "` + arg + `"`) builder.WriteString(`, "` + arg + `"`)
} }
absGoPath, err := filepath.Abs(goFile)
if err != nil {
return err
}
t := template.Must(template.New("dockerfile").Parse(text)) t := template.Must(template.New("dockerfile").Parse(text))
return t.Execute(out, Docker{ return t.Execute(out, Docker{
Chinese: env.InChina(), Chinese: env.InChina(),
GoRelPath: projPath, GoRelPath: projPath,
GoFile: goFile, GoFile: goFile,
ExeFile: pathx.FileNameWithoutExt(filepath.Base(goFile)), ExeFile: filepath.Base(absGoPath),
BaseImage: base, BaseImage: base,
HasPort: port > 0, HasPort: port > 0,
Port: port, Port: port,

@ -15,7 +15,7 @@ ADD go.sum .
RUN go mod download RUN go mod download
COPY . . COPY . .
{{if .Argument}}COPY {{.GoRelPath}}/etc /app/etc {{if .Argument}}COPY {{.GoRelPath}}/etc /app/etc
{{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoRelPath}}/{{.GoFile}} {{end}}RUN go build -ldflags="-s -w" -o /app/{{.ExeFile}} {{.GoRelPath}}
FROM {{.BaseImage}} FROM {{.BaseImage}}

@ -46,10 +46,10 @@ package {{.pkg}}
{{.vars}} {{.vars}}
{{.types}} {{.types}}
{{.new}} {{.new}}
{{.insert}} {{.delete}}
{{.find}} {{.find}}
{{.insert}}
{{.update}} {{.update}}
{{.delete}}
{{.extraMethod}} {{.extraMethod}}
{{.tableName}} {{.tableName}}
`, util.DoNotEditHead) `, util.DoNotEditHead)

Loading…
Cancel
Save