From c79e8ddc8f51362d375afc995fa566bbf5723c52 Mon Sep 17 00:00:00 2001 From: Chris Lundquist Date: Tue, 31 May 2016 23:53:50 +0000 Subject: [PATCH] [lxd] more cleanup --- builder/lxd/builder_test.go | 22 ++++++++++++++++++++++ builder/lxd/config.go | 24 ++++++------------------ builder/lxd/step_publish.go | 2 ++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/builder/lxd/builder_test.go b/builder/lxd/builder_test.go index b84dd70d6..ad5a6c95a 100644 --- a/builder/lxd/builder_test.go +++ b/builder/lxd/builder_test.go @@ -32,6 +32,28 @@ func TestBuilderPrepare_ConfigFile(t *testing.T) { t.Fatalf("should not have error: %s", err) } + // Good, remote image + config = testConfig() + config["image"] = "remote:bar" + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + // Good, remote output image + config = testConfig() + config["output_image"] = "remote:foo" + warnings, err = b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + // Bad, missing image name config = testConfig() delete(config, "image") diff --git a/builder/lxd/config.go b/builder/lxd/config.go index c2201943e..ff75deed2 100644 --- a/builder/lxd/config.go +++ b/builder/lxd/config.go @@ -12,14 +12,11 @@ import ( type Config struct { common.PackerConfig `mapstructure:",squash"` - ///ConfigFile string `mapstructure:"config_file"` - OutputImage string `mapstructure:"output_image"` - ContainerName string `mapstructure:"container_name"` - CommandWrapper string `mapstructure:"command_wrapper"` - RawInitTimeout string `mapstructure:"init_timeout"` - Image string `mapstructure:"image"` - //EnvVars []string `mapstructure:"template_environment_vars"` - InitTimeout time.Duration + OutputImage string `mapstructure:"output_image"` + ContainerName string `mapstructure:"container_name"` + CommandWrapper string `mapstructure:"command_wrapper"` + Image string `mapstructure:"image"` + InitTimeout time.Duration ctx interpolate.Context } @@ -51,17 +48,8 @@ func NewConfig(raws ...interface{}) (*Config, error) { c.CommandWrapper = "{{.Command}}" } - if c.RawInitTimeout == "" { - c.RawInitTimeout = "20s" - } - if c.Image == "" { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("`image` is a required parameter for LXD.")) - } - - c.InitTimeout, err = time.ParseDuration(c.RawInitTimeout) - if err != nil { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("Failed parsing init_timeout: %s", err)) + errs = packer.MultiErrorAppend(errs, fmt.Errorf("`image` is a required parameter for LXD. Please specify an image by alias or fingerprint. e.g. `ubuntu-daily:x`")) } if errs != nil && len(errs.Errors) > 0 { diff --git a/builder/lxd/step_publish.go b/builder/lxd/step_publish.go index fa2d19914..e519a7252 100644 --- a/builder/lxd/step_publish.go +++ b/builder/lxd/step_publish.go @@ -21,6 +21,8 @@ func (s *stepPublish) Run(state multistep.StateBag) multistep.StepAction { name := config.ContainerName args := []string{ + // If we use `lxc stop `, an ephemeral container would die forever. + // `lxc publish` has special logic to handle this case. "lxc", "publish", "--force", name, "--alias", config.OutputImage, }