-
Notifications
You must be signed in to change notification settings - Fork 4
/
appsignal_deploy.sh
executable file
·111 lines (94 loc) · 2.85 KB
/
appsignal_deploy.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
version="1.2"
function usage {
echo "AWS Elastic Beanstalk Deployment Notifications for AppSignal (v${version})"
echo
echo "Usage: appsignal_deploy.sh -a <APP NAME> -k <API KEY> [options]"
echo
echo "Options:"
echo
echo " -a The name your the application in Elastic Beanstalk."
echo " -d The name of the deployer (default: AWS Elastic Beanstalk)."
echo " -e Error if the HTTP request fails. Note that this will abort the deployment."
echo " -h Displays this help message."
echo " -k Your AppSignal push API key."
echo " -q Quiet mode."
echo " -v Display version information."
echo
}
function info {
echo "[INFO] ${@}"
}
function warn {
echo "[WARN] ${@}"
}
function error {
echo "[ERROR] ${@}" >&2
exit 1
}
api_key=""
app_name=""
app_version=""
environment=$RACK_ENV
deployer=""
verbose=1
error_on_fail=0
if [[ ${#} == 0 ]]; then
usage
exit 1
fi
while getopts "a:d:ehk:qv" option; do
case "${option}" in
a) app_name="${OPTARG}";;
d) deployer="${OPTARG}";;
e) error_on_fail=1;;
h) usage; exit;;
k) api_key="${OPTARG}";;
q) verbose=0;;
v) echo "Version ${version}"; exit;;
*) echo; usage; exit 1;;
esac
done
if [[ -z "${app_name}" ]]; then
error "The application name must be provided"
fi
if [[ -z "${api_key}" ]]; then
error "The API key must be provided"
fi
if [[ -z "${deployer}" ]]; then
deployer="AWS Elastic Beanstalk"
fi
if [[ -f REVISION ]]; then
app_version=$(cat REVISION)
else
EB_CONFIG_SOURCE_BUNDLE=$(/opt/elasticbeanstalk/bin/get-config container -k source_bundle)
app_version=$(unzip -z "${EB_CONFIG_SOURCE_BUNDLE}" | tail -n1)
if [[ -z "${app_version}" ]]; then
app_version="unknown"
error "Unable to extract application version from source REVISION file, or load version information from within the container"
fi
fi
if [[ -z "${environment}" ]]; then
environment="development"
fi
if [[ ${verbose} == 1 ]]; then
info "Application name: ${app_name}"
info "Application version: ${app_version}"
info "Application environment: ${environment}"
info "Sending deployment notification..."
fi
http_response=$(curl -X POST -d "{\"revision\":\"${app_version}\",\"repository\":\"master\",\"user\":\"${deployer}\"}" "https://push.appsignal.com/1/markers?api_key=${api_key}&name=${app_name}&environment=${environment}" -o /dev/null)
http_status=$(echo "${http_response}" | head -n 1)
echo "${http_status}" | grep -q "201"
if [[ ${?} == 0 ]]; then
if [[ ${verbose} == 1 ]]; then
info "Deployment notification successfully sent (${app_name} v${app_version})"
fi
else
msg="Failed to send deployment notification: ${http_status}"
if [[ ${error_on_fail} == 1 ]]; then
error "${msg}"
else
warn "${msg}"
fi
fi