diff --git a/Makefile b/Makefile index 24b6fb90..387fdf2a 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ layer-console: # 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}$* + ./utils/docker-zip-dir.sh bref/$* $* # Upload the layers to AWS Lambda @@ -74,8 +74,8 @@ upload-to-docker-hub: upload-to-docker-hub-php-80 upload-to-docker-hub-php-81 up 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"; \ + "bref/php-$*" "bref/php-$*-fpm" "bref/php-$*-console" \ + "bref/build-php-$*" "bref/php-$*-fpm-dev"; \ do \ docker tag $$image $$image:2 ; \ docker push $$image:2 ; \ @@ -96,10 +96,10 @@ clean: clean-80 clean-81 clean-82 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 + docker image rm --force bref/build-php-$* \ + bref/php-$* \ + bref/php-$*-zip \ + bref/php-$*-fpm \ + bref/php-$*-fpm-zip \ + bref/php-$*-fpm-dev \ + bref/php-$*-console diff --git a/docker-bake.hcl b/docker-bake.hcl index e7969d87..c0e212cf 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -5,9 +5,6 @@ group "default" { variable "CPU" { default = "x86" } -variable "CPU_PREFIX" { - default = "" -} variable "PHP_VERSION" { default = "80" } @@ -21,7 +18,7 @@ variable "DOCKER_PLATFORM" { target "build-php" { dockerfile = "php-${PHP_VERSION}/Dockerfile" target = "build-environment" - tags = ["bref/${CPU_PREFIX}build-php-${PHP_VERSION}"] + tags = ["bref/build-php-${PHP_VERSION}"] args = { "CPU" = "${CPU}" "IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}" @@ -32,13 +29,13 @@ target "build-php" { target "php" { dockerfile = "php-${PHP_VERSION}/Dockerfile" target = "function" - tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}"] + tags = ["bref/php-${PHP_VERSION}"] args = { "CPU" = "${CPU}" "IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}" } contexts = { - "bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php" + "bref/build-php-${PHP_VERSION}" = "target:build-php" } platforms = ["${DOCKER_PLATFORM}"] } @@ -46,14 +43,14 @@ target "php" { target "php-fpm" { dockerfile = "php-${PHP_VERSION}/Dockerfile" target = "fpm" - tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm"] + tags = ["bref/php-${PHP_VERSION}-fpm"] args = { "CPU" = "${CPU}" "IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}" } contexts = { - "bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php" - "bref/${CPU_PREFIX}php-${PHP_VERSION}" = "target:php" + "bref/build-php-${PHP_VERSION}" = "target:build-php" + "bref/php-${PHP_VERSION}" = "target:php" } platforms = ["${DOCKER_PLATFORM}"] } @@ -64,7 +61,6 @@ target "console-zip" { tags = ["bref/console-zip"] args = { PHP_VERSION = "${PHP_VERSION}" - CPU_PREFIX = "${CPU_PREFIX}" } platforms = ["${DOCKER_PLATFORM}"] } @@ -72,29 +68,28 @@ target "console-zip" { target "console" { context = "layers/console" target = "console" - tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-console"] + tags = ["bref/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" + "bref/build-php-${PHP_VERSION}" = "target:build-php" + "bref/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"] + tags = ["bref/php-${PHP_VERSION}-fpm-dev"] args = { PHP_VERSION = "${PHP_VERSION}" - CPU_PREFIX = "${CPU_PREFIX}" + "CPU" = "${CPU}" } 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/build-php-${PHP_VERSION}" = "target:build-php" + "bref/php-${PHP_VERSION}" = "target:php" + "bref/php-${PHP_VERSION}-fpm" = "target:php-fpm" "bref/local-api-gateway" = "docker-image://bref/local-api-gateway:latest" } platforms = ["${DOCKER_PLATFORM}"] diff --git a/layers/console/Dockerfile b/layers/console/Dockerfile index cc542416..7c86ddee 100644 --- a/layers/console/Dockerfile +++ b/layers/console/Dockerfile @@ -1,6 +1,5 @@ # syntax = docker/dockerfile:1.4 ARG PHP_VERSION -ARG CPU_PREFIX # This image only contains what's going in the layer zip file, @@ -15,7 +14,7 @@ COPY --link bootstrap.sh /var/runtime/bootstrap # This image is published to Docker Hub and replicates Lambda -FROM bref/${CPU_PREFIX}php-$PHP_VERSION as console +FROM bref/php-$PHP_VERSION as console # Copy the console layer into /opt COPY --link --from=console-zip /opt /opt diff --git a/layers/fpm-dev/Dockerfile b/layers/fpm-dev/Dockerfile index 8d853960..353bb954 100644 --- a/layers/fpm-dev/Dockerfile +++ b/layers/fpm-dev/Dockerfile @@ -1,9 +1,9 @@ # syntax = docker/dockerfile:1.4 -ARG CPU_PREFIX +ARG CPU ARG PHP_VERSION -FROM bref/${CPU_PREFIX}build-php-$PHP_VERSION as build_extensions +FROM bref/build-php-$PHP_VERSION as build_extensions ARG PHP_VERSION @@ -16,11 +16,11 @@ RUN cp $(php -r "echo ini_get('extension_dir');")/xdebug.so /opt/bref/extensions # Install Blackfire # https://blackfire.io/docs/up-and-running/installation?action=install&mode=full&version=latest&mode=full&location=server&os=manual&language=php#install-the-php-probe ARG BLACKFIRE_VERSION=1.86.1 -RUN if [[ $CPU_PREFIX == "" ]]; then curl -A "Docker" -o /opt/bref/extensions/blackfire.so -L -s "https://packages.blackfire.io/binaries/blackfire-php/$BLACKFIRE_VERSION/blackfire-php-linux_amd64-php-"$PHP_VERSION".so"; fi -RUN if [[ $CPU_PREFIX == "arm-" ]]; then curl -A "Docker" -o /opt/bref/extensions/blackfire.so -L -s "https://packages.blackfire.io/binaries/blackfire-php/$BLACKFIRE_VERSION/blackfire-php-linux_arm64-php-"$PHP_VERSION".so"; fi +RUN if [[ $CPU == "x86" ]]; then curl -A "Docker" -o /opt/bref/extensions/blackfire.so -L -s "https://packages.blackfire.io/binaries/blackfire-php/$BLACKFIRE_VERSION/blackfire-php-linux_amd64-php-"$PHP_VERSION".so"; fi +RUN if [[ $CPU == "arm" ]]; then curl -A "Docker" -o /opt/bref/extensions/blackfire.so -L -s "https://packages.blackfire.io/binaries/blackfire-php/$BLACKFIRE_VERSION/blackfire-php-linux_arm64-php-"$PHP_VERSION".so"; fi -FROM bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm +FROM bref/php-${PHP_VERSION}-fpm COPY --link --from=build_extensions /opt /opt COPY --link bref-entrypoint.sh / diff --git a/tests/Makefile b/tests/Makefile index 8a5207dd..fd486731 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,20 +5,20 @@ test: test-80 test-81 test-82 # This rule matches with a wildcard, for example `test-80`. # The `$*` variable will contained the matched part, in this case `80`. test-%: vendor - docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/${CPU_PREFIX}php-$* \ + docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/php-$* \ test_1_binary.php $* - docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/${CPU_PREFIX}php-$* \ + docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/php-$* \ test_2_extensions.php docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php \ - -e PHP_INI_SCAN_DIR="/opt/bref/etc/php/conf.d/:/var/task/" bref/${CPU_PREFIX}php-$* \ + -e PHP_INI_SCAN_DIR="/opt/bref/etc/php/conf.d/:/var/task/" bref/php-$* \ test_3_manual_enabling_extensions.php # Test function handler docker stop test-${CPU_PREFIX}php-$* 2> /dev/null || true # silence errors docker run --platform=${DOCKER_PLATFORM} --rm --detach -v=$(PWD):/var/task:ro --name test-${CPU_PREFIX}php-$* \ - bref/${CPU_PREFIX}php-$* test_4_function_handler.php + bref/php-$* test_4_function_handler.php docker exec test-${CPU_PREFIX}php-$* php test_4_function_invocation.php \ || (docker logs test-${CPU_PREFIX}php-$* && exit 1) docker stop test-${CPU_PREFIX}php-$* @@ -26,7 +26,7 @@ test-%: vendor # Test FPM handler docker stop test-${CPU_PREFIX}php-$*-fpm 2> /dev/null || true # silence errors docker run --platform=${DOCKER_PLATFORM} --rm --detach -v=$(PWD):/var/task:ro --name test-${CPU_PREFIX}php-$*-fpm \ - bref/${CPU_PREFIX}php-$*-fpm test_5_fpm_handler.php + bref/php-$*-fpm test_5_fpm_handler.php docker exec test-${CPU_PREFIX}php-$*-fpm php test_5_fpm_invocation.php \ || (docker logs test-${CPU_PREFIX}php-$*-fpm && exit 1) # print logs in case of failure docker stop test-${CPU_PREFIX}php-$*-fpm @@ -34,7 +34,7 @@ test-%: vendor # Test console handler docker stop test-${CPU_PREFIX}php-$*-console 2> /dev/null || true # silence errors docker run --platform=${DOCKER_PLATFORM} --rm --detach -v=$(PWD):/var/task:ro --name test-${CPU_PREFIX}php-$*-console \ - bref/${CPU_PREFIX}php-$*-console test_6_console_handler.php + bref/php-$*-console test_6_console_handler.php docker exec test-${CPU_PREFIX}php-$*-console php test_6_console_invocation.php \ || (docker logs test-${CPU_PREFIX}php-$*-console && exit 1) # print logs in case of failure docker stop test-${CPU_PREFIX}php-$*-console @@ -43,7 +43,7 @@ test-%: vendor docker stop test-${CPU_PREFIX}php-$*-test7 2> /dev/null || true # silence errors docker run --platform=${DOCKER_PLATFORM} --rm --detach -v=$(PWD):/var/task:ro --name test-${CPU_PREFIX}php-$*-test7 \ -e PHP_INI_SCAN_DIR="/opt/bref/etc/php/conf.d/:/var/task/" \ - bref/${CPU_PREFIX}php-$* test_4_function_handler.php + bref/php-$* test_4_function_handler.php docker exec test-${CPU_PREFIX}php-$*-test7 php test_7_custom_ini_scan_dir.php \ || (docker logs test-${CPU_PREFIX}php-$*-test7 && exit 1) # print logs in case of failure docker stop test-${CPU_PREFIX}php-$*-test7 diff --git a/utils/docker-zip-dir.sh b/utils/docker-zip-dir.sh index 2403cb1e..8068cdd0 100755 --- a/utils/docker-zip-dir.sh +++ b/utils/docker-zip-dir.sh @@ -3,19 +3,22 @@ # Fail on error set -e -rm -f "output/$2.zip" -rm -rf "output/$2" -mkdir "output/$2" +IMAGE_NAME="$1" +LAYER_NAME="$2" + +rm -f "output/$LAYER_NAME.zip" +rm -rf "output/$LAYER_NAME" +mkdir "output/$LAYER_NAME" # Remove any previously failed container if it exists docker rm -f bref-export-zip 2>/dev/null || true -docker create --name bref-export-zip "$1" +docker create --name bref-export-zip --platform "$DOCKER_PLATFORM" "$IMAGE_NAME" -docker cp bref-export-zip:/opt/. "output/$2" +docker cp bref-export-zip:/opt/. "output/$LAYER_NAME" -cd "output/$2" +cd "output/$LAYER_NAME" -zip --quiet --recurse-paths "../$2.zip" . +zip --quiet --recurse-paths "../$LAYER_NAME.zip" . docker rm -f bref-export-zip