mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-22 10:10:39 +00:00
Add support of --squash flag on build params
This commit is contained in:
parent
f55d828a22
commit
66f66c1b1c
6
main.go
6
main.go
@ -113,6 +113,11 @@ func main() {
|
|||||||
Usage: "build args",
|
Usage: "build args",
|
||||||
EnvVar: "PLUGIN_BUILD_ARGS",
|
EnvVar: "PLUGIN_BUILD_ARGS",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "squash",
|
||||||
|
Usage: "squash the layers at build time",
|
||||||
|
EnvVar: "PLUGIN_SQUASH",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "repo",
|
Name: "repo",
|
||||||
Usage: "docker repository",
|
Usage: "docker repository",
|
||||||
@ -161,6 +166,7 @@ func run(c *cli.Context) error {
|
|||||||
Context: c.String("context"),
|
Context: c.String("context"),
|
||||||
Tags: c.StringSlice("tags"),
|
Tags: c.StringSlice("tags"),
|
||||||
Args: c.StringSlice("args"),
|
Args: c.StringSlice("args"),
|
||||||
|
Squash: c.Bool("squash"),
|
||||||
Repo: c.String("repo"),
|
Repo: c.String("repo"),
|
||||||
},
|
},
|
||||||
Daemon: Daemon{
|
Daemon: Daemon{
|
||||||
|
26
plugin.go
26
plugin.go
@ -46,6 +46,7 @@ type (
|
|||||||
Context string // Docker build context
|
Context string // Docker build context
|
||||||
Tags []string // Docker build tags
|
Tags []string // Docker build tags
|
||||||
Args []string // Docker build args
|
Args []string // Docker build args
|
||||||
|
Squash bool // Docker build squash
|
||||||
Repo string // Docker build repository
|
Repo string // Docker build repository
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +110,11 @@ func (p Plugin) Exec() error {
|
|||||||
fmt.Println("Registry credentials not provided. Guest mode enabled.")
|
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
|
// add proxy build args
|
||||||
addProxyBuildArgs(&p.Build)
|
addProxyBuildArgs(&p.Build)
|
||||||
|
|
||||||
@ -177,19 +183,23 @@ func commandInfo() *exec.Cmd {
|
|||||||
|
|
||||||
// helper function to create the docker build command.
|
// helper function to create the docker build command.
|
||||||
func commandBuild(build Build) *exec.Cmd {
|
func commandBuild(build Build) *exec.Cmd {
|
||||||
cmd := exec.Command(
|
args := []string {
|
||||||
dockerExe, "build",
|
"build",
|
||||||
"--pull=true",
|
"--pull=true",
|
||||||
"--rm=true",
|
"--rm=true",
|
||||||
"-f", build.Dockerfile,
|
"-f", build.Dockerfile,
|
||||||
"-t", build.Name,
|
"-t", build.Name,
|
||||||
)
|
|
||||||
|
|
||||||
for _, arg := range build.Args {
|
|
||||||
cmd.Args = append(cmd.Args, "--build-arg", arg)
|
|
||||||
}
|
}
|
||||||
cmd.Args = append(cmd.Args, build.Context)
|
|
||||||
return cmd
|
args = append(args, build.Context)
|
||||||
|
if build.Squash {
|
||||||
|
args = append(args, "--squash")
|
||||||
|
}
|
||||||
|
for _, arg := range build.Args {
|
||||||
|
args = append(args, "--build-arg", arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
return exec.Command(dockerExe, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to add proxy values from the environment
|
// helper function to add proxy values from the environment
|
||||||
|
Loading…
Reference in New Issue
Block a user