Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ jobs:
- name: Test that layers can be exported
run: |
make layer-php-${{ matrix.php_version }}
make layer-php-${{ matrix.php_version }}-fpm
env:
CPU: ${{ matrix.cpu }}

- name: Test that the "console" layer can be exported
run: make layer-console
if: ${{ matrix.php_version == 80 }}
env:
CPU: ${{ matrix.cpu }}

Expand Down
23 changes: 3 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ docker-images-php-%:


# Build Lambda layers (zip files) *locally*
layers: layer-php-80 layer-php-81 layer-php-82 layer-php-83 layer-php-84 layer-php-80-fpm layer-php-81-fpm layer-php-82-fpm layer-php-83-fpm layer-php-84-fpm
# Build the console layer only once (x86 and single PHP version)
@if [ ${CPU} = "x86" ]; then \
$(MAKE) layer-console; \
fi
layer-console:
./utils/docker-zip-dir.sh bref/console-zip console
layers: layer-php-80 layer-php-81 layer-php-82 layer-php-83 layer-php-84
# This rule matches with a wildcard, for example `layer-php-80`.
# The `$*` variable will contained the matched part, in this case `php-80`.
layer-%:
Expand All @@ -58,15 +52,8 @@ layer-%:
# Uses the current AWS_PROFILE. Most users will not want to use this option
# as this will publish all layers to all regions + publish all Docker images.
upload-layers: upload-layers-php-80 upload-layers-php-81 upload-layers-php-82 upload-layers-php-83 upload-layers-php-84
# Upload the console layer only once (x86 and single PHP version)
@if [ ${CPU} = "x86" ]; then \
LAYER_NAME=console $(MAKE) -C ./utils/lambda-publish publish-parallel; \
fi
upload-layers-php-%:
# Upload the function layers to AWS
LAYER_NAME=${CPU_PREFIX}php-$* $(MAKE) -C ./utils/lambda-publish publish-parallel
# Upload the FPM layers to AWS
LAYER_NAME=${CPU_PREFIX}php-$*-fpm $(MAKE) -C ./utils/lambda-publish publish-parallel


# Publish Docker images to Docker Hub.
Expand All @@ -78,8 +65,7 @@ upload-to-docker-hub-php-%:

set -e ; \
for image in \
"bref/${CPU_PREFIX}php-$*" "bref/${CPU_PREFIX}php-$*-fpm" "bref/${CPU_PREFIX}php-$*-console" \
"bref/${CPU_PREFIX}build-php-$*" "bref/${CPU_PREFIX}php-$*-fpm-dev"; \
"bref/${CPU_PREFIX}php-$*" "bref/${CPU_PREFIX}build-php-$*" "bref/${CPU_PREFIX}php-$*-dev"; \
do \
docker tag $$image $$image:2 ; \
docker tag $$image $$image:${DOCKER_TAG} ; \
Expand All @@ -102,7 +88,4 @@ clean-%:
docker image rm --force bref/${CPU_PREFIX}build-php-$* \
bref/${CPU_PREFIX}php-$* \
bref/${CPU_PREFIX}php-$*-zip \
bref/${CPU_PREFIX}php-$*-fpm \
bref/${CPU_PREFIX}php-$*-fpm-zip \
bref/${CPU_PREFIX}php-$*-fpm-dev \
bref/${CPU_PREFIX}php-$*-console
bref/${CPU_PREFIX}php-$*-dev
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ Anything we want to make available in AWS Lambda is possible by preparing the ri
bref/ # custom Bref files
extensions/ # PHP extensions
...
php-fpm-runtime/ # the built-in FPM runtime
etc/php/conf.d/ # automatically loaded php.ini files
bref.ini
bootstrap.php # (for the function layer only)

bootstrap # entrypoint of the runtime

Expand Down
68 changes: 14 additions & 54 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group "default" {
targets = ["build-php", "php", "php-fpm", "console-zip", "console", "php-fpm-dev"]
targets = ["build-php", "php", "php-dev"]
}

variable "CPU" {
Expand All @@ -23,9 +23,9 @@ variable "PHP_COMPILATION_FLAGS" {

target "build-php" {
dockerfile = "php-${PHP_VERSION}/Dockerfile"
target = "build-environment"
tags = ["bref/${CPU_PREFIX}build-php-${PHP_VERSION}"]
args = {
target = "build-environment"
tags = ["bref/${CPU_PREFIX}build-php-${PHP_VERSION}"]
args = {
"IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}"
"PHP_COMPILATION_FLAGS" = "${PHP_COMPILATION_FLAGS}"
}
Expand All @@ -34,9 +34,9 @@ target "build-php" {

target "php" {
dockerfile = "php-${PHP_VERSION}/Dockerfile"
target = "function"
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}"]
args = {
target = "function"
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}"]
args = {
"IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}"
"PHP_COMPILATION_FLAGS" = "${PHP_COMPILATION_FLAGS}"
}
Expand All @@ -46,58 +46,18 @@ target "php" {
platforms = ["${DOCKER_PLATFORM}"]
}

target "php-fpm" {
target "php-dev" {
dockerfile = "php-${PHP_VERSION}/Dockerfile"
target = "fpm"
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm"]
args = {
target = "dev"
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-dev"]
args = {
"IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}"
"PHP_COMPILATION_FLAGS" = "${PHP_COMPILATION_FLAGS}"
}
contexts = {
"bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php"
"bref/${CPU_PREFIX}php-${PHP_VERSION}" = "target:php"
}
platforms = ["${DOCKER_PLATFORM}"]
}

target "console-zip" {
context = "layers/console"
target = "console-zip"
tags = ["bref/console-zip"]
args = {
PHP_VERSION = "${PHP_VERSION}"
CPU_PREFIX = "${CPU_PREFIX}"
}
platforms = ["${DOCKER_PLATFORM}"]
}

target "console" {
context = "layers/console"
target = "console"
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-console"]
args = {
PHP_VERSION = "${PHP_VERSION}"
CPU_PREFIX = "${CPU_PREFIX}"
}
contexts = {
"bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php"
"bref/${CPU_PREFIX}php-${PHP_VERSION}" = "target:php"
}
platforms = ["${DOCKER_PLATFORM}"]
}

target "php-fpm-dev" {
context = "layers/fpm-dev"
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm-dev"]
args = {
PHP_VERSION = "${PHP_VERSION}"
CPU_PREFIX = "${CPU_PREFIX}"
}
contexts = {
"bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php"
"bref/${CPU_PREFIX}php-${PHP_VERSION}" = "target:php"
"bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm" = "target:php-fpm"
"bref/local-api-gateway" = "docker-image://bref/local-api-gateway:latest"
"bref/${CPU_PREFIX}php-${PHP_VERSION}" = "target:php"
"bref/local-api-gateway" = "docker-image://bref/local-api-gateway:latest"
}
platforms = ["${DOCKER_PLATFORM}"]
}
8 changes: 7 additions & 1 deletion layers/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

$appRoot = getenv('LAMBDA_TASK_ROOT');
Expand All @@ -12,7 +13,12 @@

require $autoloadPath;

$runtimeClass = getenv('RUNTIME_CLASS');
// `RUNTIME_CLASS` is for backwards compatibility with Bref v2's environment variable
$runtimeClass = $_SERVER['BREF_RUNTIME'] ?? $_SERVER['RUNTIME_CLASS'];

if (empty($runtimeClass)) {
throw new RuntimeException('The environment variable `BREF_RUNTIME` is not set, are you trying to use Bref v2 with Bref v3 layers? Make sure to follow the Bref documentation to use the right layers for your current Bref version.');
}

if (! class_exists($runtimeClass)) {
throw new RuntimeException("Bref is not installed in your application (could not find the class \"$runtimeClass\" in Composer dependencies). Did you run \"composer require bref/bref\"?");
Expand Down
22 changes: 0 additions & 22 deletions layers/console/Dockerfile

This file was deleted.

3 changes: 0 additions & 3 deletions layers/console/README.md

This file was deleted.

27 changes: 0 additions & 27 deletions layers/console/bootstrap.sh

This file was deleted.

File renamed without changes.
45 changes: 0 additions & 45 deletions layers/fpm-dev/Dockerfile

This file was deleted.

27 changes: 0 additions & 27 deletions layers/fpm/bootstrap.sh

This file was deleted.

1 change: 1 addition & 0 deletions layers/fpm/bref.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
memory_limit=10240M
Comment thread
mnapoli marked this conversation as resolved.
Outdated

opcache.enable=1
opcache.enable_cli=1

; Skip this check to save a bit
opcache.validate_permission=0
Expand Down
27 changes: 0 additions & 27 deletions layers/function/bootstrap.sh

This file was deleted.

File renamed without changes.
14 changes: 12 additions & 2 deletions layers/function/bref.ini → layers/php.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; On the CLI we want errors to be sent to stdout -> those will end up in CloudWatch
display_errors=1
; We want errors to be sent to stderr -> those will end up in CloudWatch
; We don't want them on stdout because FPM would then send them to the browser
display_errors=stderr
Comment thread
mnapoli marked this conversation as resolved.
Outdated

; Since PHP 7.4 the default value is E_ALL
; We override it to set the recommended configuration value for production.
Expand Down Expand Up @@ -38,6 +39,15 @@ opcache.max_accelerated_files=10000
; See https://github.com/brefphp/bref/pull/291
variables_order="EGPCS"

; The lambda environment is not compatible with fastcgi_finish_request
; See https://github.com/brefphp/bref/issues/214
disable_functions=fastcgi_finish_request

; The total upload size limit is 6Mb, we override the defaults to match this limit
; API Gateway has a 10Mb limit, but Lambda's is 6Mb
post_max_size=6M
upload_max_filesize=6M

extension_dir=/opt/bref/extensions
; Extensions enabled by default
extension=pdo_mysql.so
Expand Down
Loading
Loading