provisioner/shell: make build name and builder type env vars [GH-154]
This commit is contained in:
parent
9387ba0fd4
commit
0b5f4d9d17
|
@ -31,6 +31,9 @@ IMPROVEMENTS:
|
||||||
errors. [GH-104]
|
errors. [GH-104]
|
||||||
* amazon-ebs: Credentials will come from IAM role if available. [GH-160]
|
* 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]
|
* 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.
|
* vmware: error if shutdown command has non-zero exit status.
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
|
|
@ -47,6 +47,10 @@ type config struct {
|
||||||
// should be used to specify where the script goes, {{ .Vars }}
|
// should be used to specify where the script goes, {{ .Vars }}
|
||||||
// can be used to inject the environment_vars into the environment.
|
// can be used to inject the environment_vars into the environment.
|
||||||
ExecuteCommand string `mapstructure:"execute_command"`
|
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 {
|
type Provisioner struct {
|
||||||
|
@ -139,7 +143,9 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
for _, kv := range p.config.Vars {
|
for _, kv := range p.config.Vars {
|
||||||
vs := strings.Split(kv, "=")
|
vs := strings.Split(kv, "=")
|
||||||
if len(vs) != 2 || vs[0] == "" {
|
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()
|
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 {
|
for _, path := range scripts {
|
||||||
ui.Say(fmt.Sprintf("Provisioning with shell script: %s", path))
|
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()
|
f.Close()
|
||||||
|
|
||||||
// Flatten the environment variables
|
// Flatten the environment variables
|
||||||
flattendVars := strings.Join(p.config.Vars, " ")
|
flattendVars := strings.Join(envVars, " ")
|
||||||
|
|
||||||
// Compile the command
|
// Compile the command
|
||||||
var command bytes.Buffer
|
var command bytes.Buffer
|
||||||
|
|
Loading…
Reference in New Issue