From f6bc158a8038cb966e57abff8b47608b52868c31 Mon Sep 17 00:00:00 2001 From: Chris Lundquist Date: Mon, 4 Sep 2017 17:57:55 +0000 Subject: [PATCH] [lxd] minor fixups for new styles and docs --- builder/lxd/builder.go | 30 ++++-------------------- builder/lxd/communicator.go | 2 +- website/source/docs/builders/lxd.html.md | 4 +++- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/builder/lxd/builder.go b/builder/lxd/builder.go index 9447f777f..bd3877c15 100644 --- a/builder/lxd/builder.go +++ b/builder/lxd/builder.go @@ -2,12 +2,11 @@ package lxd import ( "errors" + "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/template/interpolate" "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/common" - "github.com/mitchellh/packer/packer" - "github.com/mitchellh/packer/template/interpolate" "log" - "runtime" ) // The unique ID for this builder @@ -33,10 +32,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { } func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { - if runtime.GOOS != "linux" { - return nil, errors.New("The lxc builder only works on linux environments.") - } - wrappedCommand := func(command string) (string, error) { b.config.ctx.Data = &wrappedCommandTemplate{Command: command} return interpolate.Render(b.config.CommandWrapper, &b.config.ctx) @@ -57,15 +52,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe state.Put("wrappedCommand", CommandWrapper(wrappedCommand)) // Run - if b.config.PackerDebug { - b.runner = &multistep.DebugRunner{ - Steps: steps, - PauseFn: common.MultistepDebugFn(ui), - } - } else { - b.runner = &multistep.BasicRunner{Steps: steps} - } - + b.runner = common.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, state) b.runner.Run(state) // If there was an error, return that @@ -73,15 +60,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe return nil, rawErr.(error) } - // If we were interrupted or cancelled, then just exit. - if _, ok := state.GetOk(multistep.StateCancelled); ok { - return nil, errors.New("Build was cancelled.") - } - - if _, ok := state.GetOk(multistep.StateHalted); ok { - return nil, errors.New("Build was halted.") - } - artifact := &Artifact{ id: state.Get("imageFingerprint").(string), } diff --git a/builder/lxd/communicator.go b/builder/lxd/communicator.go index abb1f16a1..4a8970668 100644 --- a/builder/lxd/communicator.go +++ b/builder/lxd/communicator.go @@ -71,7 +71,7 @@ func (c *Communicator) UploadDir(dst string, src string, exclude []string) error // As a work around, we tar up the folder, upload it as a file, then extract it // Don't use 'z' flag as compressing may take longer and the transfer is likely local. - // If this isn't the case, it is possible for the user to crompress in another step then transfer. + // If this isn't the case, it is possible for the user to compress in another step then transfer. // It wouldn't be possibe to disable compression, without exposing this option. tar, err := c.CmdWrapper(fmt.Sprintf("tar -cf - -C %s .", src)) if err != nil { diff --git a/website/source/docs/builders/lxd.html.md b/website/source/docs/builders/lxd.html.md index 716c8bf20..dd386b1b0 100644 --- a/website/source/docs/builders/lxd.html.md +++ b/website/source/docs/builders/lxd.html.md @@ -46,5 +46,7 @@ Below is a fully functioning example. - `name` (string) - The name of the started container. Defaults to `packer-$PACKER_BUILD_NAME`. -- `output_image` (string) - The name of the output artifact. Defaults to `name` +- `output_image` (string) - The name of the output artifact. Defaults to `name`. + +- `command_wrapper` (string) - lets you prefix all builder commands, such as with `ssh` for a remote build host. Defaults to `""`.