Merge pull request #6878 from jvasallo/f-shell-local-specificos
feat: ability to specify runtime OSs where shell-local should run
This commit is contained in:
commit
6597b7e0de
|
@ -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 `mapstructure:"only_on"`
|
||||
|
||||
// The file extension to use for the file generated from the inline commands
|
||||
TempfileExtension string `mapstructure:"tempfile_extension"`
|
||||
|
||||
|
@ -159,6 +162,25 @@ func Validate(config *Config) error {
|
|||
fmt.Errorf("Bad script '%s': %s", path, err))
|
||||
}
|
||||
}
|
||||
|
||||
// Check for properly formatted go os types
|
||||
supported_syslist := []string{"darwin", "freebsd", "linux", "openbsd", "solaris", "windows"}
|
||||
if len(config.OnlyOn) > 0 {
|
||||
for _, provided_os := range config.OnlyOn {
|
||||
supported_os := false
|
||||
for _, go_os := range supported_syslist {
|
||||
if provided_os == go_os {
|
||||
supported_os = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if supported_os != true {
|
||||
return fmt.Errorf("Invalid OS specified in only_on: '%s'\n"+
|
||||
"Supported OS names: %s", provided_os, strings.Join(supported_syslist, ", "))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if config.UseLinuxPathing {
|
||||
for index, script := range config.Scripts {
|
||||
scriptAbsPath, err := filepath.Abs(script)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
@ -27,6 +28,22 @@ type EnvVarsTemplate struct {
|
|||
}
|
||||
|
||||
func Run(ui packer.Ui, config *Config) (bool, error) {
|
||||
// Check if shell-local can even execute against this runtime OS
|
||||
if len(config.OnlyOn) > 0 {
|
||||
runCommand := false
|
||||
for _, os := range config.OnlyOn {
|
||||
if os == runtime.GOOS {
|
||||
runCommand = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !runCommand {
|
||||
ui.Say(fmt.Sprintf("Skipping shell-local due to runtime OS"))
|
||||
log.Printf("[INFO] (shell-local): skipping shell-local due to missing runtime OS")
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
scripts := make([]string, len(config.Scripts))
|
||||
if len(config.Scripts) > 0 {
|
||||
copy(scripts, config.Scripts)
|
||||
|
|
|
@ -91,6 +91,12 @@ 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.
|
||||
|
||||
- `only_on` (array of strings) - This is an array of
|
||||
[runtime operating systems](https://golang.org/doc/install/source#environment)
|
||||
where `shell-local` will execute. This allows you to execute `shell-local`
|
||||
*only* on specific operating systems. By default, shell-local will always run
|
||||
if `only_on` is not set."
|
||||
|
||||
- `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
|
||||
|
|
|
@ -108,6 +108,12 @@ 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.
|
||||
|
||||
- `only_on` (array of strings) - This is an array of
|
||||
[runtime operating systems](https://golang.org/doc/install/source#environment)
|
||||
where `shell-local` will execute. This allows you to execute `shell-local`
|
||||
*only* on specific operating systems. By default, shell-local will always run
|
||||
if `only_on` is not set."
|
||||
|
||||
- `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