post-processor/shell-local: don't set executable bit for artifact files (#3505)

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Vasiliy Tolstov 2016-05-19 02:15:26 +03:00 committed by Chris Bednarski
parent e9a9219725
commit b67ee530c8
2 changed files with 20 additions and 18 deletions

View File

@ -4,13 +4,14 @@ import (
"bufio" "bufio"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os"
"strings"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config" "github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
"io/ioutil"
"os"
"strings"
) )
type Config struct { type Config struct {
@ -46,8 +47,9 @@ type PostProcessor struct {
} }
type ExecuteCommandTemplate struct { type ExecuteCommandTemplate struct {
Vars string Vars string
Path string Script string
Artifact string
} }
func (p *PostProcessor) Configure(raws ...interface{}) error { func (p *PostProcessor) Configure(raws ...interface{}) error {
@ -65,7 +67,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
} }
if p.config.ExecuteCommand == "" { if p.config.ExecuteCommand == "" {
p.config.ExecuteCommand = "chmod +x {{.Path}}; {{.Vars}} {{.Path}}" p.config.ExecuteCommand = "chmod +x {{.Script}}; {{.Vars}} {{.Script}} {{.Artifact}}"
} }
if p.config.Inline != nil && len(p.config.Inline) == 0 { if p.config.Inline != nil && len(p.config.Inline) == 0 {
@ -171,14 +173,14 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
copy(envVars[2:], p.config.Vars) copy(envVars[2:], p.config.Vars)
for _, file := range artifact.Files() { for _, file := range artifact.Files() {
for _, path := range scripts { for _, script := range scripts {
// Flatten the environment variables // Flatten the environment variables
flattendVars := strings.Join(envVars, " ") flattendVars := strings.Join(envVars, " ")
path := strings.Join([]string{path, file}, " ")
p.config.ctx.Data = &ExecuteCommandTemplate{ p.config.ctx.Data = &ExecuteCommandTemplate{
Vars: flattendVars, Vars: flattendVars,
Path: path, Script: script,
Artifact: file,
} }
command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx) command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
@ -194,19 +196,19 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
ui.Say(fmt.Sprintf( ui.Say(fmt.Sprintf(
"Executing local script: %s", "Executing local script: %s",
path)) script))
if err := cmd.StartWithUi(comm, ui); err != nil { if err := cmd.StartWithUi(comm, ui); err != nil {
return nil, false, fmt.Errorf( return nil, false, fmt.Errorf(
"Error executing script: %s\n\n"+ "Error executing script: %s\n\n"+
"Please see output above for more information.", "Please see output above for more information.",
path) script)
} }
if cmd.ExitStatus != 0 { if cmd.ExitStatus != 0 {
return nil, false, fmt.Errorf( return nil, false, fmt.Errorf(
"Erroneous exit code %d while executing script: %s\n\n"+ "Erroneous exit code %d while executing script: %s\n\n"+
"Please see output above for more information.", "Please see output above for more information.",
cmd.ExitStatus, cmd.ExitStatus,
path) script)
} }
} }
} }

View File

@ -54,11 +54,11 @@ Optional parameters:
as well, which are covered in the section below. as well, which are covered in the section below.
- `execute_command` (string) - The command to use to execute the script. By - `execute_command` (string) - The command to use to execute the script. By
default this is `chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}`. The value default this is `chmod +x {{.Script}}; {{.Vars}} {{.Script}} {{.Artifact}}`.
of this is treated as [configuration The value of this is treated as [configuration template](/docs/templates/configuration-templates.html).
template](/docs/templates/configuration-templates.html). There are two There are three available variables: `Script`, which is the path to the script
available variables: `Path`, which is the path to the script to run, and to run, `Vars`, which is the list of `environment_vars`, if configured and
`Vars`, which is the list of `environment_vars`, if configured. `Artifact`, which is path to artifact file.
- `inline_shebang` (string) - The - `inline_shebang` (string) - The
[shebang](http://en.wikipedia.org/wiki/Shebang_%28Unix%29) value to use when [shebang](http://en.wikipedia.org/wiki/Shebang_%28Unix%29) value to use when