feat: ability to specify runtime OSs where shell-local should run
This commit is contained in:
parent
29d041ea8a
commit
25c0b98363
|
@ -29,6 +29,9 @@ type Config struct {
|
|||
// The shebang value used when running inline scripts.
|
||||
InlineShebang string `mapstructure:"inline_shebang"`
|
||||
|
||||
// An array of multiple Runtime OSs to run on.
|
||||
OnlyOn []string
|
||||
|
||||
// The file extension to use for the file generated from the inline commands
|
||||
TempfileExtension string `mapstructure:"tempfile_extension"`
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
@ -58,6 +59,20 @@ func Run(ui packer.Ui, config *Config) (bool, error) {
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Check if command can execute against runtime.
|
||||
runCommand := false
|
||||
if len(config.OnlyOn) > 0 {
|
||||
for _, os := range config.OnlyOn {
|
||||
if os == runtime.GOOS {
|
||||
runCommand = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
runCommand = true
|
||||
}
|
||||
|
||||
if runCommand {
|
||||
ui.Say(fmt.Sprintf("Running local shell script: %s", script))
|
||||
|
||||
comm := &Communicator{
|
||||
|
@ -69,6 +84,7 @@ func Run(ui packer.Ui, config *Config) (bool, error) {
|
|||
// the other communicators; ultimately, this command is just used for
|
||||
// buffers and for reading the final exit status.
|
||||
flattenedCmd := strings.Join(interpolatedCmds, " ")
|
||||
|
||||
cmd := &packer.RemoteCmd{Command: flattenedCmd}
|
||||
log.Printf("[INFO] (shell-local): starting local command: %s", flattenedCmd)
|
||||
if err := cmd.StartWithUi(comm, ui); err != nil {
|
||||
|
@ -84,6 +100,10 @@ func Run(ui packer.Ui, config *Config) (bool, error) {
|
|||
cmd.ExitStatus,
|
||||
script)
|
||||
}
|
||||
} else {
|
||||
ui.Say(fmt.Sprintf("Skipping local shell script due to runtime OS: %s", script))
|
||||
log.Printf("[INFO] (shell-local): skipping command due to runtime OS not specified.")
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
|
|
@ -108,6 +108,14 @@ Optional parameters:
|
|||
**Important:** If you customize this, be sure to include something like the
|
||||
`-e` flag, otherwise individual steps failing won't fail the provisioner.
|
||||
|
||||
- `onlyon` (array of strings) - This is an array of
|
||||
[runtime operating systems](https://golang.org/doc/install/source#environment)
|
||||
where `shell-local` will only run on. This allows you to run `shell-local` *only*
|
||||
on specific compatible operating systems. If specified, shell-local will only
|
||||
execute if runtime operating system is in the list; otherwise it will skip the
|
||||
`shell-local` command. The default behavior is for `shell-local` to run if
|
||||
`onlyon` is not specified.
|
||||
|
||||
- `use_linux_pathing` (bool) - This is only relevant to windows hosts. If you
|
||||
are running Packer in a Windows environment with the Windows Subsystem for
|
||||
Linux feature enabled, and would like to invoke a bash script rather than
|
||||
|
|
Loading…
Reference in New Issue