From b8849a9c2d34fe87586aa44e084c33f274d47ac8 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Tue, 27 Dec 2016 12:22:17 -0600 Subject: [PATCH] provisioner(converge): add version specification for bootstrapping --- provisioner/converge/provisioner.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/provisioner/converge/provisioner.go b/provisioner/converge/provisioner.go index aff92cae6..f71e7282a 100644 --- a/provisioner/converge/provisioner.go +++ b/provisioner/converge/provisioner.go @@ -14,18 +14,23 @@ import ( "encoding/json" + "regexp" + "github.com/mitchellh/packer/common" "github.com/mitchellh/packer/helper/config" "github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/template/interpolate" ) +var versionRegex = regexp.MustCompile(`[\.\-\d\w]*`) + // Config for Converge provisioner type Config struct { common.PackerConfig `mapstructure:",squash"` // Bootstrapping - NoBootstrap bool `mapstructure:"no_bootstrap"` // TODO: add a way to specify bootstrap version + NoBootstrap bool `mapstructure:"no_bootstrap"` + Version string `mapstructure:"version"` // Modules ModuleDirs []ModuleDir `mapstructure:"module_dirs"` @@ -67,6 +72,11 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { return err } + // validate version + if !versionRegex.Match([]byte(p.config.Version)) { + return fmt.Errorf("Invalid Converge version %q specified. Valid versions include only letters, numbers, dots, and dashes", p.config.Version) + } + // validate sources and destinations for i, dir := range p.config.ModuleDirs { if dir.Source == "" { @@ -135,9 +145,15 @@ func (p *Provisioner) maybeBootstrap(ui packer.Ui, comm packer.Communicator) err return fmt.Errorf("Error uploading script: %s", err) } + // construct command + command := "/bin/sh /tmp/install-converge.sh" + if p.config.Version != "" { + command += " -v " + p.config.Version + } + var out bytes.Buffer cmd := &packer.RemoteCmd{ - Command: "/bin/sh /tmp/install-converge.sh", + Command: command, Stdin: nil, Stdout: &out, Stderr: &out,