|
2 | 2 | -include .env
|
3 | 3 | export # export all variables defined in .env
|
4 | 4 |
|
5 |
| -# - Build all layers |
6 |
| -# - Publish all Docker images to Docker Hub |
7 |
| -# - Publish all layers to AWS Lambda |
| 5 | +# Define all the environment variables depending on the CPU |
| 6 | +# Set CPU= (empty) to build for x86 |
| 7 | +# Set CPU=arm to build for ARM |
| 8 | +ifeq ($(CPU), arm) # if $CPU=="arm" |
| 9 | + $(info "⚠️ Building for ARM") # Print a message |
| 10 | + export CPU = arm |
| 11 | + export CPU_PREFIX = arm- |
| 12 | + export IMAGE_VERSION_SUFFIX = arm64 |
| 13 | + export DOCKER_PLATFORM = linux/arm64 |
| 14 | +else |
| 15 | + $(info "⚠️ Building for x86") # Print a message |
| 16 | + export CPU = x86 |
| 17 | + export CPU_PREFIX = |
| 18 | + export IMAGE_VERSION_SUFFIX = x86_64 |
| 19 | + export DOCKER_PLATFORM = linux/amd64 |
| 20 | +endif |
| 21 | + |
| 22 | +# By default, Docker images are built using `docker buildx bake` |
| 23 | +# But we use https://depot.dev in CI (super fast) by setting USE_DEPOT=1 |
| 24 | +ifeq ($(USE_DEPOT), 1) # if $USE_DEPOT=="1" |
| 25 | + $(info "⚠️ Building using depot.dev") # Print a message |
| 26 | + export BAKE_COMMAND = depot bake |
| 27 | +else |
| 28 | + export BAKE_COMMAND = docker buildx bake |
| 29 | +endif |
| 30 | + |
| 31 | + |
| 32 | +# Build all Docker images and layers *locally* |
| 33 | +# Use this to test your changes |
| 34 | +default: docker-images layers |
| 35 | + |
| 36 | + |
| 37 | +# Build Docker images *locally* |
| 38 | +docker-images: docker-images-php-80 docker-images-php-81 docker-images-php-82 |
| 39 | +docker-images-php-%: |
| 40 | + PHP_VERSION=$* ${BAKE_COMMAND} --load |
| 41 | + |
| 42 | + |
| 43 | +# Build Lambda layers (zip files) *locally* |
| 44 | +layers: layer-php-80 layer-php-81 layer-php-82 layer-php-80-fpm layer-php-81-fpm layer-php-82-fpm |
| 45 | + # Build the console layer only once (x86 and single PHP version) |
| 46 | + @if [ ${CPU} = "x86" ]; then \ |
| 47 | + ./utils/docker-zip-dir.sh bref/php-80-console-zip console; \ |
| 48 | + fi |
| 49 | +# This rule matches with a wildcard, for example `layer-php-80`. |
| 50 | +# The `$*` variable will contained the matched part, in this case `php-80`. |
| 51 | +layer-%: |
| 52 | + ./utils/docker-zip-dir.sh bref/${CPU_PREFIX}$* ${CPU_PREFIX}$* |
| 53 | + |
| 54 | + |
| 55 | +# Upload the layers to AWS Lambda |
8 | 56 | # Uses the current AWS_PROFILE. Most users will not want to use this option
|
9 | 57 | # as this will publish all layers to all regions + publish all Docker images.
|
10 |
| -everything: |
11 |
| - $(MAKE) -f cpu-x86.Makefile everything |
12 |
| - $(MAKE) -f cpu-arm.Makefile everything |
| 58 | +upload-layers: upload-layers-php-80 upload-layers-php-81 upload-layers-php-82 |
| 59 | + # Upload the console layer only once (x86 and single PHP version) |
| 60 | + @if [ ${CPU} = "x86" ]; then \ |
| 61 | + LAYER_NAME=console $(MAKE) -C ./utils/lambda-publish publish-parallel; \ |
| 62 | + fi |
| 63 | +upload-layers-php-%: |
| 64 | + # Upload the function layers to AWS |
| 65 | + LAYER_NAME=${CPU_PREFIX}php-$* $(MAKE) -C ./utils/lambda-publish publish-parallel |
| 66 | + # Upload the FPM layers to AWS |
| 67 | + LAYER_NAME=${CPU_PREFIX}php-$*-fpm $(MAKE) -C ./utils/lambda-publish publish-parallel |
13 | 68 |
|
14 |
| -# Build Docker images *locally* |
15 |
| -docker-images: |
16 |
| - $(MAKE) -f cpu-x86.Makefile docker-images |
17 |
| - $(MAKE) -f cpu-arm.Makefile docker-images |
18 |
| - |
19 |
| -# Build Lambda layers (zip files) *locally* (will also build Docker images) |
20 |
| -layers: |
21 |
| - $(MAKE) -f cpu-x86.Makefile layers |
22 |
| - $(MAKE) -f cpu-arm.Makefile layers |
23 |
| - |
24 |
| -# Upload the layers to AWS Lambda (will also build Docker images and layers) |
25 |
| -upload-layers: |
26 |
| - $(MAKE) -f cpu-x86.Makefile upload-layers |
27 |
| - $(MAKE) -f cpu-arm.Makefile upload-layers |
28 |
| - |
29 |
| -# Build and publish Docker images to Docker Hub. |
30 |
| -# Only publishes the `latest` version. |
31 |
| -# This process is executed when a merge to `main` happens. |
32 |
| -# When a release tag is created, GitHub Actions |
33 |
| -# will download the latest images, tag them with the version number |
34 |
| -# and re-upload them with the right tag. |
35 |
| -upload-to-docker-hub: |
36 |
| - $(MAKE) -f cpu-x86.Makefile upload-to-docker-hub |
37 |
| - $(MAKE) -f cpu-arm.Makefile upload-to-docker-hub |
38 |
| - |
39 |
| -test: |
40 |
| - $(MAKE) -f cpu-x86.Makefile test |
41 |
| - $(MAKE) -f cpu-arm.Makefile test |
42 |
| - |
43 |
| -clean: |
44 |
| - $(MAKE) -f cpu-x86.Makefile clean |
45 |
| - $(MAKE) -f cpu-arm.Makefile clean |
46 |
| - |
47 |
| -.PHONY: layers |
| 69 | + |
| 70 | +# Publish Docker images to Docker Hub. |
| 71 | +upload-to-docker-hub: upload-to-docker-hub-php-80 upload-to-docker-hub-php-81 upload-to-docker-hub-php-82 |
| 72 | +upload-to-docker-hub-php-%: |
| 73 | + # While in beta we tag and push the `:2` version, later we'll push `:latest` as well |
| 74 | + for image in \ |
| 75 | + "bref/${CPU_PREFIX}php-$*" "bref/${CPU_PREFIX}php-$*-fpm" "bref/${CPU_PREFIX}php-$*-console" \ |
| 76 | + "bref/${CPU_PREFIX}build-php-$*" "bref/${CPU_PREFIX}php-$*-fpm-dev"; \ |
| 77 | + do \ |
| 78 | + docker tag $$image $$image:2 ; \ |
| 79 | + docker push $$image:2 ; \ |
| 80 | + done |
| 81 | + # TODO: when v2 becomes "latest", we should also push "latest" tags |
| 82 | + # We could actually use `docker push --all-tags` at the end probably? |
| 83 | + |
| 84 | + |
| 85 | +test: test-80 test-81 test-82 |
| 86 | +test-%: |
| 87 | + cd tests && $(MAKE) test-$* |
| 88 | + |
| 89 | + |
| 90 | +clean: clean-80 clean-81 clean-82 |
| 91 | + # Clear the build cache, else all images will be rebuilt using cached layers |
| 92 | + docker builder prune |
| 93 | + # Remove zip files |
| 94 | + rm -f output/${CPU_PREFIX}*.zip |
| 95 | +clean-%: |
| 96 | + # Clean Docker images to force rebuilding them |
| 97 | + docker image rm --force bref/${CPU_PREFIX}build-php-$* \ |
| 98 | + bref/${CPU_PREFIX}php-$* \ |
| 99 | + bref/${CPU_PREFIX}php-$*-zip \ |
| 100 | + bref/${CPU_PREFIX}php-$*-fpm \ |
| 101 | + bref/${CPU_PREFIX}php-$*-fpm-zip \ |
| 102 | + bref/${CPU_PREFIX}php-$*-fpm-dev \ |
| 103 | + bref/${CPU_PREFIX}php-$*-console |
0 commit comments