Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
kandra: Add a hook to notify of local schema drift from merge-base.
Alex Vandiverce34ebdfedb0
diff --git a/puppet/kandra/files/hooks/post-deploy.d/zulip_notify_schema_diff.hook b/puppet/kandra/files/hooks/post-deploy.d/zulip_notify_schema_diff.hooknew file mode 100644index 00000000000..44e97d038ef--- /dev/null+++ b/puppet/kandra/files/hooks/post-deploy.d/zulip_notify_schema_diff.hook@@ -0,0 +1,27 @@+#!/usr/bin/env bash++set -e+set -u++source "$(dirname "$0")/../common/zulip_notify.sh"++if ! ref=$(crudini --get /etc/zulip/zulip.conf push_git_ref ref); then+ exit 0+fi++diffstat=$(git diff --stat "$ZULIP_NEW_MERGE_BASE_COMMIT" ./*/migrations/)++if [ -z "$diffstat" ]; then+ exit 0+fi++echo "zulip_notify_schema_diff: Found schema differences from merge-base!"++zulip_send "${deploy_environment} deploy on $(hostname) found differences in schema from merge-base:++\`\`\`+${diffstat}+\`\`\`++Please manually adjust the \`${ref}\` ref.+"diff --git a/puppet/kandra/manifests/hooks/file.pp b/puppet/kandra/manifests/hooks/file.ppnew file mode 100644index 00000000000..a01a2db526b--- /dev/null+++ b/puppet/kandra/manifests/hooks/file.pp@@ -0,0 +1,14 @@+# @summary Install a static hook file+#+define kandra::hooks::file() {+ include zulip::hooks::base++ file { "/etc/zulip/hooks/${title}":+ ensure => file,+ mode => '0755',+ owner => 'zulip',+ group => 'zulip',+ source => "puppet:///modules/kandra/hooks/${title}",+ tag => ['hooks'],+ }+}diff --git a/puppet/kandra/manifests/hooks/zulip_notify_schema_diff.pp b/puppet/kandra/manifests/hooks/zulip_notify_schema_diff.ppnew file mode 100644index 00000000000..d44639bef13--- /dev/null+++ b/puppet/kandra/manifests/hooks/zulip_notify_schema_diff.pp@@ -0,0 +1,8 @@+# @summary Install hook that checks for schema drift from published ref+#+class kandra::hooks::zulip_notify_schema_diff {+ include zulip::hooks::base+ include zulip::hooks::zulip_common++ kandra::hooks::file { 'post-deploy.d/zulip_notify_schema_diff.hook': }+}diff --git a/puppet/kandra/manifests/prod_app_frontend_once.pp b/puppet/kandra/manifests/prod_app_frontend_once.ppindex 974dab6504e..8295e347970 100644--- a/puppet/kandra/manifests/prod_app_frontend_once.pp+++ b/puppet/kandra/manifests/prod_app_frontend_once.pp@@ -2,6 +2,7 @@ class kandra::prod_app_frontend_once {include zulip::app_frontend_onceinclude zulip::hooks::push_git_refinclude zulip::hooks::zulip_notify+ include kandra::hooks::zulip_notify_schema_diffzulip::cron { 'update-first-visible-message-id':hour => '7',diff --git a/puppet/zulip/files/hooks/common/zulip_notify.sh b/puppet/zulip/files/hooks/common/zulip_notify.shindex 1ec78b99535..153d1838975 100644--- a/puppet/zulip/files/hooks/common/zulip_notify.sh+++ b/puppet/zulip/files/hooks/common/zulip_notify.sh@@ -26,10 +26,9 @@ fifrom=${ZULIP_OLD_MERGE_BASE_COMMIT:-$ZULIP_OLD_VERSION}to=${ZULIP_NEW_MERGE_BASE_COMMIT:-$ZULIP_NEW_VERSION}deploy_environment=$(crudini --get /etc/zulip/zulip.conf machine deploy_type || echo "development")+# shellcheck disable=SC2034commit_count=$(git rev-list "${from}..${to}" | wc -l)-echo "zulip_notify: Sending notify of $from .. $to ($commit_count commits) for $deploy_environment to $zulip_notify_server"-zulip_send() {./zulip-py3-venv/bin/zulip-send \--site "$zulip_notify_server" \diff --git a/puppet/zulip/files/hooks/post-deploy.d/zulip_notify.hook b/puppet/zulip/files/hooks/post-deploy.d/zulip_notify.hookindex 9e1977451fd..039cb639511 100644--- a/puppet/zulip/files/hooks/post-deploy.d/zulip_notify.hook+++ b/puppet/zulip/files/hooks/post-deploy.d/zulip_notify.hook@@ -5,4 +5,6 @@ set -usource "$(dirname "$0")/../common/zulip_notify.sh"+echo "zulip_notify: Sending notify of $from .. $to ($commit_count commits) for $deploy_environment to $zulip_notify_server"+zulip_send "Finished ${deploy_environment} deploy of [${commit_count} new commits](https://github.com/zulip/zulip/compare/${from}...${to}) on $(hostname)"diff --git a/puppet/zulip/files/hooks/pre-deploy.d/zulip_notify.hook b/puppet/zulip/files/hooks/pre-deploy.d/zulip_notify.hookindex c5f24829d60..44320e0eb10 100644--- a/puppet/zulip/files/hooks/pre-deploy.d/zulip_notify.hook+++ b/puppet/zulip/files/hooks/pre-deploy.d/zulip_notify.hook@@ -5,4 +5,6 @@ set -usource "$(dirname "$0")/../common/zulip_notify.sh"+echo "zulip_notify: Sending notify of $from .. $to ($commit_count commits) for $deploy_environment to $zulip_notify_server"+zulip_send "Starting ${deploy_environment} deploy of [${commit_count} new commits](https://github.com/zulip/zulip/compare/${from}...${to}) on $(hostname)"diff --git a/puppet/zulip/manifests/hooks/zulip_common.pp b/puppet/zulip/manifests/hooks/zulip_common.ppnew file mode 100644index 00000000000..19f8bdb1fe7--- /dev/null+++ b/puppet/zulip/manifests/hooks/zulip_common.pp@@ -0,0 +1,7 @@+# @summary zulip_notify common file+#+class zulip::hooks::zulip_common {+ include zulip::hooks::base++ zulip::hooks::file { 'common/zulip_notify.sh': }+}diff --git a/puppet/zulip/manifests/hooks/zulip_notify.pp b/puppet/zulip/manifests/hooks/zulip_notify.ppindex 79c484e3f57..a9d1188cce0 100644--- a/puppet/zulip/manifests/hooks/zulip_notify.pp+++ b/puppet/zulip/manifests/hooks/zulip_notify.pp@@ -2,9 +2,9 @@#class zulip::hooks::zulip_notify {include zulip::hooks::base+ include zulip::hooks::zulip_commonzulip::hooks::file { [- 'common/zulip_notify.sh','pre-deploy.d/zulip_notify.hook','post-deploy.d/zulip_notify.hook',]: }