Skip to content

Commit

Permalink
Merge branch 'master' into chatops_teams
Browse files Browse the repository at this point in the history
  • Loading branch information
dhollinger authored May 8, 2024
2 parents 319df08 + 661e497 commit f592620
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions api/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 10 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 14 additions & 0 deletions lib/helpers/r10k-command.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f592620

Please sign in to comment.