Skip to content

Commit b75dd3c

Browse files
committed
Initial code.
1 parent cecc63b commit b75dd3c

File tree

6 files changed

+182
-0
lines changed

6 files changed

+182
-0
lines changed

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 ribot
4+
Copyright (c) 2017 Jannis Leidel
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Dokku Sentry Webhook
2+
3+
Dokku Sentry Webhook is a plugin for [Dokku](https://github.com/dokku/dokku) that notifies
4+
[Sentry](https://sentry.io/) of deployments.
5+
6+
## Installation
7+
8+
```sh
9+
# dokku 0.3.26
10+
$ git clone https://github.com/jezdez/dokku-sentry-webhook /var/lib/dokku/plugins/sentry-webhook
11+
12+
# dokku 0.4+
13+
$ dokku plugin:install https://github.com/jezdez/dokku-sentry-webhook.git
14+
```
15+
16+
## Commands
17+
18+
```sh
19+
$ dokku help
20+
sentry:set <app> <webhook_url> Set Sentry WebHook URL
21+
sentry:clear <app> Clears Sentry WebHook URL
22+
sentry:get <app> Display Sentry WebHook URL
23+
```
24+
25+
The webhook URL can be found under the "Release Tracking" settings section of
26+
individual Sentry projects. There is a "Webhook" box with a long URL
27+
in the format `https://<sentry-host>/api/hooks/release/builtin/<n>/<long-hash>/`.
28+
29+
## License
30+
31+
The MIT License (MIT)
32+
33+
Copyright (c) 2015 ribot (dokku-slack)
34+
Copyright (c) 2017 Jannis Leidel (dokku-sentry-webhook)
35+
36+
Permission is hereby granted, free of charge, to any person obtaining a copy
37+
of this software and associated documentation files (the "Software"), to deal
38+
in the Software without restriction, including without limitation the rights
39+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40+
copies of the Software, and to permit persons to whom the Software is
41+
furnished to do so, subject to the following conditions:
42+
43+
The above copyright notice and this permission notice shall be included in
44+
all copies or substantial portions of the Software.
45+
46+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52+
SOFTWARE.

commands

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
3+
4+
PLUGIN_BASE_PATH="$PLUGIN_PATH"
5+
if [[ -n $DOKKU_API_VERSION ]]; then
6+
PLUGIN_BASE_PATH="$PLUGIN_ENABLED_PATH"
7+
fi
8+
source "$PLUGIN_BASE_PATH/common/functions"
9+
10+
is_webhook() {
11+
echo "$1" | grep -E '^http[s]?://'
12+
}
13+
14+
get_sentry_root() {
15+
if [[ -z $(is_webhook "$1") ]]; then
16+
verify_app_name "$1"
17+
APP="$1"
18+
echo "$DOKKU_ROOT/$APP"
19+
else
20+
echo "$DOKKU_ROOT"
21+
fi
22+
}
23+
24+
get_webhook() {
25+
if [[ -n $1 && -n $2 ]]; then
26+
echo "$2"
27+
else
28+
echo "$1"
29+
fi
30+
}
31+
32+
case "$1" in
33+
sentry:set)
34+
SENTRY_ROOT=$(get_sentry_root "$2")
35+
WEBHOOK=$(get_webhook "$2" "$3")
36+
[[ -z $WEBHOOK ]] && echo "Please specify at least a webhook URL" && exit 1
37+
[[ -z $(is_webhook "$WEBHOOK") ]] && echo "Webhook has to be an URL" && exit 1
38+
echo "$WEBHOOK" > "$SENTRY_ROOT/SENTRY_URL"
39+
;;
40+
41+
sentry:clear)
42+
SENTRY_ROOT=$(get_sentry_root "$2")
43+
rm "$SENTRY_ROOT/SENTRY_URL"
44+
;;
45+
46+
sentry:get)
47+
SENTRY_ROOT=$(get_sentry_root "$2")
48+
cat "$SENTRY_ROOT/SENTRY_URL"
49+
;;
50+
51+
help)
52+
HELP=$(cat<<EOF
53+
sentry:set [app] <webhook_url>, Set Sentry WebHook URL
54+
sentry:clear [app], Clears Sentry WebHook URL
55+
sentry:get [app], Display Sentry WebHook URL
56+
EOF
57+
)
58+
if [[ -n $DOKKU_API_VERSION ]]; then
59+
echo "$HELP"
60+
else
61+
cat && echo "$HELP"
62+
fi
63+
;;
64+
65+
*)
66+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
67+
;;
68+
esac

plugin.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[plugin]
2+
description = "Sentry notifier on deploy"
3+
version = "0.1.0"
4+
[plugin.config]

post-deploy

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
3+
source "$PLUGIN_AVAILABLE_PATH/config/functions"
4+
5+
main() {
6+
declare APP="$1"
7+
8+
if [[ -f "$DOKKU_ROOT/$APP/SENTRY_URL" || -f "$DOKKU_ROOT/SENTRY_URL" ]]; then
9+
echo "-----> Notifying Sentry..."
10+
URL=$(dokku url $APP)
11+
HOOK_VERSION=$(config_get "$APP" SENTRY_WEBHOOK_VERSION || true)
12+
SENTRY_URL=$(cat "$DOKKU_ROOT/$APP/SENTRY_URL" 2> /dev/null || cat "$DOKKU_ROOT/SENTRY_URL" 2> /dev/null)
13+
SENTRY_JSON="{ \
14+
\"url\": \"$URL\", \
15+
\"version\": \"$HOOK_VERSION\" \
16+
}"
17+
SENTRY_RESULT=$(curl -X POST -H "Content-Type: application/json" -d "$SENTRY_JSON" "${SENTRY_URL}")
18+
echo " ${SENTRY_RESULT}"
19+
fi
20+
}
21+
22+
main "$@"

receive-app

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
3+
source "$PLUGIN_AVAILABLE_PATH/config/functions"
4+
5+
main() {
6+
declare APP="$1" REV="$2"
7+
8+
# Don't write the revision if there is no git repository or we have no incoming REV.
9+
if [[ -d "$DOKKU_ROOT/$APP/refs" ]] && [[ -n "$REV" ]]; then
10+
config_set --no-restart "$APP" SENTRY_WEBHOOK_VERSION="$REV"
11+
fi
12+
}
13+
14+
main "$@"

0 commit comments

Comments
 (0)