Skip to content

Commit 326c97e

Browse files
authored
MCLOUD-5857: Added Blackfire support (#202)
1 parent 3744f00 commit 326c97e

File tree

15 files changed

+129
-3
lines changed

15 files changed

+129
-3
lines changed

images/php/7.2-cli/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ RUN pecl install -o -f \
122122
xdebug-2.6.1 \
123123
yaml
124124

125+
RUN curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
126+
&& mkdir -p /tmp/blackfire \
127+
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
128+
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
129+
&& ( echo extension=blackfire.so \
130+
&& echo blackfire.agent_socket=tcp://blackfire:8707 ) > $(php -i | grep "additional .ini" | awk '{print $9}')/blackfire.ini \
131+
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
125132
RUN rm -f /usr/local/etc/php/conf.d/*sodium.ini \
126133
&& rm -f /usr/local/lib/php/extensions/*/*sodium.so \
127134
&& apt-get remove libsodium* -y \
@@ -145,6 +152,7 @@ RUN cd /tmp \
145152

146153
RUN docker-php-ext-enable \
147154
bcmath \
155+
blackfire \
148156
bz2 \
149157
calendar \
150158
exif \

images/php/7.2-fpm/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ RUN pecl install -o -f \
100100
xdebug-2.6.1 \
101101
yaml
102102

103+
RUN curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
104+
&& mkdir -p /tmp/blackfire \
105+
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
106+
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
107+
&& ( echo extension=blackfire.so \
108+
&& echo blackfire.agent_socket=tcp://blackfire:8707 ) > $(php -i | grep "additional .ini" | awk '{print $9}')/blackfire.ini \
109+
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
103110
RUN rm -f /usr/local/etc/php/conf.d/*sodium.ini \
104111
&& rm -f /usr/local/lib/php/extensions/*/*sodium.so \
105112
&& apt-get remove libsodium* -y \
@@ -123,6 +130,7 @@ RUN cd /tmp \
123130

124131
RUN docker-php-ext-enable \
125132
bcmath \
133+
blackfire \
126134
bz2 \
127135
calendar \
128136
exif \

images/php/7.3-cli/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ RUN pecl install -o -f \
119119
xdebug-2.7.1 \
120120
yaml
121121

122+
RUN curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
123+
&& mkdir -p /tmp/blackfire \
124+
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
125+
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
126+
&& ( echo extension=blackfire.so \
127+
&& echo blackfire.agent_socket=tcp://blackfire:8707 ) > $(php -i | grep "additional .ini" | awk '{print $9}')/blackfire.ini \
128+
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
122129
RUN rm -f /usr/local/etc/php/conf.d/*sodium.ini \
123130
&& rm -f /usr/local/lib/php/extensions/*/*sodium.so \
124131
&& apt-get remove libsodium* -y \
@@ -142,6 +149,7 @@ RUN cd /tmp \
142149

143150
RUN docker-php-ext-enable \
144151
bcmath \
152+
blackfire \
145153
bz2 \
146154
calendar \
147155
exif \

images/php/7.3-fpm/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ RUN pecl install -o -f \
9797
xdebug-2.7.1 \
9898
yaml
9999

100+
RUN curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
101+
&& mkdir -p /tmp/blackfire \
102+
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
103+
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
104+
&& ( echo extension=blackfire.so \
105+
&& echo blackfire.agent_socket=tcp://blackfire:8707 ) > $(php -i | grep "additional .ini" | awk '{print $9}')/blackfire.ini \
106+
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
100107
RUN rm -f /usr/local/etc/php/conf.d/*sodium.ini \
101108
&& rm -f /usr/local/lib/php/extensions/*/*sodium.so \
102109
&& apt-get remove libsodium* -y \
@@ -120,6 +127,7 @@ RUN cd /tmp \
120127

121128
RUN docker-php-ext-enable \
122129
bcmath \
130+
blackfire \
123131
bz2 \
124132
calendar \
125133
exif \

images/php/7.4-cli/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
FROM php:7.4-cli-buster
33
ARG GOSU_VERSION=1.11
44

5+
ENV COMPOSER_MEMORY_LIMIT -1
56
ENV PHP_MEMORY_LIMIT 2G
67
ENV MAGENTO_ROOT /app
78
ENV DEBUG false
@@ -108,6 +109,13 @@ RUN pecl install -o -f \
108109
xdebug-2.9.3 \
109110
yaml
110111

112+
RUN curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
113+
&& mkdir -p /tmp/blackfire \
114+
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
115+
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
116+
&& ( echo extension=blackfire.so \
117+
&& echo blackfire.agent_socket=tcp://blackfire:8707 ) > $(php -i | grep "additional .ini" | awk '{print $9}')/blackfire.ini \
118+
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
111119
RUN rm -f /usr/local/etc/php/conf.d/*sodium.ini \
112120
&& rm -f /usr/local/lib/php/extensions/*/*sodium.so \
113121
&& apt-get remove libsodium* -y \
@@ -123,6 +131,7 @@ RUN rm -f /usr/local/etc/php/conf.d/*sodium.ini \
123131

124132
RUN docker-php-ext-enable \
125133
bcmath \
134+
blackfire \
126135
bz2 \
127136
calendar \
128137
exif \

images/php/7.4-fpm/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ RUN pecl install -o -f \
8787
xdebug-2.9.3 \
8888
yaml
8989

90+
RUN curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
91+
&& mkdir -p /tmp/blackfire \
92+
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
93+
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
94+
&& ( echo extension=blackfire.so \
95+
&& echo blackfire.agent_socket=tcp://blackfire:8707 ) > $(php -i | grep "additional .ini" | awk '{print $9}')/blackfire.ini \
96+
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
9097
RUN rm -f /usr/local/etc/php/conf.d/*sodium.ini \
9198
&& rm -f /usr/local/lib/php/extensions/*/*sodium.so \
9299
&& apt-get remove libsodium* -y \
@@ -102,6 +109,7 @@ RUN rm -f /usr/local/etc/php/conf.d/*sodium.ini \
102109

103110
RUN docker-php-ext-enable \
104111
bcmath \
112+
blackfire \
105113
bz2 \
106114
calendar \
107115
exif \

src/Compose/Php/ExtensionResolver.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ExtensionResolver
8585
/**
8686
* Extensions which should be ignored
8787
*/
88-
private const IGNORED_EXTENSIONS = ['blackfire', 'newrelic'];
88+
private const IGNORED_EXTENSIONS = ['newrelic'];
8989

9090
/**
9191
* @var Semver
@@ -163,6 +163,22 @@ public static function getConfig(): array
163163
'bcmath' => [
164164
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
165165
],
166+
'blackfire' => [
167+
'>=7.2' => [
168+
self::EXTENSION_TYPE => self::EXTENSION_TYPE_INSTALLATION_SCRIPT,
169+
// phpcs:disable
170+
self::EXTENSION_INSTALLATION_SCRIPT => <<< BASH
171+
curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")
172+
mkdir -p /tmp/blackfire
173+
tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire
174+
mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so
175+
( echo extension=blackfire.so
176+
echo blackfire.agent_socket=tcp://blackfire:8707 ) > $(php -i | grep "additional .ini" | awk '{print $9}')/blackfire.ini
177+
rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
178+
BASH
179+
// phpcs:enable
180+
]
181+
],
166182
'bz2' => [
167183
'>=7.0' => [
168184
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,

src/Compose/ProductionBuilder.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,27 @@ public function build(Config $config): Manager
345345
);
346346
}
347347

348+
if ($config->hasServiceEnabled(ServiceInterface::SERVICE_BLACKFIRE)) {
349+
$manager->addService(
350+
ServiceInterface::SERVICE_BLACKFIRE,
351+
$this->serviceFactory->create(
352+
ServiceInterface::SERVICE_BLACKFIRE,
353+
$config->getServiceVersion(ServiceInterface::SERVICE_BLACKFIRE),
354+
[
355+
'environment' => [
356+
'BLACKFIRE_SERVER_ID' => $config->getBlackfireConfig()['server_id'],
357+
'BLACKFIRE_SERVER_TOKEN' => $config->getBlackfireConfig()['server_token'],
358+
'BLACKFIRE_CLIENT_ID' => $config->getBlackfireConfig()['client_id'],
359+
'BLACKFIRE_CLIENT_TOKEN' => $config->getBlackfireConfig()['client_token']
360+
],
361+
'ports' => ["8707"]
362+
]
363+
),
364+
[self::NETWORK_MAGENTO],
365+
[]
366+
);
367+
}
368+
348369
$phpExtensions = $this->phpExtension->get($config);
349370

350371
/**

src/Config/Config.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ public function hasTmpMounts(): bool
248248
return (bool)$this->all()->get(SourceInterface::SYSTEM_TMP_MOUNTS);
249249
}
250250

251+
/**
252+
* @return array
253+
* @throws ConfigurationMismatchException
254+
*/
255+
public function getBlackfireConfig(): array
256+
{
257+
return (array)$this->all()->get(SourceInterface::SERVICES_BLACKFIRE_CONFIG, []);
258+
}
259+
251260
/**
252261
* @return string|null
253262
* @throws ConfigurationMismatchException

src/Config/Source/CloudSource.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ private function addRelationships(Repository $repository, array $relationships):
204204
* @param array $extensions
205205
* @param array $disabledExtensions
206206
* @return Repository
207+
* @throws ConfigurationMismatchException
207208
*/
208209
private function addPhp(
209210
Repository $repository,
@@ -217,6 +218,23 @@ private function addPhp(
217218
]);
218219

219220
if ($extensions) {
221+
/* Parse nested Blackfire configuration */
222+
foreach ($extensions as $key => $phpExtension) {
223+
if (is_array($phpExtension) && $phpExtension["name"] === ServiceInterface::SERVICE_BLACKFIRE) {
224+
/* Store extension data in repository */
225+
$repository->set([
226+
self::SERVICES_BLACKFIRE_ENABLED => true,
227+
self::SERVICES_BLACKFIRE_VERSION =>
228+
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_BLACKFIRE),
229+
self::SERVICES_BLACKFIRE_IMAGE =>
230+
$this->serviceFactory->getDefaultImage(ServiceInterface::SERVICE_BLACKFIRE),
231+
self::SERVICES_BLACKFIRE_CONFIG => $phpExtension["configuration"]
232+
]);
233+
/* Reset nested extension data with extension name */
234+
$extensions[$key] = ServiceInterface::SERVICE_BLACKFIRE;
235+
}
236+
}
237+
220238
$repository[self::PHP_ENABLED_EXTENSIONS] = $extensions;
221239
}
222240

0 commit comments

Comments
 (0)