Merge pull request #168 from mavimo/define-target-multistage-build

Allow build for a specific target
This commit is contained in:
Brad Rydzewski 2018-02-21 12:38:42 -08:00 committed by GitHub
commit 1e396b3b9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -146,6 +146,11 @@ func main() {
Usage: "build args", Usage: "build args",
EnvVar: "PLUGIN_BUILD_ARGS_FROM_ENV", EnvVar: "PLUGIN_BUILD_ARGS_FROM_ENV",
}, },
cli.StringFlag{
Name: "target",
Usage: "build target",
EnvVar: "PLUGIN_TARGET",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "squash", Name: "squash",
Usage: "squash the layers at build time", Usage: "squash the layers at build time",
@ -232,6 +237,7 @@ func run(c *cli.Context) error {
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"), Args: c.StringSlice("args"),
ArgsEnv: c.StringSlice("args-from-env"), ArgsEnv: c.StringSlice("args-from-env"),
Target: c.String("target"),
Squash: c.Bool("squash"), Squash: c.Bool("squash"),
Pull: c.BoolT("pull-image"), Pull: c.BoolT("pull-image"),
Compress: c.Bool("compress"), Compress: c.Bool("compress"),

View File

@ -44,6 +44,7 @@ type (
Tags []string // Docker build tags Tags []string // Docker build tags
Args []string // Docker build args Args []string // Docker build args
ArgsEnv []string // Docker build args from env ArgsEnv []string // Docker build args from env
Target string // Docker build target
Squash bool // Docker build squash Squash bool // Docker build squash
Pull bool // Docker build pull Pull bool // Docker build pull
Compress bool // Docker build compress Compress bool // Docker build compress
@ -208,6 +209,9 @@ func commandBuild(build Build) *exec.Cmd {
for _, arg := range build.Args { for _, arg := range build.Args {
args = append(args, "--build-arg", arg) args = append(args, "--build-arg", arg)
} }
if build.Target != "" {
args = append(args, "--target", build.Target)
}
labelSchema := []string{ labelSchema := []string{
fmt.Sprintf("build-date=%s", time.Now().Format(time.RFC3339)), fmt.Sprintf("build-date=%s", time.Now().Format(time.RFC3339)),