Skip to content

Commit

Permalink
Merge pull request heroku#94 from deguif/blackfire_refactor_specials_…
Browse files Browse the repository at this point in the history
…exts

Add blackfire install on heroku
  • Loading branch information
dzuelke committed Nov 28, 2014
2 parents 9bcf6bd + d7c3000 commit 0adff36
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ source $BP_DIR/bin/util/common.sh

# for extensions that need special treatment
source $BP_DIR/bin/util/newrelic.sh
source $BP_DIR/bin/util/blackfire.sh

export_env_dir "$ENV_DIR" '^[A-Z_][A-Z0-9_]*$' '^(HOME|PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH|LD_LIBRARY_PATH|STACK|S3_URL|RTVS_URL)$'

Expand Down Expand Up @@ -235,7 +236,10 @@ if [[ "${PHP_VERSION}" ]]; then

# special treatment for New Relic; we enable it if we detect a license key for it
install_newrelic_ext


# special treatment for Blackfire; we enable it if we detect a server id and a server token for it
install_blackfire_ext

if [[ ${#exts[@]} -eq 0 || ! ${exts[*]} =~ "zend-opcache" ]]; then
install_ext "zend-opcache" "automatic"
exts+=("zend-opcache")
Expand Down Expand Up @@ -359,6 +363,8 @@ fi
install_newrelic_daemon
install_newrelic_userini

install_blackfire_agent

if [[ ! -f "Procfile" ]]; then
bindir=$(composer config bin-dir 2> /dev/null | tail -n 1) # tail, as composer echos outdated version warnings to STDOUT
echo "web: $bindir/heroku-$engine-apache2" > Procfile
Expand Down
22 changes: 22 additions & 0 deletions bin/util/blackfire.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

install_blackfire_ext() {
# special treatment for Blackfire; we enable it if we detect a server id and a server token for it
# otherwise users would have to have it in their require section, which is annoying in development environments
BLACKFIRE_SERVER_ID=${BLACKFIRE_SERVER_ID:-}
BLACKFIRE_SERVER_TOKEN=${BLACKFIRE_SERVER_TOKEN:-}
if [[ ( ${#exts[@]} -eq 0 || ! ${exts[*]} =~ "blackfire" ) && -n "$BLACKFIRE_SERVER_TOKEN" && -n "$BLACKFIRE_SERVER_ID" ]]; then
install_ext "blackfire" "add-on detected"
exts+=("blackfire")
fi
}

install_blackfire_agent() {
# blackfire defaults
cat > $BUILD_DIR/.profile.d/blackfire.sh <<"EOF"
if [[ -n "$BLACKFIRE_SERVER_TOKEN" && -n "$BLACKFIRE_SERVER_TOKEN" ]]; then
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" &
fi
EOF
}
5 changes: 5 additions & 0 deletions conf/php/conf.d/ext-blackfire.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extension = blackfire.so

blackfire.server_token = ${BLACKFIRE_SERVER_TOKEN}
blackfire.server_id = ${BLACKFIRE_SERVER_ID}
blackfire.agent_socket = "unix:///app/.heroku/php/var/blackfire/run/agent.sock"
37 changes: 37 additions & 0 deletions support/build/extensions/no-debug-non-zts-20121212/blackfire
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Build Path: /app/.heroku/php

OUT_PREFIX=$1

# fail hard
set -o pipefail
# fail harder
set -eux

ext_dir=${OUT_PREFIX}/lib/php/extensions/no-debug-non-zts-${ZEND_MODULE_API_VERSION:=20121212}
bin_dir=${OUT_PREFIX}/bin

probe_version=`curl -A "Heroku" -o probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/${PHP_MAJOR_VERSION:=5}${PHP_MINOR_VERSION:=5} | grep 'X-Blackfire-Release-Version: ' | sed "s%X-Blackfire-Release-Version: %%" | sed s%.$%%`
echo "-----> Packaging ext/blackfire ${probe_version} (for Zend module API version ${ZEND_MODULE_API_VERSION})..."

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

echo "-----> Done."

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}/blackfire
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 "-----> Done."
7 changes: 7 additions & 0 deletions support/build/extensions/no-debug-non-zts-20131226/blackfire
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Build Path: /app/.heroku/php/

ZEND_MODULE_API_VERSION=20131226
PHP_MINOR_VERSION=6

source $(dirname $0)/../no-debug-non-zts-20121212/$(basename $0)

0 comments on commit 0adff36

Please sign in to comment.