forked from lmars/dokku-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack-notify
executable file
·60 lines (50 loc) · 1.01 KB
/
slack-notify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
main() {
local app="$1"
local hook="$(basename $0)"
slack_notify "${app}" "${hook}"
}
slack_notify() {
local app="$1"
local hook="$2"
local file="${DOKKU_ROOT}/${app}/SLACK_WEBHOOK"
if [[ ! -s "${file}" ]]; then
return 0
fi
local webhook="$(cat "${file}")"
local payload="$(slack_payload "${app}" "${hook}")"
dokku_log_info1 "Notifying Slack ..."
curl \
--request "POST" \
--silent \
--fail \
--show-error \
--location \
--output "/dev/null" \
--header "Content-Type: application/json" \
--data "${payload}" \
"${webhook}"
}
slack_payload() {
local app="$1"
local hook="$2"
local stage
case "${hook}" in
receive-app)
stage="Starting"
;;
post-deploy)
stage="Finished"
;;
esac
cat <<JSON
{
"username": "dokku-slack",
"icon_emoji": ":neckbeard:",
"text": "${stage} deploy of ${app}"
}
JSON
}
main $@