Skip to content
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

Updated for arm support #430

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
184 changes: 128 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,67 +1,122 @@
SHELL := /bin/bash
layer ?= *
cpu ?= x86
resolve_php_versions = $(or $(php_versions),`jq -r '.php | join(" ")' ${1}/config.json`)
makefile_path = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
get_cpu_types = `jq -r '.cpu | join(" ")' ${makefile_path}${1}/config.json`
resolve_cpu_types = $(or $(cpu),`jq -r '.cpu | join(" ")' ${makefile_path}${1}/config.json`)
resolve_tags = `./new-docker-tags.php $(DOCKER_TAG)`
BREF_VERSION = 2

define build_docker_image
docker build -t bref/${1}-php-${2} --build-arg PHP_VERSION=${2} --build-arg BREF_VERSION=${BREF_VERSION} ${DOCKER_BUILD_FLAGS} ${1}
docker build -t bref/${1}-${4}php-${2} --build-arg CPU_PREFIX=${3} --build-arg PHP_VERSION=${2} --build-arg BREF_VERSION=${BREF_VERSION} ${DOCKER_BUILD_FLAGS} ${1}
endef

docker-images:
if [ "${layer}" != "*" ]; then test -d layers/${layer}; fi
set -e; \
for dir in layers/${layer}; do \
for php_version in $(call resolve_php_versions,$${dir}); do \
echo "###############################################"; \
echo "###############################################"; \
echo "### Building $${dir} PHP$${php_version}"; \
echo "###"; \
$(call build_docker_image,$${dir},$${php_version}) ; \
echo ""; \
for cpu_type in $(call resolve_cpu_types,$${dir}); do \
if [ "${layer}" = "*" ] && [[ "$(call get_cpu_types,$${dir})" != *"$${cpu_type}"* ]]; then \
echo "###############################################"; \
echo "️! Skip - $${dir} no $${cpu_type} support"; \
echo ""; \
break ; \
fi; \
for php_version in $(call resolve_php_versions,$${dir}); do \
if [[ "$${cpu_type}" = "arm" ]] ; then \
cpu_prefix="arm-"; \
docker_prefix="arm-"; \
archive_prefix="arm-"; \
else \
cpu_prefix=""; \
docker_prefix=""; \
archive_prefix=""; \
fi; \
echo "###############################################"; \
echo "###############################################"; \
echo "### Building $${dir} CPU: $${cpu_type} PHP: $${php_version} "; \
echo "###"; \
$(call build_docker_image,$${dir},$${php_version},$${cpu_prefix},$${docker_prefix}) ; \
echo ""; \
done \
done \
done
done;

test: docker-images
if [ "${layer}" != "*" ]; then test -d layers/${layer}; fi
set -e; \
for dir in layers/${layer}; do \
for php_version in $(call resolve_php_versions,$${dir}); do \
echo "###############################################"; \
echo "###############################################"; \
echo "### Testing $${dir} PHP$${php_version}"; \
echo "###"; \
docker build --build-arg PHP_VERSION=$${php_version} --build-arg TARGET_IMAGE=$${dir}-php-$${php_version} -t bref/test-$${dir}-$${php_version} tests ; \
docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${php_version} /opt/bin/php /var/task/test.php ; \
if docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${php_version} /opt/bin/php -v 2>&1 >/dev/null | grep -q 'Unable\|Warning'; then exit 1; fi ; \
echo ""; \
echo " - Test passed"; \
echo ""; \
for cpu_type in $(call resolve_cpu_types,$${dir}); do \
if [ "${layer}" = "*" ] && [[ "$(call get_cpu_types,$${dir})" != *"$${cpu_type}"* ]]; then \
echo "###############################################"; \
echo "️! Skip - $${dir} no $${cpu_type} support"; \
echo ""; \
break ; \
fi; \
for php_version in $(call resolve_php_versions,$${dir}); do \
if [[ "$${cpu_type}" = "arm" ]] ; then \
cpu_prefix="arm-"; \
docker_prefix="arm-"; \
archive_prefix="arm-"; \
else \
cpu_prefix=""; \
docker_prefix=""; \
archive_prefix=""; \
fi; \
echo "###############################################"; \
echo "###############################################"; \
echo "### Testing $${dir} CPU: $${cpu_type} PHP: $${php_version} "; \
echo "###"; \
docker build --build-arg CPU_PREFIX=$${cpu_prefix} --build-arg PHP_VERSION=$${php_version} --build-arg BREF_VERSION=${BREF_VERSION} --build-arg TARGET_IMAGE=$${dir}-$${docker_prefix}php-$${php_version} -t bref/test-$${dir}-$${cpu_prefix}$${php_version} tests ; \
docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${cpu_prefix}$${php_version} /opt/bin/php /var/task/test.php ; \
if docker run --entrypoint= --rm -v $$(pwd)/$${dir}:/var/task bref/test-$${dir}-$${cpu_prefix}$${php_version} /opt/bin/php -v 2>&1 >/dev/null | grep -q 'Unable\|Warning'; then exit 1; fi ; \
echo ""; \
echo " - Test passed"; \
echo ""; \
done \
done \
done;

# The PHP runtimes
layers: docker-images
if [ "${layer}" != "*" ]; then test -d layers/${layer}; fi
PWD=pwd
rm -rf export/layer-${layer}.zip || true
rm -rf export/${archive_prefix}layer-${layer}.zip || true
mkdir -p export/tmp
set -e; \
for dir in layers/${layer}; do \
for php_version in $(call resolve_php_versions,${PWD}/$${dir}); do \
echo "###############################################"; \
echo "###############################################"; \
echo "### Exporting $${dir} PHP$${php_version}"; \
echo "###"; \
cd ${PWD} ; rm -rf export/tmp/${layer} || true ; cd export/tmp ; \
CID=$$(docker create --entrypoint=scratch bref/$${dir}-php-$${php_version}) ; \
docker cp $${CID}:/opt . ; \
docker rm $${CID} ; \
cd ./opt ; \
zip --quiet -X --recurse-paths ../../`echo "$${dir}-php-$${php_version}" | sed -e "s/layers\//layer-/g"`.zip . ; \
echo ""; \
for cpu_type in $(call resolve_cpu_types,$${dir}); do \
if [ "${layer}" = "*" ] && [[ "$(call get_cpu_types,$${dir})" != *"$${cpu_type}"* ]]; then \
echo "###############################################"; \
echo "️! Skip - $${dir} no $${cpu_type} support"; \
echo ""; \
break ; \
fi; \
for php_version in $(call resolve_php_versions,${PWD}/$${dir}); do \
if [[ "$${cpu_type}" = "arm" ]] ; then \
cpu_prefix="arm-"; \
docker_prefix="arm-"; \
archive_prefix="arm-"; \
else \
cpu_prefix=""; \
docker_prefix=""; \
archive_prefix=""; \
fi; \
echo "###############################################"; \
echo "###############################################"; \
echo "### Exporting $${dir} CPU: $${cpu_type} PHP: $${php_version} "; \
echo "###"; \
cd ${PWD} ; rm -rf export/tmp/${layer} || true ; cd export/tmp ; \
CID=$$(docker create --entrypoint=scratch bref/$${dir}-$${docker_prefix}php-$${php_version}) ; \
docker cp $${CID}:/opt . ; \
docker rm $${CID} ; \
cd ./opt ; \
zip --quiet -X --recurse-paths ../../`echo "$${dir}-$${archive_prefix}php-$${php_version}" | sed -e "s/layers\//layer-/g"`.zip . ; \
echo ""; \
done \
done \
done
done;
rm -rf export/tmp

clean:
Expand All @@ -74,28 +129,45 @@ publish: layers
# Publish docker images
publish-docker-images: docker-images
for dir in layers/${layer}; do \
for php_version in $(call resolve_php_versions,$${dir}); do \
echo "###############################################"; \
echo "###############################################"; \
echo "### Publishing $${dir} PHP$${php_version}"; \
echo "###"; \
privateImage="bref/$${dir}-php-$${php_version}"; \
publicImage=$${privateImage/layers\//extra-}; \
echo "Image name: $$publicImage"; \
echo ""; \
echo "docker push $$publicImage:latest"; \
docker tag $$privateImage:latest $$publicImage:latest; \
docker push $$publicImage:latest; \
if (test $(DOCKER_TAG)); then \
echo "Pushing tagged images"; \
for tag in $(call resolve_tags); do \
echo ""; \
echo "docker push $$publicImage:$${tag}"; \
docker tag $$privateImage:latest $$publicImage:$${tag}; \
docker push $$publicImage:$${tag}; \
done; \
for cpu_type in $(call resolve_cpu_types,$${dir}); do \
if [ "${layer}" = "*" ] && [[ "$(call get_cpu_types,$${dir})" != *"$${cpu_type}"* ]]; then \
echo "###############################################"; \
echo "️! Skip - $${dir} no $${cpu_type} support"; \
echo ""; \
break ; \
fi; \
echo ""; \
for php_version in $(call resolve_php_versions,$${dir}); do \
if [[ "$${cpu_type}" = "arm" ]] ; then \
cpu_prefix="arm-"; \
docker_prefix="arm-"; \
archive_prefix="arm-"; \
else \
cpu_prefix=""; \
docker_prefix=""; \
archive_prefix=""; \
fi; \
echo "###############################################"; \
echo "###############################################"; \
echo "### Publishing $${dir} CPU: $${cpu_type} PHP: $${php_version} "; \
echo "###"; \
privateImage="bref/$${dir}-$${docker_prefix}php-$${php_version}"; \
publicImage=$${privateImage/layers\//extra-}; \
echo "Image name: $$publicImage"; \
echo ""; \
echo "docker push $$publicImage:latest"; \
docker tag $$privateImage:latest $$publicImage:latest; \
docker push $$publicImage:latest; \
if (test $(DOCKER_TAG)); then \
echo "Pushing tagged images"; \
for tag in $(call resolve_tags); do \
echo ""; \
echo "docker push $$publicImage:$${tag}"; \
docker tag $$privateImage:latest $$publicImage:$${tag}; \
docker push $$publicImage:$${tag}; \
done; \
fi; \
echo ""; \
done \
done \
done
done;

13 changes: 7 additions & 6 deletions layers/amqp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
ARG CPU_PREFIX
ARG PHP_VERSION
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext
ARG PHP_VERSION
FROM bref/${CPU_PREFIX}build-php-$PHP_VERSION:$BREF_VERSION AS ext

ENV LIBRABBITMQ_BUILD_DIR=${BUILD_DIR}/librabbitmq

RUN set -xe; \
mkdir -p ${LIBRABBITMQ_BUILD_DIR}; \
# Download and upack the source code
curl -Ls https://github.com/alanxz/rabbitmq-c/archive/v0.9.0.tar.gz \
# Download and unpack the source code
curl -Ls https://github.com/alanxz/rabbitmq-c/archive/refs/tags/v0.13.0.tar.gz \
| tar xzC ${LIBRABBITMQ_BUILD_DIR}

# Move into the unpackaged code directory
WORKDIR ${LIBRABBITMQ_BUILD_DIR}/rabbitmq-c-0.9.0/
WORKDIR ${LIBRABBITMQ_BUILD_DIR}/rabbitmq-c-0.13.0/

# Install
RUN set -xe; \
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} . && \
cmake --build . --target install

RUN if [[ "$PHP_VERSION" = "80" ]] ; then pecl install amqp-1.11.0beta ; else pecl install amqp ; fi
#RUN if [[ "$PHP_VERSION" = "80" ]] ; then pecl install amqp-1.11.0beta ; else pecl install amqp ; fi
RUN pecl install amqp
RUN cp `php-config --extension-dir`/amqp.so /tmp/amqp.so
RUN echo 'extension=amqp.so' > /tmp/ext.ini

Expand Down
4 changes: 4 additions & 0 deletions layers/amqp/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"80",
"81",
"82"
],
"cpu": [
"x86",
"arm"
]
}
2 changes: 1 addition & 1 deletion layers/amqp/test.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

if (!class_exists($class = AMQPConnection::class)) {
echo sprintf('FAIL: Class "%s" does not exist.', $class).PHP_EOL;
echo test . phpsprintf('FAIL: Class "%s" does not exist.', $class) . PHP_EOL;
exit(1);
}

Expand Down
3 changes: 2 additions & 1 deletion layers/blackfire/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG CPU_PREFIX
ARG PHP_VERSION
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext
FROM bref/${CPU_PREFIX}build-php-$PHP_VERSION:$BREF_VERSION AS ext

RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
Expand Down
3 changes: 3 additions & 0 deletions layers/blackfire/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"80",
"81",
"82"
],
"cpu": [
"x86"
]
}
4 changes: 2 additions & 2 deletions layers/blackfire/store.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
exit(1);
}

$file = __DIR__.'/versions.json';
$file = __DIR__ . '/versions.json';
$data = json_decode(file_get_contents($file), true);
$data[$argv[1]] = $argv[2];

file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT));

exit(0);
exit(0);
2 changes: 1 addition & 1 deletion layers/blackfire/test.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

if (!class_exists($class = BlackfireProbe::class)) {
echo sprintf('FAIL: Class "%s" does not exist.', $class).PHP_EOL;
echo test . phpsprintf('FAIL: Class "%s" does not exist.', $class) . PHP_EOL;
exit(1);
}

Expand Down
3 changes: 2 additions & 1 deletion layers/bsdiff/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG CPU_PREFIX
ARG PHP_VERSION
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext
FROM bref/${CPU_PREFIX}build-php-$PHP_VERSION:$BREF_VERSION AS ext

RUN set -ex && \
LD_LIBRARY_PATH= && \
Expand Down
4 changes: 4 additions & 0 deletions layers/bsdiff/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"80",
"81",
"82"
],
"cpu": [
"x86",
"arm"
]
}
3 changes: 2 additions & 1 deletion layers/calendar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG CPU_PREFIX
ARG PHP_VERSION
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext
FROM bref/${CPU_PREFIX}build-php-$PHP_VERSION:$BREF_VERSION AS ext

WORKDIR ${PHP_BUILD_DIR}/ext/calendar
RUN phpize && \
Expand Down
4 changes: 4 additions & 0 deletions layers/calendar/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"80",
"81",
"82"
],
"cpu": [
"x86",
"arm"
]
}
3 changes: 2 additions & 1 deletion layers/cassandra/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG CPU_PREFIX
ARG PHP_VERSION
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext
FROM bref/${CPU_PREFIX}build-php-$PHP_VERSION:$BREF_VERSION AS ext

# Datastax is providing a PHP Cassandra driver, but this hasn't been updated for a while and doesn't work with PHP 7.2 or higher
# Datastax indicated there will be updates in the near future, so check https://docs.datastax.com/en/developer/php-driver/ if you want to avoid building your own :-)
Expand Down
2 changes: 2 additions & 0 deletions layers/cassandra/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"php": [
],
"cpu": [
]
}
2 changes: 1 addition & 1 deletion layers/cassandra/test.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

if (!class_exists($class = Cassandra\Timestamp::class)) {
echo sprintf('FAIL: Class "%s" does not exist.', $class).PHP_EOL;
echo test . phpsprintf('FAIL: Class "%s" does not exist.', $class) . PHP_EOL;
exit(1);
}

Expand Down
3 changes: 2 additions & 1 deletion layers/decimal/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG CPU_PREFIX
ARG PHP_VERSION
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext
FROM bref/${CPU_PREFIX}build-php-$PHP_VERSION:$BREF_VERSION AS ext

ENV LD_LIBRARY_PATH=/usr/lib:/usr/lib64:$LD_LIBRARY_PATH
RUN yum -y install amazon-linux-extras
Expand Down
4 changes: 4 additions & 0 deletions layers/decimal/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"80",
"81",
"82"
],
"cpu": [
"x86",
"arm"
]
}
Loading