Skip to content

Commit 74cbbb4

Browse files
authored
Merge pull request #65 from brefphp/merge-docker-images
2 parents 92a435e + 869c676 commit 74cbbb4

File tree

6 files changed

+47
-50
lines changed

6 files changed

+47
-50
lines changed

Makefile

+10-10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ layer-console:
5151
# This rule matches with a wildcard, for example `layer-php-80`.
5252
# The `$*` variable will contained the matched part, in this case `php-80`.
5353
layer-%:
54-
./utils/docker-zip-dir.sh bref/${CPU_PREFIX}$* ${CPU_PREFIX}$*
54+
./utils/docker-zip-dir.sh bref/$* $*
5555

5656

5757
# 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
7474
upload-to-docker-hub-php-%:
7575
# While in beta we tag and push the `:2` version, later we'll push `:latest` as well
7676
for image in \
77-
"bref/${CPU_PREFIX}php-$*" "bref/${CPU_PREFIX}php-$*-fpm" "bref/${CPU_PREFIX}php-$*-console" \
78-
"bref/${CPU_PREFIX}build-php-$*" "bref/${CPU_PREFIX}php-$*-fpm-dev"; \
77+
"bref/php-$*" "bref/php-$*-fpm" "bref/php-$*-console" \
78+
"bref/build-php-$*" "bref/php-$*-fpm-dev"; \
7979
do \
8080
docker tag $$image $$image:2 ; \
8181
docker push $$image:2 ; \
@@ -96,10 +96,10 @@ clean: clean-80 clean-81 clean-82
9696
rm -f output/${CPU_PREFIX}*.zip
9797
clean-%:
9898
# Clean Docker images to force rebuilding them
99-
docker image rm --force bref/${CPU_PREFIX}build-php-$* \
100-
bref/${CPU_PREFIX}php-$* \
101-
bref/${CPU_PREFIX}php-$*-zip \
102-
bref/${CPU_PREFIX}php-$*-fpm \
103-
bref/${CPU_PREFIX}php-$*-fpm-zip \
104-
bref/${CPU_PREFIX}php-$*-fpm-dev \
105-
bref/${CPU_PREFIX}php-$*-console
99+
docker image rm --force bref/build-php-$* \
100+
bref/php-$* \
101+
bref/php-$*-zip \
102+
bref/php-$*-fpm \
103+
bref/php-$*-fpm-zip \
104+
bref/php-$*-fpm-dev \
105+
bref/php-$*-console

docker-bake.hcl

+14-19
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ group "default" {
55
variable "CPU" {
66
default = "x86"
77
}
8-
variable "CPU_PREFIX" {
9-
default = ""
10-
}
118
variable "PHP_VERSION" {
129
default = "80"
1310
}
@@ -21,7 +18,7 @@ variable "DOCKER_PLATFORM" {
2118
target "build-php" {
2219
dockerfile = "php-${PHP_VERSION}/Dockerfile"
2320
target = "build-environment"
24-
tags = ["bref/${CPU_PREFIX}build-php-${PHP_VERSION}"]
21+
tags = ["bref/build-php-${PHP_VERSION}"]
2522
args = {
2623
"CPU" = "${CPU}"
2724
"IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}"
@@ -32,28 +29,28 @@ target "build-php" {
3229
target "php" {
3330
dockerfile = "php-${PHP_VERSION}/Dockerfile"
3431
target = "function"
35-
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}"]
32+
tags = ["bref/php-${PHP_VERSION}"]
3633
args = {
3734
"CPU" = "${CPU}"
3835
"IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}"
3936
}
4037
contexts = {
41-
"bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php"
38+
"bref/build-php-${PHP_VERSION}" = "target:build-php"
4239
}
4340
platforms = ["${DOCKER_PLATFORM}"]
4441
}
4542

4643
target "php-fpm" {
4744
dockerfile = "php-${PHP_VERSION}/Dockerfile"
4845
target = "fpm"
49-
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm"]
46+
tags = ["bref/php-${PHP_VERSION}-fpm"]
5047
args = {
5148
"CPU" = "${CPU}"
5249
"IMAGE_VERSION_SUFFIX" = "${IMAGE_VERSION_SUFFIX}"
5350
}
5451
contexts = {
55-
"bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php"
56-
"bref/${CPU_PREFIX}php-${PHP_VERSION}" = "target:php"
52+
"bref/build-php-${PHP_VERSION}" = "target:build-php"
53+
"bref/php-${PHP_VERSION}" = "target:php"
5754
}
5855
platforms = ["${DOCKER_PLATFORM}"]
5956
}
@@ -64,37 +61,35 @@ target "console-zip" {
6461
tags = ["bref/console-zip"]
6562
args = {
6663
PHP_VERSION = "${PHP_VERSION}"
67-
CPU_PREFIX = "${CPU_PREFIX}"
6864
}
6965
platforms = ["${DOCKER_PLATFORM}"]
7066
}
7167

7268
target "console" {
7369
context = "layers/console"
7470
target = "console"
75-
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-console"]
71+
tags = ["bref/php-${PHP_VERSION}-console"]
7672
args = {
7773
PHP_VERSION = "${PHP_VERSION}"
78-
CPU_PREFIX = "${CPU_PREFIX}"
7974
}
8075
contexts = {
81-
"bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php"
82-
"bref/${CPU_PREFIX}php-${PHP_VERSION}" = "target:php"
76+
"bref/build-php-${PHP_VERSION}" = "target:build-php"
77+
"bref/php-${PHP_VERSION}" = "target:php"
8378
}
8479
platforms = ["${DOCKER_PLATFORM}"]
8580
}
8681

8782
target "php-fpm-dev" {
8883
context = "layers/fpm-dev"
89-
tags = ["bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm-dev"]
84+
tags = ["bref/php-${PHP_VERSION}-fpm-dev"]
9085
args = {
9186
PHP_VERSION = "${PHP_VERSION}"
92-
CPU_PREFIX = "${CPU_PREFIX}"
87+
"CPU" = "${CPU}"
9388
}
9489
contexts = {
95-
"bref/${CPU_PREFIX}build-php-${PHP_VERSION}" = "target:build-php"
96-
"bref/${CPU_PREFIX}php-${PHP_VERSION}" = "target:php"
97-
"bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm" = "target:php-fpm"
90+
"bref/build-php-${PHP_VERSION}" = "target:build-php"
91+
"bref/php-${PHP_VERSION}" = "target:php"
92+
"bref/php-${PHP_VERSION}-fpm" = "target:php-fpm"
9893
"bref/local-api-gateway" = "docker-image://bref/local-api-gateway:latest"
9994
}
10095
platforms = ["${DOCKER_PLATFORM}"]

layers/console/Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# syntax = docker/dockerfile:1.4
22
ARG PHP_VERSION
3-
ARG CPU_PREFIX
43

54

65
# This image only contains what's going in the layer zip file,
@@ -15,7 +14,7 @@ COPY --link bootstrap.sh /var/runtime/bootstrap
1514

1615

1716
# This image is published to Docker Hub and replicates Lambda
18-
FROM bref/${CPU_PREFIX}php-$PHP_VERSION as console
17+
FROM bref/php-$PHP_VERSION as console
1918

2019
# Copy the console layer into /opt
2120
COPY --link --from=console-zip /opt /opt

layers/fpm-dev/Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# syntax = docker/dockerfile:1.4
2-
ARG CPU_PREFIX
2+
ARG CPU
33
ARG PHP_VERSION
44

55

6-
FROM bref/${CPU_PREFIX}build-php-$PHP_VERSION as build_extensions
6+
FROM bref/build-php-$PHP_VERSION as build_extensions
77

88
ARG PHP_VERSION
99

@@ -16,11 +16,11 @@ RUN cp $(php -r "echo ini_get('extension_dir');")/xdebug.so /opt/bref/extensions
1616
# Install Blackfire
1717
# 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
1818
ARG BLACKFIRE_VERSION=1.86.1
19-
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
20-
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
19+
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
20+
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
2121

2222

23-
FROM bref/${CPU_PREFIX}php-${PHP_VERSION}-fpm
23+
FROM bref/php-${PHP_VERSION}-fpm
2424

2525
COPY --link --from=build_extensions /opt /opt
2626
COPY --link bref-entrypoint.sh /

tests/Makefile

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@ test: test-80 test-81 test-82
55
# This rule matches with a wildcard, for example `test-80`.
66
# The `$*` variable will contained the matched part, in this case `80`.
77
test-%: vendor
8-
docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/${CPU_PREFIX}php-$* \
8+
docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/php-$* \
99
test_1_binary.php $*
1010

11-
docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/${CPU_PREFIX}php-$* \
11+
docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php bref/php-$* \
1212
test_2_extensions.php
1313

1414
docker run --platform=${DOCKER_PLATFORM} --rm -v=$(PWD):/var/task:ro --entrypoint=php \
15-
-e PHP_INI_SCAN_DIR="/opt/bref/etc/php/conf.d/:/var/task/" bref/${CPU_PREFIX}php-$* \
15+
-e PHP_INI_SCAN_DIR="/opt/bref/etc/php/conf.d/:/var/task/" bref/php-$* \
1616
test_3_manual_enabling_extensions.php
1717

1818
# Test function handler
1919
docker stop test-${CPU_PREFIX}php-$* 2> /dev/null || true # silence errors
2020
docker run --platform=${DOCKER_PLATFORM} --rm --detach -v=$(PWD):/var/task:ro --name test-${CPU_PREFIX}php-$* \
21-
bref/${CPU_PREFIX}php-$* test_4_function_handler.php
21+
bref/php-$* test_4_function_handler.php
2222
docker exec test-${CPU_PREFIX}php-$* php test_4_function_invocation.php \
2323
|| (docker logs test-${CPU_PREFIX}php-$* && exit 1)
2424
docker stop test-${CPU_PREFIX}php-$*
2525

2626
# Test FPM handler
2727
docker stop test-${CPU_PREFIX}php-$*-fpm 2> /dev/null || true # silence errors
2828
docker run --platform=${DOCKER_PLATFORM} --rm --detach -v=$(PWD):/var/task:ro --name test-${CPU_PREFIX}php-$*-fpm \
29-
bref/${CPU_PREFIX}php-$*-fpm test_5_fpm_handler.php
29+
bref/php-$*-fpm test_5_fpm_handler.php
3030
docker exec test-${CPU_PREFIX}php-$*-fpm php test_5_fpm_invocation.php \
3131
|| (docker logs test-${CPU_PREFIX}php-$*-fpm && exit 1) # print logs in case of failure
3232
docker stop test-${CPU_PREFIX}php-$*-fpm
3333

3434
# Test console handler
3535
docker stop test-${CPU_PREFIX}php-$*-console 2> /dev/null || true # silence errors
3636
docker run --platform=${DOCKER_PLATFORM} --rm --detach -v=$(PWD):/var/task:ro --name test-${CPU_PREFIX}php-$*-console \
37-
bref/${CPU_PREFIX}php-$*-console test_6_console_handler.php
37+
bref/php-$*-console test_6_console_handler.php
3838
docker exec test-${CPU_PREFIX}php-$*-console php test_6_console_invocation.php \
3939
|| (docker logs test-${CPU_PREFIX}php-$*-console && exit 1) # print logs in case of failure
4040
docker stop test-${CPU_PREFIX}php-$*-console
@@ -43,7 +43,7 @@ test-%: vendor
4343
docker stop test-${CPU_PREFIX}php-$*-test7 2> /dev/null || true # silence errors
4444
docker run --platform=${DOCKER_PLATFORM} --rm --detach -v=$(PWD):/var/task:ro --name test-${CPU_PREFIX}php-$*-test7 \
4545
-e PHP_INI_SCAN_DIR="/opt/bref/etc/php/conf.d/:/var/task/" \
46-
bref/${CPU_PREFIX}php-$* test_4_function_handler.php
46+
bref/php-$* test_4_function_handler.php
4747
docker exec test-${CPU_PREFIX}php-$*-test7 php test_7_custom_ini_scan_dir.php \
4848
|| (docker logs test-${CPU_PREFIX}php-$*-test7 && exit 1) # print logs in case of failure
4949
docker stop test-${CPU_PREFIX}php-$*-test7

utils/docker-zip-dir.sh

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
# Fail on error
44
set -e
55

6-
rm -f "output/$2.zip"
7-
rm -rf "output/$2"
8-
mkdir "output/$2"
6+
IMAGE_NAME="$1"
7+
LAYER_NAME="$2"
8+
9+
rm -f "output/$LAYER_NAME.zip"
10+
rm -rf "output/$LAYER_NAME"
11+
mkdir "output/$LAYER_NAME"
912

1013
# Remove any previously failed container if it exists
1114
docker rm -f bref-export-zip 2>/dev/null || true
1215

13-
docker create --name bref-export-zip "$1"
16+
docker create --name bref-export-zip --platform "$DOCKER_PLATFORM" "$IMAGE_NAME"
1417

15-
docker cp bref-export-zip:/opt/. "output/$2"
18+
docker cp bref-export-zip:/opt/. "output/$LAYER_NAME"
1619

17-
cd "output/$2"
20+
cd "output/$LAYER_NAME"
1821

19-
zip --quiet --recurse-paths "../$2.zip" .
22+
zip --quiet --recurse-paths "../$LAYER_NAME.zip" .
2023

2124
docker rm -f bref-export-zip

0 commit comments

Comments
 (0)