|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
"text/template"
|
|
|
@ -24,6 +25,7 @@ const (
|
|
|
|
// Docker describes a dockerfile
|
|
|
|
// Docker describes a dockerfile
|
|
|
|
type Docker struct {
|
|
|
|
type Docker struct {
|
|
|
|
Chinese bool
|
|
|
|
Chinese bool
|
|
|
|
|
|
|
|
GoMainFrom string
|
|
|
|
GoRelPath string
|
|
|
|
GoRelPath string
|
|
|
|
GoFile string
|
|
|
|
GoFile string
|
|
|
|
ExeFile string
|
|
|
|
ExeFile string
|
|
|
@ -65,11 +67,7 @@ func dockerCommand(_ *cobra.Command, _ []string) (err error) {
|
|
|
|
pathx.RegisterGoctlHome(home)
|
|
|
|
pathx.RegisterGoctlHome(home)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if len(goFile) == 0 {
|
|
|
|
if len(goFile) > 0 && !pathx.FileExists(goFile) {
|
|
|
|
return errors.New("-go can't be empty")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !pathx.FileExists(goFile) {
|
|
|
|
|
|
|
|
return fmt.Errorf("file %q not found", goFile)
|
|
|
|
return fmt.Errorf("file %q not found", goFile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -126,9 +124,13 @@ func findConfig(file, dir string) (string, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func generateDockerfile(goFile, base string, port int, version, timezone string, args ...string) error {
|
|
|
|
func generateDockerfile(goFile, base string, port int, version, timezone string, args ...string) error {
|
|
|
|
projPath, err := getFilePath(filepath.Dir(goFile))
|
|
|
|
var projPath string
|
|
|
|
if err != nil {
|
|
|
|
var err error
|
|
|
|
return err
|
|
|
|
if len(goFile) > 0 {
|
|
|
|
|
|
|
|
projPath, err = getFilePath(filepath.Dir(goFile))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if len(projPath) == 0 {
|
|
|
|
if len(projPath) == 0 {
|
|
|
@ -151,12 +153,27 @@ func generateDockerfile(goFile, base string, port int, version, timezone string,
|
|
|
|
builder.WriteString(`, "` + arg + `"`)
|
|
|
|
builder.WriteString(`, "` + arg + `"`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var exeName string
|
|
|
|
|
|
|
|
if len(varExeName) > 0 {
|
|
|
|
|
|
|
|
exeName = varExeName
|
|
|
|
|
|
|
|
} else if len(goFile) > 0 {
|
|
|
|
|
|
|
|
exeName = pathx.FileNameWithoutExt(filepath.Base(goFile))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
absPath, err := filepath.Abs(projPath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exeName = filepath.Base(absPath)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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(),
|
|
|
|
|
|
|
|
GoMainFrom: path.Join(projPath, goFile),
|
|
|
|
GoRelPath: projPath,
|
|
|
|
GoRelPath: projPath,
|
|
|
|
GoFile: goFile,
|
|
|
|
GoFile: goFile,
|
|
|
|
ExeFile: pathx.FileNameWithoutExt(filepath.Base(goFile)),
|
|
|
|
ExeFile: exeName,
|
|
|
|
BaseImage: base,
|
|
|
|
BaseImage: base,
|
|
|
|
HasPort: port > 0,
|
|
|
|
HasPort: port > 0,
|
|
|
|
Port: port,
|
|
|
|
Port: port,
|
|
|
|