Skip to content

Bref v3 #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
16 changes: 12 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ jobs:

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=${GITHUB_REF#refs/heads/}
else
VERSION=$GITHUB_REF
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

# See https://stackoverflow.com/questions/70312490/github-actions-runner-environment-doesnt-build-for-arm-images
- name: Set up QEMU to run ARM images (that were built with Depot)
Expand All @@ -39,7 +47,7 @@ jobs:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::534081306603:role/bref-layer-publisher-github-actions
role-to-assume: arn:aws:iam::873528684822:role/bref-layer-publisher-github-actions
role-session-name: bref-layer-publisher-github-actions
aws-region: us-east-1

Expand Down Expand Up @@ -86,7 +94,7 @@ jobs:
owner: 'brefphp',
repo: 'bref',
workflow_id: 'update-layer-versions.yml',
ref: 'master',
ref: 'v3',
inputs: {
release_url: '${{ github.event.release.url }}',
release_html_url: '${{ github.event.release.html_url }}',
Expand All @@ -108,5 +116,5 @@ jobs:
owner: 'brefphp',
repo: 'layers.js',
workflow_id: 'release.yml',
ref: 'main'
ref: 'v3'
})
9 changes: 1 addition & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
script: |
const matrix = {
cpu: ['x86', 'arm'],
php_version: ['80', '81', '82', '83', '84'],
php_version: ['82', '83', '84'],
}

// If this is a third-party pull request, skip ARM builds
Expand Down 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
42 changes: 12 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,66 +35,51 @@ default: docker-images layers


# Build Docker images *locally*
docker-images: docker-images-php-80 docker-images-php-81 docker-images-php-82 docker-images-php-83 docker-images-php-84
docker-images: docker-images-php-82 docker-images-php-83 docker-images-php-84
docker-images-php-%:
PHP_VERSION=$* ${BAKE_COMMAND} --load


# 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
# This rule matches with a wildcard, for example `layer-php-80`.
# The `$*` variable will contained the matched part, in this case `php-80`.
layers: layer-php-82 layer-php-83 layer-php-84
# This rule matches with a wildcard, for example `layer-php-84`.
# The `$*` variable will contained the matched part, in this case `php-84`.
layer-%:
./utils/docker-zip-dir.sh bref/${CPU_PREFIX}$* ${CPU_PREFIX}$*


# Upload the layers to AWS Lambda
# 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: upload-layers-php-82 upload-layers-php-83 upload-layers-php-84
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.
upload-to-docker-hub: upload-to-docker-hub-php-80 upload-to-docker-hub-php-81 upload-to-docker-hub-php-82 upload-to-docker-hub-php-83 upload-to-docker-hub-php-84
upload-to-docker-hub: upload-to-docker-hub-php-82 upload-to-docker-hub-php-83 upload-to-docker-hub-php-84
upload-to-docker-hub-php-%:
# Make sure we have defined the docker tag
(test $(DOCKER_TAG)) && echo "Tagging images with \"${DOCKER_TAG}\"" || echo "You have to define environment variable DOCKER_TAG"
test $(DOCKER_TAG)

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:3 ; \
docker tag $$image $$image:${DOCKER_TAG} ; \
docker push $$image:2 ; \
docker push $$image:3 ; \
docker push $$image:${DOCKER_TAG} ; \
docker push $$image:latest ; \
done


test: test-80 test-81 test-82 test-83 test-84
test: test-82 test-83 test-84
test-%:
cd tests && $(MAKE) test-$*


clean: clean-80 clean-81 clean-82 clean-83 clean-84
clean: clean-82 clean-83 clean-84
# Clear the build cache, else all images will be rebuilt using cached layers
docker builder prune
# Remove zip files
Expand All @@ -104,7 +89,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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The published Lambda layers will be public (they are readonly anyway). You can f
If you ever need to check out the content of a layer, you can start a `bash` terminal inside the Docker image:

```sh
docker run --rm -it --entrypoint=bash bref/php-80
docker run --rm -it --entrypoint=bash bref/php-84
```

> **Note:**
Expand Down 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
70 changes: 15 additions & 55 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 @@ -9,7 +9,7 @@ variable "CPU_PREFIX" {
default = ""
}
variable "PHP_VERSION" {
default = "80"
default = "84"
}
variable "IMAGE_VERSION_SUFFIX" {
default = "x86_64"
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}"]
}
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.

45 changes: 0 additions & 45 deletions layers/fpm-dev/Dockerfile

This file was deleted.

Loading