|
|
@ -30,6 +30,7 @@ type Docker struct {
|
|
|
|
HasPort bool
|
|
|
|
HasPort bool
|
|
|
|
Port int
|
|
|
|
Port int
|
|
|
|
Argument string
|
|
|
|
Argument string
|
|
|
|
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DockerCommand provides the entry for goctl docker
|
|
|
|
// DockerCommand provides the entry for goctl docker
|
|
|
@ -42,6 +43,11 @@ func DockerCommand(c *cli.Context) (err error) {
|
|
|
|
|
|
|
|
|
|
|
|
goFile := c.String("go")
|
|
|
|
goFile := c.String("go")
|
|
|
|
home := c.String("home")
|
|
|
|
home := c.String("home")
|
|
|
|
|
|
|
|
version := c.String("version")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(version) > 0 {
|
|
|
|
|
|
|
|
version = version + "-"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if len(home) > 0 {
|
|
|
|
if len(home) > 0 {
|
|
|
|
util.RegisterGoctlHome(home)
|
|
|
|
util.RegisterGoctlHome(home)
|
|
|
@ -57,7 +63,7 @@ func DockerCommand(c *cli.Context) (err error) {
|
|
|
|
|
|
|
|
|
|
|
|
port := c.Int("port")
|
|
|
|
port := c.Int("port")
|
|
|
|
if _, err := os.Stat(etcDir); os.IsNotExist(err) {
|
|
|
|
if _, err := os.Stat(etcDir); os.IsNotExist(err) {
|
|
|
|
return generateDockerfile(goFile, port)
|
|
|
|
return generateDockerfile(goFile, port, version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cfg, err := findConfig(goFile, etcDir)
|
|
|
|
cfg, err := findConfig(goFile, etcDir)
|
|
|
@ -65,7 +71,7 @@ func DockerCommand(c *cli.Context) (err error) {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := generateDockerfile(goFile, port, "-f", "etc/"+cfg); err != nil {
|
|
|
|
if err := generateDockerfile(goFile, port, version, "-f", "etc/"+cfg); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -106,7 +112,7 @@ func findConfig(file, dir string) (string, error) {
|
|
|
|
return files[0], nil
|
|
|
|
return files[0], nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func generateDockerfile(goFile string, port int, args ...string) error {
|
|
|
|
func generateDockerfile(goFile string, port int, version string, args ...string) error {
|
|
|
|
projPath, err := getFilePath(filepath.Dir(goFile))
|
|
|
|
projPath, err := getFilePath(filepath.Dir(goFile))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -147,6 +153,7 @@ func generateDockerfile(goFile string, port int, args ...string) error {
|
|
|
|
HasPort: port > 0,
|
|
|
|
HasPort: port > 0,
|
|
|
|
Port: port,
|
|
|
|
Port: port,
|
|
|
|
Argument: builder.String(),
|
|
|
|
Argument: builder.String(),
|
|
|
|
|
|
|
|
Version: version,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|