Commit 0b5f4d9d authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

provisioner/shell: make build name and builder type env vars [GH-154]

parent 9387ba0f
......@@ -31,6 +31,9 @@ IMPROVEMENTS:
errors. [GH-104]
* amazon-ebs: Credentials will come from IAM role if available. [GH-160]
* amazon-ebs: Verify the source AMI is EBS-backed before launching. [GH-169]
* shell provisioner: the build name and builder type are available in
the `PACKER_BUILD_NAME` and `PACKER_BUILDER_TYPE` env vars by default,
respectively. [GH-154]
* vmware: error if shutdown command has non-zero exit status.
BUG FIXES:
......
......@@ -47,6 +47,10 @@ type config struct {
// should be used to specify where the script goes, {{ .Vars }}
// can be used to inject the environment_vars into the environment.
ExecuteCommand string `mapstructure:"execute_command"`
// Packer configurations, these come from Packer itself
PackerBuildName string `mapstructure:"packer_build_name"`
PackerBuilderType string `mapstructure:"packer_builder_type"`
}
type Provisioner struct {
......@@ -139,7 +143,9 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
for _, kv := range p.config.Vars {
vs := strings.Split(kv, "=")
if len(vs) != 2 || vs[0] == "" {
errs = append(errs, fmt.Errorf("Environment variable not in format 'key=value': %s", kv))
errs = append(
errs,
fmt.Errorf("Environment variable not in format 'key=value': %s", kv))
}
}
......@@ -182,6 +188,12 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
tf.Close()
}
// Build our variables up by adding in the build name and builder type
envVars := make([]string, len(p.config.Vars)+2)
envVars[0] = "PACKER_BUILD_NAME=" + p.config.PackerBuildName
envVars[1] = "PACKER_BUILDER_TYPE=" + p.config.PackerBuilderType
copy(envVars[2:], p.config.Vars)
for _, path := range scripts {
ui.Say(fmt.Sprintf("Provisioning with shell script: %s", path))
......@@ -202,7 +214,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
f.Close()
// Flatten the environment variables
flattendVars := strings.Join(p.config.Vars, " ")
flattendVars := strings.Join(envVars, " ")
// Compile the command
var command bytes.Buffer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment