[lxd] more cleanup
This commit is contained in:
parent
607da30547
commit
c79e8ddc8f
|
@ -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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -21,6 +21,8 @@ func (s *stepPublish) Run(state multistep.StateBag) multistep.StepAction {
|
|||
name := config.ContainerName
|
||||
|
||||
args := []string{
|
||||
// If we use `lxc stop <container>`, an ephemeral container would die forever.
|
||||
// `lxc publish` has special logic to handle this case.
|
||||
"lxc", "publish", "--force", name, "--alias", config.OutputImage,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue