Skip to content

Commit ccb5cff

Browse files
committed
notifier: Implement upgrade logic for notifier service
* If $update is enabled for git-clone, then add an exec resource that checks the working copy, and if HEAD is not $branch tag, then: - fetch origin - checkout tag (forced) - clean working copy, which deletes stale node_modules (and also config.json) * The node_modules is updated given the 'creates' should evaluate to false. Add notify to ensure service restart. * The config.json file resource already ensures its own re-creation and notification, hopefully Puppet merges the notifications, but probably fine either way? Revert the hiera change from notifier v4 back to v3 (was pushed to staging only, and didn't do anything), so that I check first test that this change doesn't cause any churn on repeat runs by itself, and then test that the upgrade works.
1 parent 943b746 commit ccb5cff

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

hieradata/common.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ profile::base::groups:
553553
gitpuppet:
554554
gid: 600
555555

556-
profile::notifier::version: v4.0.0
556+
profile::notifier::version: v3.0.0
557557

558558
# https://github.com/wp-cli/wp-cli/releases
559559
profile::wordpress::base::wordpress_cli_version: "2.8.1"

modules/git/manifests/clone.pp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# @summary clones a git repository
22
# @param $path the filesystem path
33
# @param $remote the remote url
4-
# @param $branch the branch to clone
4+
# @param $branch the branch or tag to checkout
55
# @param $owner file owner
66
# @param $group file group
77
# @param $shared true if the group should have write access
88
# @param $ensure present or absent
9+
# @param $update Enable this to update an existing clone after $branch points to
10+
# a different tag than before. Only supports tags. This will *delete* any ignored
11+
# or untracked files (such as previously provisioned configuration or node_modules).
12+
# To update after branch pushes, use `notifier` instead.
913
define git::clone (
1014
Stdlib::Unixpath $path,
1115
String $remote,
@@ -14,6 +18,7 @@
1418
String $group,
1519
Boolean $shared = false,
1620
Jqlib::Ensure $ensure = present,
21+
Boolean $update = false,
1722
) {
1823
if $ensure == 'present' {
1924
if $shared {
@@ -41,6 +46,21 @@
4146
group => $group,
4247
umask => $umask,
4348
}
49+
50+
if $update {
51+
exec { "git_checkout_${title}":
52+
cwd => $path,
53+
unless => "test \"$(git describe --exact-match --tags) = \"${branch}\"",
54+
# This will delete
55+
command => "/usr/bin/git fetch --tags --prune --prune-tags \"${remote}\" && /usr/bin/git checkout --force --quiet \"${branch}\" && /usr/bin/git clean -dfx",
56+
logoutput => true,
57+
provider => 'shell',
58+
user => $owner,
59+
group => $group,
60+
umask => $umask,
61+
}
62+
}
63+
4464
} elsif $ensure == 'absent' {
4565
file { $path:
4666
ensure => absent,

modules/notifier/manifests/init.pp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# @summary configures node-notifier to receive github webhooks
22
# @param $webhook_secret github webhook secret
3-
# @param $version git version to clone. note that the module doesn't
4-
# currently auto update after changing this.
3+
# @param $version git tag to clone
54
class notifier (
65
String[1] $webhook_secret,
76
String[1] $version,
@@ -26,6 +25,9 @@
2625
owner => 'notifier',
2726
group => 'notifier',
2827
branch => $version,
28+
# After updates, git::clone will delete old node_modules, allowing
29+
# the next exec to install the new version, and then restart the service.
30+
update => true,
2931
require => Systemd::Tmpfile['notifier'],
3032
}
3133

@@ -38,6 +40,7 @@
3840
Git::Clone['notifier'],
3941
Systemd::Tmpfile['notifier'],
4042
],
43+
notify => Service['notifier'],
4144
}
4245

4346
$config = {

0 commit comments

Comments
 (0)