11#! /usr/bin/env bash
22
33set -e
4- set -ex
54
65# Install Blackfire
7- version=$( php -r " echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;" )
8-
9- if [[ -z " ${BLACKFIRE_VERSION} " ]]; then
6+ if [[ " ${BLACKFIRE_VERSION} " == " " ]]; then
107 echo " Blackfire version is not set in the environment variables. Exiting!"
118 exit 1
129fi
1310
1411# Let's make it flexible: for those who want to be safe, the image will be built with v1
1512# Now if you build the image yourself, you can build it with v2, this way everyone gets happy :)
1613
17- mkdir /tmp/blackfire
18-
19- # Todo: Maybe version the Blackfire version by environment variable? :)
20-
21- if [ $BLACKFIRE_VERSION == " 1" ]; then
22- echo " Installing Blackfire version 1"
23- # curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v2/releases/probe/php/linux/amd64/$version
24- curl -o /tmp/blackfire/blackfire.so " https://packages.blackfire.io/binaries/blackfire-php/1.78.0/blackfire-php-$CONTAINER_OS " _" $CONTAINER_ARCH -php-$version .so"
25- mv /tmp/blackfire/blackfire.so $( php -r " echo ini_get('extension_dir');" ) /blackfire.so
26- echo " extension=blackfire.so" > /etc/php/${PHP_VERSION} /mods-available/blackfire.ini
27-
28- # Adding this in the list of Ubuntu extensions because we use that list as a base for the modules list.
29- # TODO: question: cannot we use /etc/php/mods-available instead???
30- touch /var/lib/php/modules/${PHP_VERSION} /registry/blackfire
31- # curl -A "Docker" -L https://blackfire.io/api/v1/releases/client/linux_static/amd64 | tar zxp -C /tmp/blackfire
32- curl -o /tmp/blackfire/blackfire " https://packages.blackfire.io/binaries/blackfire-agent/1.50.0/blackfire-cli-$CONTAINER_OS " _" $CONTAINER_ARCH "
33- chmod +x /tmp/blackfire/blackfire
34- mv /tmp/blackfire/blackfire /usr/bin/blackfire
35- rm -Rf /tmp/blackfire
36-
37- elif [ $BLACKFIRE_VERSION == " 2" ]; then
38- echo " Installing Blackfire version 2..."
39-
40- curl -o /tmp/blackfire/blackfire.so " https://packages.blackfire.io/binaries/blackfire-php/1.78.0/blackfire-php-$CONTAINER_OS " _" $CONTAINER_ARCH -php-$version .so"
41- mv /tmp/blackfire/blackfire.so $( php -r " echo ini_get('extension_dir');" ) /blackfire.so
42- echo " extension=blackfire.so" > /etc/php/${PHP_VERSION} /mods-available/blackfire.ini
43- touch /var/lib/php/modules/${PHP_VERSION} /registry/blackfire
44- curl -o /tmp/blackfire-cli.tar.gz " https://packages.blackfire.io/binaries/blackfire/2.10.0/blackfire-" $CONTAINER_OS " _" $CONTAINER_ARCH " .tar.gz"
45- tar zxpf /tmp/blackfire-cli.tar.gz -C /tmp/blackfire
46- mv /tmp/blackfire/blackfire /usr/bin/blackfire
47-
48- rm -Rf /tmp/blackfire
14+ version=$( php -r " echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;" )
15+ # Probe is the same for v1 and v2
16+ curl -A " Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/${TARGETOS} /${TARGETARCH} /$version
17+ mkdir -p /tmp/blackfire
18+ tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire
19+ mv /tmp/blackfire/blackfire-* .so $( php -r " echo ini_get ('extension_dir');" ) /blackfire.so
20+ printf " extension=blackfire.so" > " /etc/php/${PHP_VERSION} /mods-available/blackfire.ini"
21+ rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
22+
23+ if [[ " ${BLACKFIRE_VERSION} " == " 1" ]]; then
24+ # Cli for v1 require specific version
25+ curl -A " Docker" " https://packages.blackfire.io/binaries/blackfire-agent/1.50.0/blackfire-cli-${TARGETOS} " _" ${TARGETARCH} " -o /tmp/blackfire
26+ chmod +x /tmp/blackfire
27+ mv /tmp/blackfire /usr/bin/blackfire
28+ rm -Rf /tmp/blackfire
29+ elif [[ " ${BLACKFIRE_VERSION} " == " 2" ]]; then
30+ # Cli for v2 is latest version
31+ echo " Installing Blackfire version 2..."
32+ mkdir -p /tmp/blackfire
33+ curl -A " Docker" -L https://blackfire.io/api/v1/releases/cli/linux/${TARGETARCH} | tar zxp -C /tmp/blackfire
34+ if ! /tmp/blackfire/blackfire self:version --no-ansi | grep -qE " version 2\.[0-9]+\.[0-9]+" ; then
35+ echo " Blackfire installed is not version 2 : $( /tmp/blackfire/blackfire self:version --no-ansi) "
36+ exit 1
37+ fi
38+ mv /tmp/blackfire/blackfire /usr/bin/blackfire
39+ rm -Rf /tmp/blackfire
4940else
50- echo " Blackfire version in environment variable is either empty or the value is invalid"
51- echo " Value: '$BLACKFIRE_VERSION '"
41+ echo " Blackfire version in environment variable is invalid"
42+ echo " Value: '${ BLACKFIRE_VERSION} '"
5243 exit 1
53- fi
44+ fi
45+
46+ # Let's perform a test
47+ phpenmod -v $PHP_VERSION blackfire
48+ /usr/bin/real_php -m | grep " blackfire"
49+ # Check that there is no output on STDERR when starting php:
50+ OUTPUT=` /usr/bin/real_php -r " echo '';" 2>&1 `
51+ [[ " $OUTPUT " == " " ]]
52+ # And now, let's disable it!
53+ phpdismod -v $PHP_VERSION blackfire
0 commit comments