Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

hooks: Add a common/ directory and factor out common Sentry code.

Alex Vandiver377f2d6d0302
diff --git a/puppet/zulip/files/hooks/common/sentry.sh b/puppet/zulip/files/hooks/common/sentry.sh
new file mode 100755
index 00000000000..7e0190a9f2e
--- /dev/null
+++ b/puppet/zulip/files/hooks/common/sentry.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+
+set -e
+set -u
+
+if ! grep -Eq 'SENTRY_DSN|SENTRY_FRONTEND_DSN' /etc/zulip/settings.py; then
+ echo "sentry: No DSN configured! Set SENTRY_DSN or SENTRY_FRONTEND_DSN in /etc/zulip/settings.py"
+ exit 0
+fi
+
+if ! SENTRY_AUTH_TOKEN=$(crudini --get /etc/zulip/zulip-secrets.conf secrets sentry_release_auth_token); then
+ echo "sentry: No release auth token set! Set sentry_release_auth_token in /etc/zulip/zulip-secrets.conf"
+ exit 0
+fi
+export SENTRY_AUTH_TOKEN
+
+# shellcheck disable=SC2034
+if ! sentry_org=$(crudini --get /etc/zulip/zulip.conf sentry organization); then
+ echo "sentry: No organization set! Set sentry.organization in /etc/zulip/zulip.conf"
+ exit 0
+fi
+
+sentry_project=$(crudini --get /etc/zulip/zulip.conf sentry project)
+sentry_frontend_project=$(crudini --get /etc/zulip/zulip.conf sentry frontend_project)
+if [ -z "$sentry_project" ] && [ -z "$sentry_frontend_project" ]; then
+ echo "sentry: No project set! Set sentry.project and/or sentry.frontend_project in /etc/zulip/zulip.conf"
+ exit 0
+fi
+
+if [ -n "$sentry_project" ] && ! grep -q 'SENTRY_DSN' /etc/zulip/settings.py; then
+ echo "sentry: sentry.project is set but SENTRY_DSN is not set in /etc/zulip/settings.py"
+ exit 0
+fi
+if [ -n "$sentry_frontend_project" ] && ! grep -q 'SENTRY_FRONTEND_DSN' /etc/zulip/settings.py; then
+ echo "sentry: sentry.frontend_project is set but SENTRY_FRONTEND_DSN is not set in /etc/zulip/settings.py"
+ exit 0
+fi
+
+if ! which sentry-cli >/dev/null; then
+ echo "sentry: No sentry-cli installed!"
+ exit 0
+fi
+
+# shellcheck disable=SC2034
+sentry_release="zulip-server@$ZULIP_NEW_VERSION"
diff --git a/puppet/zulip/files/hooks/post-deploy.d/sentry.hook b/puppet/zulip/files/hooks/post-deploy.d/sentry.hook
index c57e1eb8b08..78997486535 100755
--- a/puppet/zulip/files/hooks/post-deploy.d/sentry.hook
+++ b/puppet/zulip/files/hooks/post-deploy.d/sentry.hook
@@ -3,40 +3,7 @@
set -e
set -u
-if ! grep -q 'SENTRY_DSN' /etc/zulip/settings.py; then
- echo "sentry: No DSN configured! Set SENTRY_DSN in /etc/zulip/settings.py"
- exit 0
-fi
-
-if ! SENTRY_AUTH_TOKEN=$(crudini --get /etc/zulip/zulip-secrets.conf secrets sentry_release_auth_token); then
- echo "sentry: No release auth token set! Set sentry_release_auth_token in /etc/zulip/zulip-secrets.conf"
- exit 0
-fi
-export SENTRY_AUTH_TOKEN
-
-if ! sentry_org=$(crudini --get /etc/zulip/zulip.conf sentry organization); then
- echo "sentry: No organization set! Set sentry.organization in /etc/zulip/zulip.conf"
- exit 0
-fi
-
-sentry_project=$(crudini --get /etc/zulip/zulip.conf sentry project)
-sentry_frontend_project=$(crudini --get /etc/zulip/zulip.conf sentry frontend_project)
-if [ -z "$sentry_project" ] && [ -z "$sentry_frontend_project" ]; then
- echo "sentry: No project set! Set sentry.project and/or sentry.frontend_project in /etc/zulip/zulip.conf"
- exit 0
-fi
-
-if ! which sentry-cli >/dev/null; then
- echo "sentry: No sentry-cli installed!"
- exit 0
-fi
-
-if ! [ -f ./sentry-release ]; then
- echo "sentry: No Sentry sentry-release file found!"
- exit 0
-fi
-
-sentry_release=$(cat ./sentry-release)
+source "$(dirname "$0")/../common/sentry.sh"
deploy_environment=$(crudini --get /etc/zulip/zulip.conf machine deploy_type || echo "development")
diff --git a/puppet/zulip/files/hooks/pre-deploy.d/sentry.hook b/puppet/zulip/files/hooks/pre-deploy.d/sentry.hook
index e23fd66a97f..6fc2b64ef0e 100755
--- a/puppet/zulip/files/hooks/pre-deploy.d/sentry.hook
+++ b/puppet/zulip/files/hooks/pre-deploy.d/sentry.hook
@@ -3,44 +3,8 @@
set -e
set -u
-if ! grep -Eq 'SENTRY_DSN|SENTRY_FRONTEND_DSN' /etc/zulip/settings.py; then
- echo "sentry: No DSN configured! Set SENTRY_DSN or SENTRY_FRONTEND_DSN in /etc/zulip/settings.py"
- exit 0
-fi
-
-if ! SENTRY_AUTH_TOKEN=$(crudini --get /etc/zulip/zulip-secrets.conf secrets sentry_release_auth_token); then
- echo "sentry: No release auth token set! Set sentry_release_auth_token in /etc/zulip/zulip-secrets.conf"
- exit 0
-fi
-export SENTRY_AUTH_TOKEN
-
-if ! sentry_org=$(crudini --get /etc/zulip/zulip.conf sentry organization); then
- echo "sentry: No organization set! Set sentry.organization in /etc/zulip/zulip.conf"
- exit 0
-fi
-
-sentry_project=$(crudini --get /etc/zulip/zulip.conf sentry project)
-sentry_frontend_project=$(crudini --get /etc/zulip/zulip.conf sentry frontend_project)
-if [ -z "$sentry_project" ] && [ -z "$sentry_frontend_project" ]; then
- echo "sentry: No project set! Set sentry.project and/or sentry.frontend_project in /etc/zulip/zulip.conf"
- exit 0
-fi
-
-if [ -n "$sentry_project" ] && ! grep -q 'SENTRY_DSN' /etc/zulip/settings.py; then
- echo "sentry: sentry.project is set but SENTRY_DSN is not set in /etc/zulip/settings.py"
- exit 0
-fi
-if [ -n "$sentry_frontend_project" ] && ! grep -q 'SENTRY_FRONTEND_DSN' /etc/zulip/settings.py; then
- echo "sentry: sentry.frontend_project is set but SENTRY_FRONTEND_DSN is not set in /etc/zulip/settings.py"
- exit 0
-fi
-
-if ! which sentry-cli >/dev/null; then
- echo "sentry: No sentry-cli installed!"
- exit 0
-fi
+source "$(dirname "$0")/../common/sentry.sh"
-sentry_release="zulip-server@$ZULIP_NEW_VERSION"
echo "$sentry_release" >./sentry-release
echo "sentry: Creating release $sentry_release"
diff --git a/puppet/zulip/manifests/hooks/base.pp b/puppet/zulip/manifests/hooks/base.pp
index 99adf87ef87..7d0178cf258 100644
--- a/puppet/zulip/manifests/hooks/base.pp
+++ b/puppet/zulip/manifests/hooks/base.pp
@@ -3,6 +3,7 @@
class zulip::hooks::base {
file { [
'/etc/zulip/hooks',
+ '/etc/zulip/hooks/common',
'/etc/zulip/hooks/pre-deploy.d',
'/etc/zulip/hooks/post-deploy.d',
]:
diff --git a/puppet/zulip/manifests/hooks/sentry.pp b/puppet/zulip/manifests/hooks/sentry.pp
index eafd132c965..759f136b88a 100644
--- a/puppet/zulip/manifests/hooks/sentry.pp
+++ b/puppet/zulip/manifests/hooks/sentry.pp
@@ -20,5 +20,9 @@ class zulip::hooks::sentry {
target => $bin,
}
- zulip::hooks::file { ['pre-deploy.d/sentry.hook', 'post-deploy.d/sentry.hook']: }
+ zulip::hooks::file { [
+ 'common/sentry.sh',
+ 'pre-deploy.d/sentry.hook',
+ 'post-deploy.d/sentry.hook',
+ ]: }
}