Showing with 73 additions and 4 deletions.
  1. +13 −0 CHANGELOG.md
  2. +17 −0 README.md
  3. +1 −0 manifests/params.pp
  4. +2 −0 manifests/webhook/config.pp
  5. +1 −1 metadata.json
  6. +6 −0 spec/classes/webhook/config_spec.rb
  7. +33 −3 templates/webhook.bin.erb
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not impact the functionality of the module.

## [v5.0.2](https://github.com/voxpupuli/puppet-r10k/tree/v5.0.2) (2017-04-06)
[Full Changelog](https://github.com/voxpupuli/puppet-r10k/compare/v5.0.1...v5.0.2)

**Closed issues:**

- Webhook not compatible with Puppet 4.10.0 [\#359](https://github.com/voxpupuli/puppet-r10k/issues/359)

**Merged pull requests:**

- Add check to fix the ruby path on puppet 4.10.0 [\#360](https://github.com/voxpupuli/puppet-r10k/pull/360) ([dhollinger](https://github.com/dhollinger))
- Webhook: ignore deploying some environments [\#355](https://github.com/voxpupuli/puppet-r10k/pull/355) ([nike38rus](https://github.com/nike38rus))

## [v5.0.1](https://github.com/voxpupuli/puppet-r10k/tree/v5.0.1) (2017-04-06)
[Full Changelog](https://github.com/voxpupuli/puppet-r10k/compare/v5.0.0...v5.0.1)

Expand All @@ -13,6 +25,7 @@ These should not impact the functionality of the module.

**Merged pull requests:**

- Release 5.0.1 [\#358](https://github.com/voxpupuli/puppet-r10k/pull/358) ([bastelfreak](https://github.com/bastelfreak))
- puppet-lint: fix arrow\_on\_right\_operand\_line [\#357](https://github.com/voxpupuli/puppet-r10k/pull/357) ([bastelfreak](https://github.com/bastelfreak))
- Create sanitize\_input helper method for strings sent to run\_command method. [\#356](https://github.com/voxpupuli/puppet-r10k/pull/356) ([xraystyle](https://github.com/xraystyle))
- Use styleguide compliant syntax for sshkey example. [\#353](https://github.com/voxpupuli/puppet-r10k/pull/353) ([kallies](https://github.com/kallies))
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,23 @@ class { '::r10k::webhook':
}
```

### Ignore deploying some environments

If you need to configure webhook to not trigger r10k when changes pushed in some branch or repository, you can list them in
`r10k::webhook::config::ignore_environments` parameter as array.
There is an ability to specify it as a regular expression by enclosing it in forward slashes.

Here is an example where the test branch in dev repository and all branches in all repositories that includes the word 'feature'
in names will be skipped:

```puppet
class { '::r10k::webhook::config':
. . .
prefix => ':repo',
ignore_environments => ['dev_test', '/.*feature.*/']
}
```

## Reference

####Class: `r10k`
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
$webhook_configfile_owner = 'root'
$webhook_configfile_group = $root_group
$webhook_configfile_mode = '0644'
$webhook_ignore_environments = []

# Service Settings for SystemD in EL7
if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '7' {
Expand Down
2 changes: 2 additions & 0 deletions manifests/webhook/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
$manage_symlink = false,
$configfile_symlink = '/etc/webhook.yaml',
$enable_mutex_lock = $r10k::params::webhook_enable_mutex_lock,
Array $ignore_environments = $r10k::params::webhook_ignore_environments,
) inherits r10k::params {

if $hash == 'UNSET' {
Expand Down Expand Up @@ -75,6 +76,7 @@
'slack_webhook' => $slack_webhook,
'slack_channel' => $slack_channel,
'slack_username' => $slack_username,
'ignore_environments' => $ignore_environments,
}
} else {
$webhook_hash = $hash
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Vox Pupuli",
"license": "Apache-2.0",
"name": "puppet-r10k",
"version": "5.0.1",
"version": "5.0.2",
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
Expand Down
6 changes: 6 additions & 0 deletions spec/classes/webhook/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
discovery_timeout: "10"
enable_mutex_lock: false
enable_ssl: true
ignore_environments: []
pass: "peadmin"
port: "8088"
prefix: false
Expand Down Expand Up @@ -85,6 +86,7 @@
discovery_timeout: "10"
enable_mutex_lock: false
enable_ssl: true
ignore_environments: []
pass: "peadmin"
port: "8088"
prefix: false
Expand Down Expand Up @@ -144,6 +146,7 @@
discovery_timeout: "10"
enable_mutex_lock: false
enable_ssl: true
ignore_environments: []
pass: "puppet"
port: "8088"
prefix: false
Expand Down Expand Up @@ -186,6 +189,7 @@
discovery_timeout: "10"
enable_mutex_lock: true
enable_ssl: true
ignore_environments: []
pass: "puppet"
port: "8088"
prefix: false
Expand Down Expand Up @@ -228,6 +232,7 @@
enable_mutex_lock: false
enable_ssl: true
github_secret: "secret"
ignore_environments: []
pass: "puppet"
port: "8088"
prefix: false
Expand Down Expand Up @@ -269,6 +274,7 @@
discovery_timeout: "10"
enable_mutex_lock: false
enable_ssl: true
ignore_environments: []
pass: "puppet"
port: "8088"
prefix: false
Expand Down
36 changes: 33 additions & 3 deletions templates/webhook.bin.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!<%= if @is_pe == true or @is_pe == 'true' then '/opt/puppet/bin' elsif @puppetversion >= '4.2.0' then '/opt/puppetlabs/puppet/bin' else '/usr/bin' end %>/ruby
<% if @is_pe == true or @is_pe == 'true' -%>
#!/opt/puppet/bin/ruby
<% elsif Puppet::Util::Package.versioncmp(Puppet.version, '4.2.0') >= 0 -%>
#!/opt/puppetlabs/puppet/bin/ruby
<% else -%>
#!/usr/bin/ruby
<% end -%>
# This mini-webserver is meant to be run as the peadmin user
# so that it can call mcollective from a puppetmaster
# Authors:
Expand Down Expand Up @@ -163,11 +169,17 @@ end
# The best we can do is just deploy all environments by passing nil to
# deploy() if we don't know the correct branch.
if prefix.nil? or prefix.empty? or branch.nil? or branch.empty?
deploy(normalize(branch))
env = normalize(branch)
else
deploy(normalize("#{prefix}_#{branch}"))
env = normalize("#{prefix}_#{branch}")
end

if ignore_env?(env)
$logger.info("Skipping deployment of environment #{env} according to ignore_environments configuration parameter")
return 200
else
deploy(env)
end
end

not_found do
Expand All @@ -176,6 +188,24 @@ end

helpers do

# Ignore environments that we don't care about e.g. feature or bugfix branches
def ignore_env?(env)
list = $config['ignore_environments']
return false if list.nil? or list.empty?

list.each do |l|
# Even unquoted array elements wrapped by slashes becomes strings after YAML parsing
# So we need to convert it into Regexp manually
if l =~ /^\/.+\/$/
return true if env =~ Regexp.new(l[1..-2])
else
return true if env == l
end
end

return false
end

# Check to see if this is an event we care about. Default to responding to all events
def ignore_event?
# Explicitly ignore GitHub ping events
Expand Down