2015-09-02 06:29:26 -04:00
|
|
|
package shell_local
|
|
|
|
|
|
|
|
import (
|
2019-03-22 09:56:02 -04:00
|
|
|
"context"
|
|
|
|
|
2018-02-23 16:26:31 -05:00
|
|
|
sl "github.com/hashicorp/packer/common/shell-local"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2015-09-02 06:29:26 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type PostProcessor struct {
|
2018-02-27 15:50:42 -05:00
|
|
|
config sl.Config
|
2015-09-02 06:29:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type ExecuteCommandTemplate struct {
|
2016-11-21 08:39:34 -05:00
|
|
|
Vars string
|
|
|
|
Script string
|
2015-09-02 06:29:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PostProcessor) Configure(raws ...interface{}) error {
|
2018-02-28 17:35:42 -05:00
|
|
|
err := sl.Decode(&p.config, raws...)
|
2015-09-02 06:29:26 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-02 15:32:34 -05:00
|
|
|
if len(p.config.ExecuteCommand) == 1 {
|
|
|
|
// Backwards compatibility -- before we merged the shell-local
|
|
|
|
// post-processor and provisioners, the post-processor accepted
|
|
|
|
// execute_command as a string rather than a slice of strings. It didn't
|
|
|
|
// have a configurable call to shell program, automatically prepending
|
|
|
|
// the user-supplied execute_command string with "sh -c". If users are
|
|
|
|
// still using the old way of defining ExecuteCommand (by supplying a
|
|
|
|
// single string rather than a slice of strings) then we need to
|
|
|
|
// prepend this command with the call that the post-processor defaulted
|
|
|
|
// to before.
|
2018-03-01 11:48:21 -05:00
|
|
|
p.config.ExecuteCommand = append([]string{"sh", "-c"}, p.config.ExecuteCommand...)
|
|
|
|
}
|
2015-09-02 06:29:26 -04:00
|
|
|
|
2018-02-27 15:50:42 -05:00
|
|
|
return sl.Validate(&p.config)
|
2015-09-02 06:29:26 -04:00
|
|
|
}
|
|
|
|
|
2019-04-08 13:59:42 -04:00
|
|
|
func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, bool, error) {
|
2018-02-28 14:53:53 -05:00
|
|
|
// this particular post-processor doesn't do anything with the artifact
|
|
|
|
// except to return it.
|
2015-09-02 06:29:26 -04:00
|
|
|
|
2019-04-03 15:03:40 -04:00
|
|
|
success, retErr := sl.Run(ui, &p.config)
|
|
|
|
if !success {
|
|
|
|
return nil, false, false, retErr
|
2017-01-23 17:15:51 -05:00
|
|
|
}
|
|
|
|
|
2019-04-03 15:03:40 -04:00
|
|
|
// Force shell-local pp to keep the input artifact, because otherwise we'll
|
|
|
|
// lose it instead of being able to pass it through. If oyu want to delete
|
|
|
|
// the input artifact for a shell local pp, use the artifice pp to create a
|
|
|
|
// new artifact
|
|
|
|
return artifact, true, true, retErr
|
2017-01-23 17:15:51 -05:00
|
|
|
}
|