From 9281fada2d864669ee10f775288485d2091940d4 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Thu, 2 May 2019 16:01:35 +0200 Subject: [PATCH] prevent a breaking change so that we can merge the `-parallel-builds` option first. --- command/build.go | 21 +++++++++++++-------- command/build_test.go | 10 +++++----- contrib/zsh-completion/_packer | 3 ++- website/source/docs/commands/build.html.md | 9 +++++++-- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/command/build.go b/command/build.go index b9d063e78..0ed93b79e 100644 --- a/command/build.go +++ b/command/build.go @@ -26,8 +26,8 @@ type BuildCommand struct { } func (c *BuildCommand) Run(args []string) int { - var cfgColor, cfgDebug, cfgForce, cfgTimestamp bool - var cfgParallel int64 + var cfgColor, cfgDebug, cfgForce, cfgTimestamp, cfgParallel bool + var cfgParallelBuilds int64 var cfgOnError string flags := c.Meta.FlagSet("build", FlagSetBuildFilter|FlagSetVars) flags.Usage = func() { c.Ui.Say(c.Help()) } @@ -37,7 +37,8 @@ func (c *BuildCommand) Run(args []string) int { flags.BoolVar(&cfgTimestamp, "timestamp-ui", false, "") flagOnError := enumflag.New(&cfgOnError, "cleanup", "abort", "ask") flags.Var(flagOnError, "on-error", "") - flags.Int64Var(&cfgParallel, "parallel", 0, "") + flags.BoolVar(&cfgParallel, "parallel", true, "") + flags.Int64Var(&cfgParallelBuilds, "parallel-builds", 0, "") if err := flags.Parse(args); err != nil { return 1 } @@ -153,8 +154,11 @@ func (c *BuildCommand) Run(args []string) int { }{m: make(map[string][]packer.Artifact)} errors := make(map[string]error) // ctx := context.Background() - if cfgParallel < 1 { - cfgParallel = math.MaxInt64 + if cfgParallel == false { + cfgParallelBuilds = 1 + } + if cfgParallelBuilds < 1 { + cfgParallelBuilds = math.MaxInt64 } buildCtx, cancelCtx := context.WithCancel(context.Background()) @@ -172,7 +176,7 @@ func (c *BuildCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("Cancelling build after receiving %s", sig)) }() - limitParallel := semaphore.NewWeighted(cfgParallel) + limitParallel := semaphore.NewWeighted(cfgParallelBuilds) for _, b := range builds { // Increment the waitgroup so we wait for this item to finish properly wg.Add(1) @@ -210,7 +214,7 @@ func (c *BuildCommand) Run(args []string) int { wg.Wait() } - if cfgParallel == 1 { + if cfgParallelBuilds == 1 { log.Printf("Parallelization disabled, waiting for build to finish: %s", b.Name()) wg.Wait() } @@ -323,7 +327,8 @@ Options: -force Force a build to continue if artifacts exist, deletes existing artifacts. -machine-readable Produce machine-readable output. -on-error=[cleanup|abort|ask] If the build fails do: clean up (default), abort, or ask. - -parallel=count Number of builds to run in parallel. (Default: 0) + -parallel=false Disable parallelization. (Default: true) + -parallel-builds=1 Number of builds to run in parallel. 0 means no limit (Default: 0) -timestamp-ui Enable prefixing of each ui output with an RFC3339 timestamp. -var 'key=value' Variable for templates, can be used multiple times. -var-file=path JSON file containing user variables. diff --git a/command/build_test.go b/command/build_test.go index 12282769b..8f3661b95 100644 --- a/command/build_test.go +++ b/command/build_test.go @@ -17,7 +17,7 @@ func TestBuildOnlyFileCommaFlags(t *testing.T) { } args := []string{ - "-parallel=1", + "-parallel=false", "-only=chocolate,vanilla", filepath.Join(testFixture("build-only"), "template.json"), } @@ -59,7 +59,7 @@ func TestBuildStdin(t *testing.T) { defer func() { os.Stdin = stdin }() defer cleanup() - if code := c.Run([]string{"-parallel=1", "-"}); code != 0 { + if code := c.Run([]string{"-parallel=false", "-"}); code != 0 { fatalCommand(t, c.Meta) } @@ -77,7 +77,7 @@ func TestBuildOnlyFileMultipleFlags(t *testing.T) { } args := []string{ - "-parallel=1", + "-parallel=false", "-only=chocolate", "-only=cherry", "-only=apple", // ignored @@ -111,7 +111,7 @@ func TestBuildEverything(t *testing.T) { } args := []string{ - "-parallel=1", + "-parallel=false", `-except=`, filepath.Join(testFixture("build-only"), "template.json"), } @@ -136,7 +136,7 @@ func TestBuildExceptFileCommaFlags(t *testing.T) { } args := []string{ - "-parallel=1", + "-parallel=false", "-except=chocolate,vanilla", filepath.Join(testFixture("build-only"), "template.json"), } diff --git a/contrib/zsh-completion/_packer b/contrib/zsh-completion/_packer index 4a79f3cd6..7bf52bbba 100644 --- a/contrib/zsh-completion/_packer +++ b/contrib/zsh-completion/_packer @@ -17,7 +17,8 @@ _packer () { '-except=[(foo,bar,baz) Run all builds and post-procesors other than these.]' '-on-error=[(cleanup,abort,ask) If the build fails do: clean up (default), abort, or ask.]' '-only=[(foo,bar,baz) Only build the given builds by name.]' - '-parallel=[(0) Number of builds to run in parallel. (Default: 0)]' + '-parallel=[(false) Disable parallelization. (Default: false)]' + '-parallel-builds=[(0) Number of builds to run in parallel. (Defaults to infinite: 0)]' '-var[("key=value") Variable for templates, can be used multiple times.]' '-var-file=[(path) JSON file containing user variables.]' '(-)*:files:_files -g "*.json"' diff --git a/website/source/docs/commands/build.html.md b/website/source/docs/commands/build.html.md index a1d416245..c5109e2e3 100644 --- a/website/source/docs/commands/build.html.md +++ b/website/source/docs/commands/build.html.md @@ -52,8 +52,13 @@ artifacts that are created will be outputted at the end of the build. attribute is specified within the configuration. `-only` does not apply to post-processors. -- `-parallel=1` - Limit the number of builds to run in parallel (no limit by - default). +- `-parallel=false` - /!\ Deprecated, use `-parallel-builds=1` instead, + setting `-parallel-builds=N` to more that 0 will ignore the `-parallel` + setting. Set `-parallel=false` to disable parallelization of multiple + builders (on by default). + +- `-parallel-builds=N` - Limit the number of builds to run in parallel, 0 + means no limit (defaults to 0). - `-timestamp-ui` - Enable prefixing of each ui output with an RFC3339 timestamp.