[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)
|
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
|
// Bad, missing image name
|
||||||
config = testConfig()
|
config = testConfig()
|
||||||
delete(config, "image")
|
delete(config, "image")
|
||||||
|
|
|
@ -12,13 +12,10 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
common.PackerConfig `mapstructure:",squash"`
|
common.PackerConfig `mapstructure:",squash"`
|
||||||
///ConfigFile string `mapstructure:"config_file"`
|
|
||||||
OutputImage string `mapstructure:"output_image"`
|
OutputImage string `mapstructure:"output_image"`
|
||||||
ContainerName string `mapstructure:"container_name"`
|
ContainerName string `mapstructure:"container_name"`
|
||||||
CommandWrapper string `mapstructure:"command_wrapper"`
|
CommandWrapper string `mapstructure:"command_wrapper"`
|
||||||
RawInitTimeout string `mapstructure:"init_timeout"`
|
|
||||||
Image string `mapstructure:"image"`
|
Image string `mapstructure:"image"`
|
||||||
//EnvVars []string `mapstructure:"template_environment_vars"`
|
|
||||||
InitTimeout time.Duration
|
InitTimeout time.Duration
|
||||||
|
|
||||||
ctx interpolate.Context
|
ctx interpolate.Context
|
||||||
|
@ -51,17 +48,8 @@ func NewConfig(raws ...interface{}) (*Config, error) {
|
||||||
c.CommandWrapper = "{{.Command}}"
|
c.CommandWrapper = "{{.Command}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.RawInitTimeout == "" {
|
|
||||||
c.RawInitTimeout = "20s"
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Image == "" {
|
if c.Image == "" {
|
||||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("`image` is a required parameter for LXD."))
|
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`"))
|
||||||
}
|
|
||||||
|
|
||||||
c.InitTimeout, err = time.ParseDuration(c.RawInitTimeout)
|
|
||||||
if err != nil {
|
|
||||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Failed parsing init_timeout: %s", err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if errs != nil && len(errs.Errors) > 0 {
|
if errs != nil && len(errs.Errors) > 0 {
|
||||||
|
|
|
@ -21,6 +21,8 @@ func (s *stepPublish) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
name := config.ContainerName
|
name := config.ContainerName
|
||||||
|
|
||||||
args := []string{
|
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,
|
"lxc", "publish", "--force", name, "--alias", config.OutputImage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue