Skip to content

Revert to compiling PHP from source #43

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

Merged
merged 98 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
f730f66
Revert to Bref's v1 compilation scripts
mnapoli Jan 13, 2023
a6e0e6d
Improve comments and formatting of the file
mnapoli Jan 13, 2023
8236185
Remove instruction that had no impact
mnapoli Jan 13, 2023
387d930
Compile by default in parallel
mnapoli Jan 13, 2023
66b04de
Compile by default in parallel
mnapoli Jan 13, 2023
07a30df
Simplify the scripts by removing useless `set -xe`
mnapoli Jan 13, 2023
c968120
Move the compilation of Oniguruma to base-devel
mnapoli Jan 13, 2023
beddb73
Add a test to check that HTTP2 is supported with curl
mnapoli Jan 13, 2023
0446dfd
Compile PHP 8.1 from source
mnapoli Jan 13, 2023
b16c6b4
Fix incorrect mention of libedit
mnapoli Jan 13, 2023
b077406
We compile PHP with the "readline" sys lib instead of libedit
mnapoli Jan 13, 2023
74b7da4
Add a script that automatically detects and copies the system libraries
mnapoli Jan 13, 2023
48e031f
Automatically detect and copy the system libraries instead of manuall…
mnapoli Jan 13, 2023
c3180e3
Update the list of PHP extensions to remove the (now) built-in extens…
mnapoli Jan 13, 2023
41e5d34
Apply the new build system (compile PHP from source) to PHP 8.0 and 8.2
mnapoli Jan 13, 2023
955df37
Get rid of PHP_INI_SCAN_DIR
mnapoli Jan 13, 2023
7a96817
Use the new `COPY --link` syntax to accelerate builds
mnapoli Jan 13, 2023
adb5504
Package PHP-FPM from the compiled binary
mnapoli Jan 13, 2023
d9f6867
Set up Docker buildx to use BuildKit features
mnapoli Jan 13, 2023
d943ae2
Set up Docker buildx to use BuildKit features
mnapoli Jan 13, 2023
555d39b
Set up Docker buildx to use BuildKit features
mnapoli Jan 13, 2023
effc939
Switch to Docker Compose v2
mnapoli Jan 13, 2023
f3e2345
Simplify the CI config
mnapoli Jan 13, 2023
cdad0bd
Build base-devel images in GitHub CI
mnapoli Jan 13, 2023
1b2517c
Bugfix
mnapoli Jan 13, 2023
e0eb48c
Always build base-devel
mnapoli Jan 13, 2023
73486ee
Fix Docker build
mnapoli Jan 13, 2023
8184f34
Fix Docker build
mnapoli Jan 13, 2023
4c5a8a5
Fix Docker build
mnapoli Jan 13, 2023
a088947
Build images in CI
mnapoli Jan 14, 2023
f209c33
Revert "Build images in CI"
mnapoli Jan 14, 2023
6ebeabb
Debug CI
mnapoli Jan 14, 2023
a9df041
Attempt at using `docker bake`
mnapoli Jan 14, 2023
7cc04b1
Build multiple PHP versions in GitHub Actions
mnapoli Jan 14, 2023
86b987b
Improve CI and Docker caching
mnapoli Jan 14, 2023
cdc0859
Improve CI and Docker caching
mnapoli Jan 14, 2023
99360ab
Replace more Docker Compose with `docker run`
mnapoli Jan 14, 2023
c128690
Build more images in GitHub Actions
mnapoli Jan 14, 2023
6ccc6a3
Build more images in GitHub Actions
mnapoli Jan 14, 2023
d4ade8e
Build more images in GitHub Actions
mnapoli Jan 14, 2023
16db22e
Build more images in GitHub Actions
mnapoli Jan 14, 2023
fdf48da
Remove more Docker Compose because of its incompatibility with bake
mnapoli Jan 15, 2023
67d13bf
Debug CI
mnapoli Jan 15, 2023
e9ca837
Debug CI
mnapoli Jan 15, 2023
ba21352
Fix tests
mnapoli Jan 15, 2023
fe64ad2
Build all PHP versions to get all failure information
mnapoli Jan 15, 2023
3692e38
Debug CI
mnapoli Jan 16, 2023
0ea0116
CI
mnapoli Jan 16, 2023
a8cdbcc
Fix image name
mnapoli Jan 16, 2023
ff880a0
Adopt bake for local build
mnapoli Jan 16, 2023
8c666c7
Document not to enable [the experimental Rosetta emulation](https://d…
mnapoli Jan 16, 2023
897a534
Cleanup CI debug line
mnapoli Jan 16, 2023
fab1937
Get rid of `docker compose` for exporting zip layers
mnapoli Jan 16, 2023
47c21ec
Fix the zip script
mnapoli Jan 16, 2023
fd777f9
Locally build all images
mnapoli Jan 16, 2023
c33d364
Too many system libraries were copied in layers
mnapoli Jan 16, 2023
e1e73f3
Improve code formatting
mnapoli Jan 16, 2023
8ddb755
Do not re-build Docker images when building layer zip files
mnapoli Jan 16, 2023
c385bd4
Build ARM layers by compiling PHP
mnapoli Jan 16, 2023
b893e3f
Download zlib over HTTPS
mnapoli Jan 16, 2023
1c70d43
Use the system zlib instead of compiling it on ARM
mnapoli Jan 16, 2023
8619edc
Fix ARM layer names
mnapoli Jan 16, 2023
fe1d963
Debug CI
mnapoli Jan 17, 2023
b7d4e19
Disable Docker cache mode=max for some layers in GitHub Actions to av…
mnapoli Jan 17, 2023
dcc8614
Fix CPU_PREFIX in CI
mnapoli Jan 17, 2023
9ac2919
Disable Docker cache mode=max for some layers in GitHub Actions to av…
mnapoli Jan 17, 2023
4ba2634
Disable Docker cache mode=max entirely in GitHub Actions to avoid tim…
mnapoli Jan 17, 2023
dd2296b
Cleanup unused code
mnapoli Jan 17, 2023
3008e1f
Disable Docker cache for some images to avoid timeouts
mnapoli Jan 17, 2023
7c79643
Avoid compiling zlib if we can
mnapoli Jan 18, 2023
5f16d76
Remove useless flag
mnapoli Jan 18, 2023
e071287
Merge ini files because we have fewer extensions to load now
mnapoli Jan 18, 2023
58c1bb5
Remove useless file copies
mnapoli Jan 18, 2023
7fcc487
We don't publish base-devel images separately (every night) as they c…
mnapoli Jan 18, 2023
30d38c3
Cache fpm-internal-src once for all PHP versions and CPU architectures
mnapoli Jan 21, 2023
1961621
Simplify the base-devel image by merging into a single Dockerfile
mnapoli Jan 22, 2023
807f2b4
Cleanup useless file
mnapoli Jan 22, 2023
0501e0d
Simplify Dockerfiles by merging ARM and x86 together
mnapoli Jan 22, 2023
a7da2b4
Try using Depot
mnapoli Jan 22, 2023
33609e6
Merge the base-devel image into PHP Dockerfiles
mnapoli Jan 22, 2023
df928ee
Inline the `bref/fpm-internal-src` image into PHP Dockerfiles
mnapoli Jan 23, 2023
f67bc6c
Use the new `depot bake` command
mnapoli Jan 23, 2023
61de798
Explicitly set the Docker platform in tests to fix the CI
mnapoli Jan 23, 2023
7ac54fa
Fix Docker platform
mnapoli Jan 23, 2023
fb81096
Allow debugging in CI
mnapoli Jan 23, 2023
78fe749
Simplify the GitHub Actions config
mnapoli Jan 23, 2023
c16205a
Try forcing the Depot platform to hopefully fix the CI
mnapoli Jan 28, 2023
82c1eee
CI
mnapoli Jan 28, 2023
e324c63
Cleanup previous changes that didn't help make the CI work
mnapoli Jan 28, 2023
5765841
Simplify CI
mnapoli Jan 28, 2023
d8f5ee1
Edit CI message
mnapoli Jan 28, 2023
20ad0e3
Update the documentation
mnapoli Jan 28, 2023
f0ecf71
Merge the Makefiles using variables
mnapoli Jan 28, 2023
6101ee2
Change CI name
mnapoli Jan 28, 2023
8db39ac
Upgrade PHP versions
mnapoli Jan 28, 2023
a30f3e0
Merge pull request #44 from brefphp/depot
mnapoli Jan 28, 2023
4c20d20
Cleanup the utils/lib-copy script
mnapoli Jan 29, 2023
287cf44
Fixup
mnapoli Jan 29, 2023
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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
aws/
output/
tests/
utils/
.env
.env.example
.gitignore
Expand Down
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
# Limit the parallelization of layer publication.
# Default is 7, we recommend a lower number when publishing from a laptop.
MAX_PARALLEL_PUBLISH=3

# In the CI and on local machines in the core team we build using https://depot.dev
# as it is much faster to build cross-platform images.
# Do not uncomment this line, unless you have a depot.dev account.
#USE_DEPOT=1
26 changes: 0 additions & 26 deletions .github/workflows/release-base-devel-image.yml

This file was deleted.

73 changes: 40 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,64 @@ permissions:
contents: read # This is required for actions/checkout

jobs:
release-x86:
name: Publish x86 layers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::534081306603:role/bref-layer-publisher-github-actions
role-session-name: bref-layer-publisher-github-actions
aws-region: us-east-1
- name: Configure Docker Hub credentials
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- run: make -f cpu-x86.Makefile layers
- run: make -f cpu-x86.Makefile test
- run: make -f cpu-x86.Makefile upload-layers
- run: make -f cpu-x86.Makefile upload-to-docker-hub

release-arm:
name: Publish ARM layers
release:
name: Publish ${{ matrix.cpu }} layers
runs-on: ubuntu-latest
strategy:
matrix:
cpu:
- x86
- arm
steps:
- uses: actions/checkout@v3

# 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)
uses: docker/setup-qemu-action@v2

- uses: depot/setup-action@v1

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::534081306603:role/bref-layer-publisher-github-actions
role-session-name: bref-layer-publisher-github-actions
aws-region: us-east-1

- name: Configure Docker Hub credentials
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# See https://stackoverflow.com/questions/70312490/github-actions-runner-environment-doesnt-build-for-arm-images
- name: Set up QEMU to build ARM images
uses: docker/setup-qemu-action@v2
- name: Set up Docker buildx to build ARM images
uses: docker/setup-buildx-action@v2
- run: make -f cpu-arm.Makefile layers
- run: make -f cpu-arm.Makefile test
- run: make -f cpu-arm.Makefile upload-layers
- run: make -f cpu-arm.Makefile upload-to-docker-hub

- name: Build Docker images
run: make docker-images
env:
CPU: ${{ matrix.cpu }}
USE_DEPOT: 1
DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }}

- run: make layers
env:
CPU: ${{ matrix.cpu }}

- run: make test
env:
CPU: ${{ matrix.cpu }}

- run: make upload-layers
env:
CPU: ${{ matrix.cpu }}

- run: make upload-to-docker-hub
env:
CPU: ${{ matrix.cpu }}

update-layer-versions:
name: Update layer versions in brefphp/bref
runs-on: ubuntu-latest
needs: [ release-x86, release-arm ]
needs: [ release ]
steps:
- name: Trigger layer update in brefphp/bref
uses: actions/github-script@v6
Expand All @@ -82,7 +89,7 @@ jobs:
update-layer-js-versions:
name: Update layer versions in brefphp/layers.js
runs-on: ubuntu-latest
needs: [ release-x86, release-arm ]
needs: [ release ]
steps:
- name: Trigger release in brefphp/layers.js
uses: actions/github-script@v6
Expand Down
48 changes: 34 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,43 @@ on:
branches: [ '*' ]

jobs:
tests-x86:
name: Build x86 images, layers, and run tests
tests:
name: Build and tests PHP ${{ matrix.php_version }}, ${{ matrix.cpu }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cpu:
- x86
- arm
php_version:
- 80
- 81
- 82
steps:
- uses: actions/checkout@v3
- run: make -f cpu-x86.Makefile layers
- run: make -f cpu-x86.Makefile test

tests-arm:
name: Build ARM images, layers, and run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# See https://stackoverflow.com/questions/70312490/github-actions-runner-environment-doesnt-build-for-arm-images
- name: Set up QEMU to build ARM images
- name: Set up QEMU to run ARM images (that were built with Depot)
uses: docker/setup-qemu-action@v2
- name: Set up Docker buildx to build ARM images
uses: docker/setup-buildx-action@v2
- run: make -f cpu-arm.Makefile layers
- run: make -f cpu-arm.Makefile test

- uses: depot/setup-action@v1

- name: Build Docker images
run: make docker-images-php-${{ matrix.php_version }}
env:
CPU: ${{ matrix.cpu }}
USE_DEPOT: 1
DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }}

- 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: Run tests
run: make test-${{ matrix.php_version }}
env:
CPU: ${{ matrix.cpu }}
136 changes: 96 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,102 @@
-include .env
export # export all variables defined in .env

# - Build all layers
# - Publish all Docker images to Docker Hub
# - Publish all layers to AWS Lambda
# Define all the environment variables depending on the CPU
# Set CPU= (empty) to build for x86
# Set CPU=arm to build for ARM
ifeq ($(CPU), arm) # if $CPU=="arm"
$(info "⚠️ Building for ARM") # Print a message
export CPU = arm
export CPU_PREFIX = arm-
export IMAGE_VERSION_SUFFIX = arm64
export DOCKER_PLATFORM = linux/arm64
else
$(info "⚠️ Building for x86") # Print a message
export CPU = x86
export CPU_PREFIX =
export IMAGE_VERSION_SUFFIX = x86_64
export DOCKER_PLATFORM = linux/amd64
endif

# By default, Docker images are built using `docker buildx bake`
# But we use https://depot.dev in CI (super fast) by setting USE_DEPOT=1
ifeq ($(USE_DEPOT), 1) # if $USE_DEPOT=="1"
$(info "⚠️ Building using depot.dev") # Print a message
export BAKE_COMMAND = depot bake
else
export BAKE_COMMAND = docker buildx bake
endif


# Build all Docker images and layers *locally*
# Use this to test your changes
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-%:
PHP_VERSION=$* ${BAKE_COMMAND} --load


# Build Lambda layers (zip files) *locally*
layers: layer-php-80 layer-php-81 layer-php-82 layer-php-80-fpm layer-php-81-fpm layer-php-82-fpm
# Build the console layer only once (x86 and single PHP version)
@if [ ${CPU} = "x86" ]; then \
./utils/docker-zip-dir.sh bref/php-80-console-zip console; \
fi
# This rule matches with a wildcard, for example `layer-php-80`.
# The `$*` variable will contained the matched part, in this case `php-80`.
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.
everything:
$(MAKE) -f cpu-x86.Makefile everything
$(MAKE) -f cpu-arm.Makefile everything
upload-layers: upload-layers-php-80 upload-layers-php-81 upload-layers-php-82
# 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

# Build Docker images *locally*
docker-images:
$(MAKE) -f cpu-x86.Makefile docker-images
$(MAKE) -f cpu-arm.Makefile docker-images

# Build Lambda layers (zip files) *locally* (will also build Docker images)
layers:
$(MAKE) -f cpu-x86.Makefile layers
$(MAKE) -f cpu-arm.Makefile layers

# Upload the layers to AWS Lambda (will also build Docker images and layers)
upload-layers:
$(MAKE) -f cpu-x86.Makefile upload-layers
$(MAKE) -f cpu-arm.Makefile upload-layers

# Build and publish Docker images to Docker Hub.
# Only publishes the `latest` version.
# This process is executed when a merge to `main` happens.
# When a release tag is created, GitHub Actions
# will download the latest images, tag them with the version number
# and re-upload them with the right tag.
upload-to-docker-hub:
$(MAKE) -f cpu-x86.Makefile upload-to-docker-hub
$(MAKE) -f cpu-arm.Makefile upload-to-docker-hub

test:
$(MAKE) -f cpu-x86.Makefile test
$(MAKE) -f cpu-arm.Makefile test

clean:
$(MAKE) -f cpu-x86.Makefile clean
$(MAKE) -f cpu-arm.Makefile clean

.PHONY: layers

# 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-%:
# While in beta we tag and push the `:2` version, later we'll push `:latest` as well
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"; \
do \
docker tag $$image $$image:2 ; \
docker push $$image:2 ; \
done
# TODO: when v2 becomes "latest", we should also push "latest" tags
# We could actually use `docker push --all-tags` at the end probably?


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


clean: clean-80 clean-81 clean-82
# Clear the build cache, else all images will be rebuilt using cached layers
docker builder prune
# Remove zip files
rm -f output/${CPU_PREFIX}*.zip
clean-%:
# Clean Docker images to force rebuilding them
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
Loading