Skip to content

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Mar 16, 2023
2 parents f858f5d + 9fccbad commit 3a82859
Show file tree
Hide file tree
Showing 55 changed files with 331 additions and 545 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/blackfire.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
id: fetch_version
run: |
cd layers/blackfire;
for VERSION in 73 74 80 81; do
for VERSION in 80 81; do
BF_AGENT_VERSION=$(curl -s -o probe -D - https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$VERSION | grep -i 'X-Blackfire-Release-Version: ' | sed "s%X-Blackfire-Release-Version: %%I" | sed s%.$%%);
php ./store.php $VERSION $BF_AGENT_VERSION;
done
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change log

## 2.0.0

## Breaking changes

- Just like Bref v2, support for PHP 7.3 and 7.4 was dropped. PHP 8.0 or greater is required.

## Internal changes

These internal changes will not impact most users, however we list them in case you have an advanced use case:

- The "bref-extra" PHP extensions are now installed in the official Bref directory for PHP extensions: `/opt/bref/extensions`. They were previously installed in `/opt/bref-extra`.

## 0.12.5

### Added
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ SHELL := /bin/bash
layer ?= *
resolve_php_versions = $(or $(php_versions),`jq -r '.php | join(" ")' ${1}/config.json`)
resolve_tags = `./new-docker-tags.php $(DOCKER_TAG)`
BREF_VERSION = 2
define build_docker_image
docker build -t bref/${1}-php-${2} --build-arg PHP_VERSION=${2} ${DOCKER_BUILD_FLAGS} ${1}
docker build -t bref/${1}-php-${2} --build-arg PHP_VERSION=${2} --build-arg BREF_VERSION=${BREF_VERSION} ${DOCKER_BUILD_FLAGS} ${1}
endef
docker-images:
Expand Down
17 changes: 7 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ service: app
provider:
name: aws
region: us-east-1
runtime: provided.al2

plugins:
- ./vendor/bref/bref
Expand All @@ -30,10 +29,9 @@ plugins:
functions:
console:
handler: bin/console
runtime: php-81
layers:
- ${bref:layer.php-81}
- ${bref-extra:amqp-php-81} # <----- Example for AMQP layer
- ${bref:layer.console}
```
### Available layers
Expand Down Expand Up @@ -161,9 +159,8 @@ docker-compose.yml
Dockerfile-phpFpm
```
FROM bref/extra-mongodb-php-82 as mongodbextra
FROM bref/php-82-fpm-dev
COPY --from=mongodbextra /opt /opt
COPY --from=bref/extra-mongodb-php-82 /opt /opt
```
## For contributors and maintainers
Expand All @@ -172,7 +169,7 @@ COPY --from=mongodbextra /opt /opt
The idea is to start from bref/build-php-XX, install all libraries and extensions
you want, then move all related files to `/opt`. Those files will be available in
the same same location on the Lambda.
the same location on the Lambda.
Note that one can't just move files/libraries around. Most of them are expected to
be in their "standard" location.
Expand All @@ -195,7 +192,7 @@ make test
layer=imagick make test

# Test a single layer on a single PHP version
layer=imagick php_versions=74 make test
layer=imagick php_versions=81 make test
```
You can publish the layer in your AWS account to test it in AWS Lambda as well:
Expand Down Expand Up @@ -227,14 +224,14 @@ git push
#### Config
You can also build only one specific layer by providing `layer=blackfire` to `make`.
Same thing for some specific version(s) of php by providing `php_versions="73 74"` to `make`.
Same thing for some specific version(s) of php by providing `php_versions="80 81"` to `make`.
You can invoke both ways:
```shell
# First way: make with named arguments
make layer=gd php_versions=74
make layer=gd php_versions=81
# Second way: environment variables passed to make
layer=blackfire php_versions=80 make
layer=blackfire php_versions=81 make
```

## Lambda layers in details
Expand Down
54 changes: 1 addition & 53 deletions checksums.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,18 @@
{
"amqp-php-73": "62d7818aae952cda723294c549f4fe2e",
"amqp-php-74": "75f216839af0a7954508c0dfbe111ef2",
"blackfire-php-73": "cddd48f0de242f95b2a4c9919111e63f",
"blackfire-php-74": "02eb83348630a23281ad8a5f8050d7a3",
"cassandra-php-73": "856f61c17a91fd801f342fe57d304a0f",
"cassandra-php-74": "78865fc2551e11b0c7725aeda15c0463",
"ds-php-73": "d7e766ac190ef7e73d73d205475f8aea",
"ds-php-74": "bf75a8ba745dd1078b8385bdadc4b9d8",
"ds-php-80": "3ac724f1507a22a67299ac2d4f4bbda2",
"gd-php-73": "34d3c9485a429de127dbca8fc482a22f",
"gd-php-74": "ca873f4f60cd8704f8c42eaef28e971e",
"gd-php-80": "335e9a9a1ed3382c01293e4c0f13b5b2",
"gmp-php-73": "b9af2bdb33760e39fd122e8b2b077255",
"gmp-php-74": "d5e318c544bfd64074bd5a3c51b26a5d",
"gmp-php-80": "239d8bbdebd17c951a416fa1798692b7",
"grpc-php-73": "ad4b288e5a2a5fe8a68d1d2e3f69e902",
"grpc-php-74": "9969c30b4e82913dbe21243b55ecd616",
"igbinary-php-73": "437902c68dc48cb2af42bb87eb710a09",
"igbinary-php-74": "a5b236c3e07c4edb9bea571da52b9686",
"igbinary-php-80": "4c293f167ffa6a1ecc75b7d5c5a07013",
"imagick-php-73": "c27620d1830353932bf145c938b5c53f",
"imagick-php-74": "6d8a40d33fe0c59acfa41461a21ca73d",
"imagick-php-80": "fc7c7e396565f1121077c59932ff285a",
"imap-php-73": "c141e6bc9d7c5fc54054df54fdba9f48",
"imap-php-74": "ed66daf477e5ba479326774f080c4d87",
"ldap-php-73": "f759f8b488b6f1643fe9081658e7560a",
"ldap-php-74": "b5bedc999d3d0aed235df293dcd410ed",
"ldap-php-80": "4af191177c16dfa221567b338eb58815",
"mailparse-php-73": "f49f0b66c0db338fab8e56577e5ad10d",
"mailparse-php-74": "702aafe062cea83884c74cecf2c69fad",
"mailparse-php-80": "c27d4e271dcf873ff318b0d6eb940c51",
"memcache-php-73": "711c4d269533d616b401a7d566e41b71",
"memcache-php-74": "b87da75e0c31d0f18285a6a7fa9a4095",
"memcache-php-80": "c3ae49f188ccbb17f8498fad8e909a8f",
"memcached-php-73": "c4f73f8f249c88b67fa02c4ce779a52e",
"memcached-php-74": "8c55e19abce3d0a1129ae3760d51053d",
"mongodb-php-73": "e82ff82226354fbcae68b74756b54288",
"mongodb-php-74": "6566353f69bfab2dd21f4c6835255d8d",
"mongodb-php-80": "23c388c85a95e637ddce66d69af2cc2d",
"msgpack-php-73": "dbe21d378313821d63ef61d27a782105",
"msgpack-php-74": "9135bd160a9105d2a11fea58679a5f95",
"newrelic-php-73": "ac551418182cb06319b7bcb480d7bc5d",
"newrelic-php-74": "46e860d2654a02191b10178f4ee2edd1",
"odbc-snowflake-php-73": "7ed04eb4497e0d4ef039d7d94d807179",
"odbc-snowflake-php-74": "d965793a15654afe08bd40e252e1e029",
"odbc-snowflake-php-80": "431007abb1ea2e3dc26c748311f3e023",
"pcov-php-73": "57668c70f6c1e38ddd65496fb9bf2af1",
"pcov-php-74": "6520eddb62ba44cb890a75094dd469be",
"pcov-php-80": "c631e6947dd69b4f703844aa8f017497",
"pgsql-php-73": "d4954f4784a162725336212dd3ae451a",
"pgsql-php-74": "82a1fda19ed497b7eca72da6c9ccdbca",
"pgsql-php-80": "a8983cf4f4e255f9f49bf13becf9d9d9",
"redis-php-73": "6c5a727445ae3551bc91c4c9735fcb2c",
"redis-php-74": "788c19584d1c6c58cb32245219727efd",
"redis-php-80": "b33bb5ad2fa07e325b972d6759b482bf",
"scrypt-php-73": "659640c1633cc28f5259bf189cfb5f46",
"scrypt-php-74": "f946cee8f6b9ae9de5f4d4465621da7e",
"sqlsrv-php-73": "31dcf086af0ef509f0dc6e72708a60ca",
"sqlsrv-php-74": "757c92ade582cdbdec90b6e06db31daa",
"uuid-php-73": "04f1d6061082bd3cb502245ee83338c4",
"uuid-php-74": "ec21632672422d72a1e57f92ebf84508",
"uuid-php-80": "8326ea5beb0a64dbda618af5de9a9b37",
"xdebug-php-73": "db4333638a7b701d05c42a20485bea70",
"xdebug-php-74": "787d7984d239798ee91839d19b58e801",
"xdebug-php-80": "87cce18a36803f9b850e5c4e0f5791cb",
"yaml-php-73": "338da4e5f5b0ec10ba59779ec6645c5e",
"yaml-php-74": "9a4c6a491aea61a1043bcf8b8f24e041",
"yaml-php-80": "6d3b1b4eec7e5667a80849a6feb742a3"
}
}
63 changes: 30 additions & 33 deletions docs/create_your_own_extension_layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ FROM scratch
```

The environment variable `PHP_VERSION` is passed from the Makefile as an argument
to docker build. It may have values like: `73`, `74`, `80`. A docker image is created
to docker build. It may have values like: `80`, `81`. A docker image is created
for each `PHP_VERSION`. If the build procedure of your extension differs for each version,
you may use this variable to switch processing in Dockerfile.

There are some other env variables available,`PHP_BUILD_DIR` is `/tmp/build/php`, `INSTALL_DIR` is `/opt/bref`.
There are some other env variables available, like `PHP_BUILD_DIR` or `INSTALL_DIR`.

### Building your extension

Expand All @@ -47,6 +47,8 @@ RUN ./configure --with-pgsql=${INSTALL_DIR}
RUN make -j `nproc` && make install

RUN cp `php-config --extension-dir`/pgsql.so /tmp/pgsql.so
RUN echo 'extension=pgsql.so' > /tmp/ext.ini
RUN php /bref/lib-copy/copy-dependencies.php /tmp/pgsql.so /tmp/extension-libs
```

You may need to:
Expand All @@ -57,19 +59,23 @@ You may need to:

The Dockerfiles for [these](../layers) extensions could be very helpful.

> **Note**
> The `/bref/lib-copy/copy-dependencies.php` script will automatically copy system dependencies (libraries) used by the extension provided as a first argument.
### Copy files

The final extension layer is just a zip archive of files that overlay the PHP layer.
The extension and all related files that need to be installed should be placed `/opt`
directory in the final image.

```Dockerfile
RUN echo 'extension=/opt/bref-extra/pgsql.so' > /tmp/ext.ini
RUN echo 'extension=pgsql.so' > /tmp/ext.ini

FROM scratch

COPY --from=ext /tmp/pgsql.so /opt/bref-extra/pgsql.so
COPY --from=ext /tmp/pgsql.so /opt/bref/extensions/pgsql.so
COPY --from=ext /tmp/ext.ini /opt/bref/etc/php/conf.d/ext-pgsql.ini
COPY --from=ext /tmp/extension-libs /opt/lib
```

### Making a layer
Expand All @@ -96,7 +102,7 @@ $ make layers
Register the zip file generated above to AWS as Lambda Layer. It also able to add from AWS console.

```bash
$ aws lambda publish-layer-version --layer-name pgsql-php-73 --zip-file fileb://./export/layer-pgsql-php-73.zip
$ aws lambda publish-layer-version --layer-name pgsql-php-80 --zip-file fileb://./export/layer-pgsql-php-80.zip
```

# Test layers
Expand All @@ -118,10 +124,9 @@ $ composer init
$ composer require bref/bref
$ vendor/bin/bref init
What kind of lambda do you want to create? (you will be able to add more functions later by editing `serverless.yml`) [PHP function]:
[0] PHP function
[1] HTTP application
[2] Console application
> 1
[0] Web application
[1] PHP function
> 0
## Select suitable for check your extension.
```

Expand All @@ -134,7 +139,7 @@ provider:
name: aws
- region: us-east-1
+ region: <YOUR AWS REGION>
runtime: provided
runtime: provided.al2

plugins:
- ./vendor/bref/bref
Expand All @@ -145,33 +150,25 @@ functions:
description: ''
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
layers:
- ${bref:layer.php-73-fpm}
+ - arn:aws:lambda:<YOUR AWS REGION>:<YOUR AWS ID>:layer:pgsql-php-73:3
- ${bref:layer.php-80-fpm}
+ - arn:aws:lambda:<YOUR AWS REGION>:<YOUR AWS ID>:layer:pgsql-php-80:3

events:
- http: 'ANY /'
- http: 'ANY /{proxy+}'
- httpApi: '*'
```

Update `index.php` to be allowed you to check the extension.
Update `index.php` to check that the extension is automatically loaded and works.

```diff
<?php

- echo "Hello World";
+ #
+ # Add some check processing
+ # Check the extension works
+ #
```

Add a setting to load the extension.

```bash
$ mkdir -p php/conf.d
$ echo "extension=/opt/bref-extra/pgsql.so" > php/conf.d/pgsql.ini
```

Finally deploy and test this function.
Finally, deploy and test this function.

```bash
$ serverless deploy
Expand All @@ -188,15 +185,15 @@ In order to contribute, you should do a little more work.
```diff
### 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` |
| GMP | `${bref-extra:gmp-php-74}` | `extension=/opt/bref-extra/gmp.so` |
| Memcache | `${bref-extra:memcached-php-74}` | `extension=/opt/bref-extra/memcache.so` |
| Memcached | `${bref-extra:memcached-php-74}` | `extension=/opt/bref-extra/memcached.so` |
+| PostgreSQL | `${bref-extra:pgsql-php-74}` | `extension=/opt/bref-extra/pgsql.so` |
| Xdebug | `${bref-extra:xdebug-php-74}` | `zend_extension=/opt/bref-extra/xdebug.so` |
| Name | Serverless config (php 8.1) |
| ---- | ----------------------------|
| AMQP | `${bref-extra:amqp-php-81}` |
| Blackfire | `${bref-extra:blackfire-php-81}` |
| GMP | `${bref-extra:gmp-php-81}` |
| Memcache | `${bref-extra:memcached-php-81}` |
| Memcached | `${bref-extra:memcached-php-81}` |
+| PostgreSQL | `${bref-extra:pgsql-php-81}` |
| Xdebug | `${bref-extra:xdebug-php-81}` |

Note that the "Memcached" layer provides both extension for [Memcache](https://pecl.php.net/package/memcache) and [Memcached](https://pecl.php.net/package/memcached).
```
Expand Down
Loading

0 comments on commit 3a82859

Please sign in to comment.