-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
blackfire
executable file
·140 lines (114 loc) · 5.19 KB
/
blackfire
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
# Build Path: /app/.heroku/php
OUT_PREFIX=$1
# fail hard
set -o pipefail
# fail harder
set -eu
source $(dirname $BASH_SOURCE)/../../_util/include/manifest.sh
ZEND_MODULE_API_VERSION=$(basename $(dirname $0))
ZEND_MODULE_API_VERSION=${ZEND_MODULE_API_VERSION#no-debug-non-zts-}
case ${ZEND_MODULE_API_VERSION} in
20121212)
series=5.5
;;
20131226)
series=5.6
;;
20151012)
series=7.0
;;
20160303)
series=7.1
;;
20170718)
series=7.2
;;
20180731)
series=7.3
;;
20190902)
series=7.4
;;
*)
echo "Unsupported PHP/Zend Module API version: ${ZEND_MODULE_API_VERSION}"
exit 1
;;
esac
ext_dir=${OUT_PREFIX}/lib/php/extensions/no-debug-non-zts-${ZEND_MODULE_API_VERSION}
bin_dir=${OUT_PREFIX}/bin
dep_formula=${0#$WORKSPACE_DIR/}
dep_name=$(basename $BASH_SOURCE)
if [[ "$dep_formula" != "$dep_name" ]]; then
probe_version=${dep_formula##*"/${dep_name}-"}
echo "Using explicit version ${probe_version}"
else
probe_version=`curl -I -A "Heroku" -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/${series/\./} | grep 'X-Blackfire-Release-Version: ' | sed "s%X-Blackfire-Release-Version: %%" | sed s%.$%%`
cat <<-EOF
!!! WARNING !!!
You're building the generic version of this extension.
API returned version ${probe_version}; it will be built in five seconds.
If you used --overwrite (and no deploy.sh --publish), then this will replace
the existing version of the package under a wrong version number IMMEDIATELY,
even without re-generating the repository, since the archive name is identical:
the repo and new manifest both point to ${dep_name}.tar.gz, but the new manifest
information will not be exposed in the repo until you run mkrepo.sh.
EOF
sleep 5
fi
dep_version=${probe_version}
dep_package=ext-${dep_name}-${dep_version}
if [[ "$dep_formula" != "$dep_name" ]]; then
dep_manifest=${dep_package}_php-$series.composer.json
else
dep_manifest=ext-${dep_name}_php-$series.composer.json
fi
echo "-----> Packaging ${dep_package}..."
curl -L -o probe.tar.gz "https://packages.blackfire.io/binaries/blackfire-php/${probe_version}/blackfire-php-linux_amd64-php-${series/\./}.tar.gz"
mkdir -p ${ext_dir}
tar -zxf probe.tar.gz
cp blackfire-${ZEND_MODULE_API_VERSION}.so ${ext_dir}/blackfire.so
rm probe.tar.gz blackfire-${ZEND_MODULE_API_VERSION}.so blackfire-${ZEND_MODULE_API_VERSION}.sha
agent_version=`curl -A "Heroku" -o agent.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/agent/linux/amd64 | grep 'X-Blackfire-Release-Version: ' | sed "s%X-Blackfire-Release-Version: %%" | sed s%.$%%`
echo "-----> Packaging bin/blackfire-agent ${agent_version}..."
mkdir -p ${OUT_PREFIX}/var/blackfire/run
mkdir -p ${OUT_PREFIX}/etc/blackfire
echo -e "[blackfire]\nserver-id=f1abf3a8-3f85-4743-99b2-97f066c099b9\nserver-token=5ecbc6486e9db6b780a0c0a9ef1e244709e632996fe9105cb9075ab2826944d5" > ${OUT_PREFIX}/etc/blackfire/agent.ini
mkdir -p ${bin_dir}
tar -zxf agent.tar.gz
chmod +x agent
cp agent ${bin_dir}/blackfire-agent
rm agent.tar.gz agent agent.sha1
echo "-----> Packaging bin/blackfire ${agent_version}..."
curl https://packages.blackfire.io/binaries/blackfire-agent/${agent_version}/blackfire-cli-linux_amd64 > ${bin_dir}/blackfire
chmod +x ${bin_dir}/blackfire
find ${OUT_PREFIX} -type f \( -executable -o -name '*.a' \) -exec sh -c "file -i '{}' | grep -Eq 'application/x-(archive|executable|sharedlib); charset=binary'" \; -print | xargs strip --strip-unneeded
# gets sourced on dyno boot
cat > ${OUT_PREFIX}/bin/profile.blackfire.sh <<'EOF'
export BLACKFIRE_LOG_LEVEL=${BLACKFIRE_LOG_LEVEL:-"1"}
touch /app/.heroku/php/var/blackfire/run/agent.sock
/app/.heroku/php/bin/blackfire-agent --config=/app/.heroku/php/etc/blackfire/agent.ini --socket="unix:///app/.heroku/php/var/blackfire/run/agent.sock" --log-level="${BLACKFIRE_LOG_LEVEL}" &
EOF
mkdir -p ${OUT_PREFIX}/etc/php/conf.d
cat > ${OUT_PREFIX}/etc/php/conf.d/blackfire.ini-dist <<'EOF'
extension = blackfire.so
blackfire.log_level = ${BLACKFIRE_LOG_LEVEL}
blackfire.server_token = ${BLACKFIRE_SERVER_TOKEN}
blackfire.server_id = ${BLACKFIRE_SERVER_ID}
blackfire.agent_socket = "unix:///app/.heroku/php/var/blackfire/run/agent.sock"
EOF
MANIFEST_REQUIRE="${MANIFEST_REQUIRE:-"{\"heroku-sys/php\":\"${series}.*\"}"}"
MANIFEST_CONFLICT="${MANIFEST_CONFLICT:-"{\"heroku-sys/hhvm\":\"*\"}"}"
MANIFEST_REPLACE="${MANIFEST_REPLACE:-"{}"}"
MANIFEST_PROVIDE="${MANIFEST_PROVIDE:-"{}"}"
MANIFEST_EXTRA="${MANIFEST_EXTRA:-"{\"config\":\"etc/php/conf.d/blackfire.ini-dist\",\"profile\":\"bin/profile.blackfire.sh\"}"}"
python $(dirname $BASH_SOURCE)/../../_util/include/manifest.py "heroku-sys-php-extension" "heroku-sys/ext-${dep_name}" "$dep_version" "${dep_formula}.tar.gz" "$MANIFEST_REQUIRE" "$MANIFEST_CONFLICT" "$MANIFEST_REPLACE" "$MANIFEST_PROVIDE" "$MANIFEST_EXTRA" > $dep_manifest
print_or_export_manifest_cmd "$(generate_manifest_cmd "$dep_manifest")"
if [[ "$dep_formula" == "$dep_name" ]]; then
cat <<-EOF
!!! WARNING !!! If you just deployed using --overwrite and without --publish:
the new manifest points to the updated tarball ${dep_name}.tar.gz;
this tarball will now already be picked up by the existing repository under a
wrong version number. Regenerate repository with 'mkrepo.sh --upload' at once!
EOF
fi