diff --git a/README.md b/README.md index 977d02c..6606c37 100644 --- a/README.md +++ b/README.md @@ -230,12 +230,24 @@ Type: bool Description: Deploy modules in environments. Default: `true` +### `use_legacy_puppetfile_flag` + +Type: bool +Description: Use the legacy `--puppetfile` flag instead of `--modules`. This should only be used when your version of r10k doesn't support the newer flag. +Default: `false` + ### `generate_types` Type: bool Description: Run `puppet generate types` after updating an environment Default: `true` +### `command_path` + +Type: `string` +Description: Allow overriding the default path to r10k. +Default: `/opt/puppetlabs/puppetserver/bin/r10k` + ## Usage Webhook API provides following paths diff --git a/api/environment.go b/api/environment.go index 2ccddb5..2b1ba21 100644 --- a/api/environment.go +++ b/api/environment.go @@ -24,7 +24,7 @@ func (e EnvironmentController) DeployEnvironment(c *gin.Context) { var branch string // Set the base r10k command into a slice of strings - cmd := []string{"r10k", "deploy", "environment"} + cmd := []string{h.GetR10kCommand(), "deploy", "environment"} // Get the configuration conf := config.GetConfig() @@ -63,7 +63,11 @@ func (e EnvironmentController) DeployEnvironment(c *gin.Context) { cmd = append(cmd, "--generate-types") } if conf.R10k.DeployModules { - cmd = append(cmd, "--modules") + if conf.R10k.UseLegacyPuppetfileFlag { + cmd = append(cmd, "--puppetfile") + } else { + cmd = append(cmd, "--modules") + } } // Pass the command to the execute function and act on the result and any error diff --git a/api/module.go b/api/module.go index 2537f98..6f16e94 100644 --- a/api/module.go +++ b/api/module.go @@ -24,7 +24,7 @@ func (m ModuleController) DeployModule(c *gin.Context) { var h helpers.Helper // Set the base r10k command into a string slice - cmd := []string{"r10k", "deploy", "module"} + cmd := []string{h.GetR10kCommand(), "deploy", "module"} // Get the configuration conf := config.GetConfig() diff --git a/config/config.go b/config/config.go index 1e1adee..640575e 100644 --- a/config/config.go +++ b/config/config.go @@ -35,14 +35,15 @@ type Config struct { ServerUri string `mapstructure:"server_uri"` } `mapstructure:"chatops"` R10k struct { - CommandPath string `mapstructure:"command_path"` - ConfigPath string `mapstructure:"config_path"` - DefaultBranch string `mapstructure:"default_branch"` - Prefix string `mapstructure:"prefix"` - AllowUppercase bool `mapstructure:"allow_uppercase"` - Verbose bool `mapstructure:"verbose"` - DeployModules bool `mapstructure:"deploy_modules"` - GenerateTypes bool `mapstructure:"generate_types"` + CommandPath string `mapstructure:"command_path"` + ConfigPath string `mapstructure:"config_path"` + DefaultBranch string `mapstructure:"default_branch"` + Prefix string `mapstructure:"prefix"` + AllowUppercase bool `mapstructure:"allow_uppercase"` + Verbose bool `mapstructure:"verbose"` + DeployModules bool `mapstructure:"deploy_modules"` + UseLegacyPuppetfileFlag bool `mapstructure:"use_legacy_puppetfile_flag"` + GenerateTypes bool `mapstructure:"generate_types"` } `mapstructure:"r10k"` } @@ -88,6 +89,7 @@ func setDefaults(v *viper.Viper) *viper.Viper { v.SetDefault("r10k.verbose", true) v.SetDefault("r10k.deploy_modules", true) v.SetDefault("r10k.generate_types", true) + v.SetDefault("r10k.use_legacy_puppetfile_flag", false) return v } diff --git a/go.mod b/go.mod index e2caec4..50734a2 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 - github.com/xanzy/go-gitlab v0.103.0 + github.com/xanzy/go-gitlab v0.104.0 gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index 3c49f32..29b1b6b 100644 --- a/go.sum +++ b/go.sum @@ -149,8 +149,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/xanzy/go-gitlab v0.103.0 h1:J9pTQoq0GsEFqzd6srCM1QfdfKAxSNz6mT6ntrpNF2w= -github.com/xanzy/go-gitlab v0.103.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI= +github.com/xanzy/go-gitlab v0.104.0 h1:YDuuaTrNdHMuBW+FagO/W4dHvAQOqpCf2pMB45ATbog= +github.com/xanzy/go-gitlab v0.104.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= diff --git a/lib/helpers/r10k-command.go b/lib/helpers/r10k-command.go new file mode 100644 index 0000000..5a62943 --- /dev/null +++ b/lib/helpers/r10k-command.go @@ -0,0 +1,14 @@ +package helpers + +import "github.com/voxpupuli/webhook-go/config" + +const Command = "r10k" + +func (h *Helper) GetR10kCommand() string { + conf := config.GetConfig().R10k + commandPath := conf.CommandPath + if commandPath == "" { + return Command + } + return commandPath +}