Skip to content

Commit

Permalink
Adding blackfire and xdebug
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Dec 20, 2019
1 parent ad3f1db commit 6afeae0
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 24 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ env:
- LAYER=amqp PHP=72
- LAYER=amqp PHP=73
- LAYER=amqp PHP=74
- LAYER=mecached PHP=72
- LAYER=mecached PHP=73
- LAYER=mecached PHP=74
- LAYER=blackfire PHP=72
- LAYER=blackfire PHP=73
- LAYER=blackfire PHP=74
- LAYER=xdebug PHP=72
- LAYER=xdebug PHP=73
- LAYER=xdebug PHP=74

script:
- cd layer/$LAYER
- cd layers/$LAYER
- docker build --build-arg PHP_VERSION=$PHP .
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SHELL := /bin/bash
php_versions = 72 73 74
php_versions = 73


docker-images:
PWD=pwd
Expand All @@ -10,23 +10,24 @@ docker-images:
echo "###############################################"; \
echo "### Building $${dir} PHP$${php_version}"; \
echo "###"; \
cd ${PWD} ; cd $${dir} ; docker build -t bref/$${dir}-php-$${php_version} --build-arg PHP_VERSION=$${php_version} ${DOCKER_BUILD_FLAGS} . ; \
cd ${PWD} ; cd $${dir} ; \
docker build -t bref/$${dir}-php-$${php_version} --build-arg PHP_VERSION=$${php_version} ${DOCKER_BUILD_FLAGS} . ; \
echo ""; \
done \
done

# The PHP runtimes
layers: docker-images
PWD=pwd
rm -rf export/tmp export/layer-*.zip || true
rm -rf export/layer-*.zip || true
mkdir export/tmp
for dir in layers/*; do \
for php_version in $(php_versions); do \
echo "###############################################"; \
echo "###############################################"; \
echo "### Exporting $${dir} PHP$${php_version}"; \
echo "###"; \
cd ${PWD} ; cd export/tmp ; \
cd ${PWD} ; rm -rf export/tmp/* || true ; cd export/tmp ; \
docker run --entrypoint "tar" bref/$${dir}-php-$${php_version} -ch -C /opt . | tar -x ; \
zip --quiet -X --recurse-paths ../`echo "$${dir}-php-$${php_version}" | sed -e "s/layers\//layer-/g"`.zip . ; \
echo ""; \
Expand Down
25 changes: 17 additions & 8 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Bref extra layers
# Bref Extra PHP Extension

Create small layers with specific PHP extensions. This is useful when you want something "off the shelf".
If you ever need more than one layer you should consider creating your own layer. That is because AWS has
a limit of 5 layers per Lambda.
This repository has some AWS Lambda layers with PHP extensions. This is useful when you want something "off the shelf".
If you ever need more than 2-3 layer you should consider creating your own layer. That is because AWS has
a limit of 5 layers per Lambda.

We are happy to get contributions for other extensions. Sky is the limit! (And also your knowledge with Docker...)

```yaml
# serverless.yml
Expand All @@ -15,22 +17,29 @@ provider:

plugins:
- ./vendor/bref/bref
- ./vendor/bref/extra-layers # Add the extra Serverless plugin
- ./vendor/bref/extra-layers # <--- Add the extra Serverless plugin

functions:
console:
handler: bin/console
layers:
- ${bref:layer.php-73}
- ${bref:extra.amqp-php-72} # AMQP layer
- ${bref:layer.php-74}
- ${bref:extra.amqp-php-74} # <----- Example for AMQP layer
- ${bref:layer.console}
```
```
;php/conf.d/php.ini
extension=amqp.so
extension=/opt/bref-extra/amqp.so
```

## Available layers

| Name | Serverless config (php 7.4) | php.ini config |
| ---- | ----------------------------| -------------- |
| AMQP | `${bref:extra.amqp-php-74}` | `extension=/opt/bref-extra/amqp.so` |
| Blackfire | `${bref:extra.blackfire-php-74}` | `extension=/opt/bref-extra/blackfire.so` |
| Xdebug | `${bref:extra.xdebug-php-74}` | `zend_extension=/opt/bref-extra/xdebug.so` |

## Deploy new versions

Expand Down
11 changes: 9 additions & 2 deletions checksums.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"memcached-php-73": "58d2102c602ff849734a57c255d70657",
"amqp-php-73": "26446b9824c8bb7af006664437fb09b8"
"blackfire-php-74": "d84b2d7f3e290237a40994e2d758fb05",
"amqp-php-74": "a77a771d9fbdb85c3733be399fe1d674",
"xdebug-php-74": "943b56db0f477f0be019318338f84dcb",
"blackfire-php-72": "41ee2abc51d6645b451b1ca712b989eb",
"blackfire-php-73": "b8c9548691e517c73aa9342fc17d7a85",
"amqp-php-72": "5f7a99b816afb6f8135b0c03d047a45f",
"xdebug-php-72": "44d5a532fcb4a54ac4d9b2d6f1337c92",
"xdebug-php-73": "4918003f160dd65986f5247d283846d4",
"amqp-php-73": "32a6249787c6d087a8d7f9ee1576cb51"
}
132 changes: 129 additions & 3 deletions layers.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,79 @@
{
"memcached-php-73": {
"blackfire-php-74": {
"ca-central-1": 1,
"eu-central-1": 1,
"eu-north-1": 1,
"eu-west-1": 1,
"eu-west-2": 1,
"eu-west-3": 1,
"sa-east-1": 1,
"us-east-1": 1,
"us-east-2": 1,
"us-west-1": 1,
"us-west-2": 1,
"ap-south-1": 1,
"ap-northeast-1": 1,
"ap-northeast-2": 1,
"ap-southeast-1": 1,
"ap-southeast-2": 1
},
"amqp-php-74": {
"ca-central-1": 1,
"eu-central-1": 1,
"eu-north-1": 1,
"eu-west-1": 1,
"eu-west-2": 1,
"eu-west-3": 1,
"sa-east-1": 1,
"us-east-1": 1,
"us-east-2": 1,
"us-west-1": 1,
"us-west-2": 1,
"ap-south-1": 1,
"ap-northeast-1": 1,
"ap-northeast-2": 1,
"ap-southeast-1": 1,
"ap-southeast-2": 1
},
"xdebug-php-74": {
"ca-central-1": 1,
"eu-central-1": 1,
"eu-north-1": 1,
"eu-west-1": 1,
"eu-west-2": 1,
"eu-west-3": 1,
"sa-east-1": 1,
"us-east-1": 1,
"us-east-2": 1,
"us-west-1": 1,
"us-west-2": 1,
"ap-south-1": 1,
"ap-northeast-1": 1,
"ap-northeast-2": 1,
"ap-southeast-1": 1,
"ap-southeast-2": 1
},
"blackfire-php-72": {
"ca-central-1": 1,
"eu-central-1": 1,
"eu-north-1": 1,
"eu-west-1": 1,
"eu-west-2": 1,
"eu-west-3": 1,
"sa-east-1": 1,
"us-east-1": 1,
"us-east-2": 1,
"us-west-1": 1,
"us-west-2": 1,
"ap-south-1": 1,
"ap-northeast-1": 1,
"ap-northeast-2": 1,
"ap-southeast-1": 1,
"ap-southeast-2": 1
},
"blackfire-php-73": {
"ca-central-1": 2,
"eu-central-1": 3,
"eu-central-1": 2,
"eu-north-1": 2,
"eu-west-1": 2,
"eu-west-2": 2,
Expand All @@ -17,7 +89,43 @@
"ap-southeast-1": 2,
"ap-southeast-2": 2
},
"amqp-php-73": {
"amqp-php-72": {
"ca-central-1": 1,
"eu-central-1": 1,
"eu-north-1": 1,
"eu-west-1": 1,
"eu-west-2": 1,
"eu-west-3": 1,
"sa-east-1": 1,
"us-east-1": 1,
"us-east-2": 1,
"us-west-1": 1,
"us-west-2": 1,
"ap-south-1": 1,
"ap-northeast-1": 1,
"ap-northeast-2": 1,
"ap-southeast-1": 1,
"ap-southeast-2": 1
},
"xdebug-php-72": {
"ca-central-1": 1,
"eu-central-1": 1,
"eu-north-1": 1,
"eu-west-1": 1,
"eu-west-2": 1,
"eu-west-3": 1,
"sa-east-1": 1,
"us-east-1": 1,
"us-east-2": 1,
"us-west-1": 1,
"us-west-2": 1,
"ap-south-1": 1,
"ap-northeast-1": 1,
"ap-northeast-2": 1,
"ap-southeast-1": 1,
"ap-southeast-2": 1
},
"xdebug-php-73": {
"ca-central-1": 3,
"eu-central-1": 3,
"eu-north-1": 3,
Expand All @@ -34,5 +142,23 @@
"ap-northeast-2": 3,
"ap-southeast-1": 3,
"ap-southeast-2": 3
},
"amqp-php-73": {
"ca-central-1": 4,
"eu-central-1": 4,
"eu-north-1": 4,
"eu-west-1": 4,
"eu-west-2": 4,
"eu-west-3": 4,
"sa-east-1": 4,
"us-east-1": 4,
"us-east-2": 4,
"us-west-1": 4,
"us-west-2": 4,
"ap-south-1": 4,
"ap-northeast-1": 4,
"ap-northeast-2": 4,
"ap-southeast-1": 4,
"ap-southeast-2": 4
}
}
3 changes: 2 additions & 1 deletion layers/amqp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN set -xe; \
cmake --build . --target install

RUN pecl install amqp
RUN cp /opt/bref/lib/php/extensions/no-debug-zts-*/amqp.so /tmp/amqp.so

# Build the final image from the lambci image that is close to the production environment
FROM lambci/lambda:provided
Expand All @@ -34,4 +35,4 @@ COPY --from=ext /opt/bref/lib64/librabbitmq.so.4 /opt/bref/lib64/librabbitmq.so.
COPY --from=ext /opt/bref/lib64/librabbitmq.so.4.3.0 /opt/bref/lib64/librabbitmq.so.4.3.0
COPY --from=ext /opt/bref/lib64/pkgconfig/librabbitmq.pc /opt/bref/lib64/pkgconfig/librabbitmq.pc

COPY --from=ext /opt/bref/lib/php/extensions/no-debug-zts-20180731/amqp.so /opt/bref/lib/php/extensions/no-debug-zts-20180731/amqp.so
COPY --from=ext /tmp/amqp.so /opt/bref-extra/amqp.so
16 changes: 16 additions & 0 deletions layers/blackfire/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG PHP_VERSION
FROM bref/build-php-$PHP_VERSION AS ext

RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")-zts \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& cp /tmp/blackfire/blackfire-*.so /tmp/blackfire.so \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz


# Build the final image from the lambci image that is close to the production environment
FROM lambci/lambda:provided

# Copy things we installed to the final image
COPY --from=ext /tmp/blackfire.so /opt/bref-extra/blackfire.so
5 changes: 3 additions & 2 deletions layers/memcached/Dockerfile → layers/xdebug/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
ARG PHP_VERSION
FROM bref/build-php-$PHP_VERSION AS ext

RUN LD_LIBRARY_PATH= yum install -y php-pecl-memcached
RUN pecl install xdebug
RUN cp `php-config --extension-dir`/xdebug.so /tmp/xdebug.so

# Build the final image from the lambci image that is close to the production environment
FROM lambci/lambda:provided

# Copy things we installed to the final image
COPY --from=ext /usr/lib64/php/modules/memcached.so /opt/bref/lib/php/extensions/no-debug-zts-20180731/memcached.so
COPY --from=ext /tmp/xdebug.so /opt/bref-extra/xdebug.so
1 change: 1 addition & 0 deletions src/Command/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function __invoke(OutputInterface $output)
exit(1);
}

ksort($discoveredChecksums);
// Dump checksums
file_put_contents($this->projectDir.'/checksums.json', json_encode($discoveredChecksums, \JSON_PRETTY_PRINT));

Expand Down

0 comments on commit 6afeae0

Please sign in to comment.