From 9794f928666afe6a50746a809e9123e03c77d182 Mon Sep 17 00:00:00 2001 From: Anton Konovalov Date: Thu, 15 Oct 2015 14:16:09 +0300 Subject: [PATCH 1/2] fix(file): fixing work with Dockerfile.* now it's not work becaouse file != context see more here https://docs.docker.com/reference/commandline/build/ --- main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 0782478..dc2eff5 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,9 @@ type Docker struct { Repo string `json:"repo"` Tag string `json:"tag"` File string `json:"file"` - Dns []string `json:"dns"` + // see more here https://docs.docker.com/reference/commandline/build/ + Context string `json:"context"` + Dns []string `json:"dns"` } func main() { @@ -47,8 +49,8 @@ func main() { vargs.Registry = "https://index.docker.io/v1/" } // Set the Dockerfile path - if len(vargs.File) == 0 { - vargs.File = "." + if len(vargs.Context) == 0 { + vargs.Context = "." } // Set the Tag value if len(vargs.Tag) == 0 { @@ -121,8 +123,14 @@ func main() { trace(cmd) cmd.Run() + strCmd := []string{"/usr/bin/docker", "build", "--pull=true","--rm=true", "-t", vargs.Repo, vargs.Context} + // Add file flag to cmd + if len(vargs.File) != 0 { + strCmd = append(append(strCmd[0:3],"-f="+vargs.File),strCmd[4:]...) + } + // Build the container - cmd = exec.Command("/usr/bin/docker", "build", "--pull=true", "--rm=true", "-t", vargs.Repo, vargs.File) + cmd = exec.Command(strCmd[0],strCmd[1:]...) cmd.Dir = workspace.Path cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr From 0f4ab18017869908a2ecf4261e5be84c4ce6cf99 Mon Sep 17 00:00:00 2001 From: Anton Konovalov Date: Fri, 16 Oct 2015 10:37:17 +0300 Subject: [PATCH 2/2] refact(main): readable --- main.go | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index dc2eff5..8f3c8c3 100644 --- a/main.go +++ b/main.go @@ -12,19 +12,19 @@ import ( ) type Docker struct { - Storage string `json:"storage_driver"` - Registry string `json:"registry"` - Insecure bool `json:"insecure"` - Username string `json:"username"` - Password string `json:"password"` - Email string `json:"email"` - Auth string `json:"auth"` - Repo string `json:"repo"` - Tag string `json:"tag"` - File string `json:"file"` + Storage string `json:"storage_driver"` + Registry string `json:"registry"` + Insecure bool `json:"insecure"` + Username string `json:"username"` + Password string `json:"password"` + Email string `json:"email"` + Auth string `json:"auth"` + Repo string `json:"repo"` + Tag string `json:"tag"` + File string `json:"file"` // see more here https://docs.docker.com/reference/commandline/build/ - Context string `json:"context"` - Dns []string `json:"dns"` + Context string `json:"context"` + Dns []string `json:"dns"` } func main() { @@ -48,7 +48,11 @@ func main() { if len(vargs.Registry) == 0 { vargs.Registry = "https://index.docker.io/v1/" } - // Set the Dockerfile path + // Set the Dockerfile name + if len(vargs.File) == 0 { + vars.File = "Dockerfile" + } + // Set the Context value if len(vargs.Context) == 0 { vargs.Context = "." } @@ -123,14 +127,8 @@ func main() { trace(cmd) cmd.Run() - strCmd := []string{"/usr/bin/docker", "build", "--pull=true","--rm=true", "-t", vargs.Repo, vargs.Context} - // Add file flag to cmd - if len(vargs.File) != 0 { - strCmd = append(append(strCmd[0:3],"-f="+vargs.File),strCmd[4:]...) - } - // Build the container - cmd = exec.Command(strCmd[0],strCmd[1:]...) + cmd = exec.Command("/usr/bin/docker", "build", "--pull=true", "--rm=true", "-f", vars.File, "-t", vargs.Repo, vargs.Context) cmd.Dir = workspace.Path cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr