Skip to content

Commit

Permalink
Add support of --squash flag on build params
Browse files Browse the repository at this point in the history
  • Loading branch information
Kévin Darcel committed Jan 19, 2017
1 parent e13f711 commit ecf2746
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ func main() {
Usage: "build args",
EnvVar: "PLUGIN_BUILD_ARGS",
},
cli.BoolFlag{
Name: "squash",
Usage: "squash the layers at build time",
EnvVar: "PLUGIN_SQUASH",
},
cli.StringFlag{
Name: "repo",
Usage: "docker repository",
Expand Down Expand Up @@ -161,6 +166,7 @@ func run(c *cli.Context) error {
Context: c.String("context"),
Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"),
Squash: c.Bool("squash"),
Repo: c.String("repo"),
},
Daemon: Daemon{
Expand Down
32 changes: 21 additions & 11 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type (
Context string // Docker build context
Tags []string // Docker build tags
Args []string // Docker build args
Squash bool // Docker build squash
Repo string // Docker build repository
}

Expand Down Expand Up @@ -109,6 +110,11 @@ func (p Plugin) Exec() error {
fmt.Println("Registry credentials not provided. Guest mode enabled.")
}

if p.Build.Squash && !p.Daemon.Experimental {
fmt.Println("Squash build flag is only available when Docker deamon is started with experimental flag. Ignoring...")
p.Build.Squash = false
}

// add proxy build args
addProxyBuildArgs(&p.Build)

Expand Down Expand Up @@ -177,19 +183,23 @@ func commandInfo() *exec.Cmd {

// helper function to create the docker build command.
func commandBuild(build Build) *exec.Cmd {
cmd := exec.Command(
dockerExe, "build",
"--pull=true",
"--rm=true",
"-f", build.Dockerfile,
"-t", build.Name,
)

args := []string {
"build",
"--pull=true",
"--rm=true",
"-f", build.Dockerfile,
"-t", build.Name,
}

args = append(args, build.Context)
if build.Squash {
args = append(args, "--squash")
}
for _, arg := range build.Args {
cmd.Args = append(cmd.Args, "--build-arg", arg)
args = append(args, "--build-arg", arg)
}
cmd.Args = append(cmd.Args, build.Context)
return cmd

return exec.Command(dockerExe, args...)
}

// helper function to add proxy values from the environment
Expand Down

0 comments on commit ecf2746

Please sign in to comment.