From 95123e88b55d20674777268e4baa6b367a04d0a9 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Fri, 1 Sep 2023 10:45:59 +0200 Subject: [PATCH] build(config/containers) fall-back to src build for older Xdebug versions --- config/containers/php/Dockerfile | 18 ++++++++++++++++-- makefile | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/config/containers/php/Dockerfile b/config/containers/php/Dockerfile index 6ccdb49..d1c6964 100644 --- a/config/containers/php/Dockerfile +++ b/config/containers/php/Dockerfile @@ -4,9 +4,23 @@ FROM composer:2.2 as composer FROM php:${PHP_VERSION}-cli-alpine +ARG XDEBUG_SRC='xdebug' + COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/ -RUN install-php-extensions xdebug && apk add gettext && rm -rf /var/cache/apk/* -RUN rm /usr/bin/install-php-extensions +# If the XDEBUG_SRC starts with http, download, extract and prepare it. +RUN if echo ${XDEBUG_SRC} | grep -Eq '^http'; then \ + curl -k -o /tmp/xdebug.tgz ${XDEBUG_SRC} && \ + XDEBUG_VERSION=$(echo ${XDEBUG_SRC} | sed -e 's/.*xdebug-\(.*\)\.tgz/\1/') && \ + tar xzf /tmp/xdebug.tgz -C /tmp && \ + mv /tmp/package.xml /tmp/xdebug-${XDEBUG_VERSION} && \ + rm /tmp/xdebug.tgz && \ + XDEBUG_SRC=/tmp/xdebug-${XDEBUG_VERSION}; \ + fi \ + && install-php-extensions ${XDEBUG_SRC} \ + && apk add gettext \ + && rm -rf /var/cache/apk/* \ + && rm /usr/bin/install-php-extensions \ + && rm -rf /tmp/xdebug.tgz /tmp/xdebug-${XDEBUG_VERSION} ARG XDEBUG_REMOTE_HOST='host.docker.internal' ARG XDEBUG_REMOTE_PORT='9009' diff --git a/makefile b/makefile index 29810c4..0d6c449 100644 --- a/makefile +++ b/makefile @@ -8,17 +8,37 @@ PROJECT_NAME = $(notdir $(PWD)) #.SILENT: PHP_VERSION ?= 5.6 +# Create a function that will return the xdebug source depending on the PHP version. +define xdebug_src + @if [ "$(1)" = 5.6 ]; \ + then echo "https://pecl.php.net/get/xdebug-2.5.5.tgz"; \ + elif [ "$(1)" = 7.0 ]; \ + then echo "https://pecl.php.net/get/xdebug-2.7.2.tgz"; \ + else \ + echo "xdebug"; \ + fi +endef + php_versions :=5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 build: $(build_php_versions) ## Builds the project PHP images. mkdir -p var/cache/composer mkdir -p var/log # Foreach PHP version build a Docker image. for version in $(php_versions); do \ + if [ "$${version}" = 5.6 ]; \ + then export XDEBUG_SRC="https://pecl.php.net/get/xdebug-2.5.5.tgz"; \ + elif [ "$${version}" = 7.0 ]; \ + then export XDEBUG_SRC="https://pecl.php.net/get/xdebug-2.7.2.tgz"; \ + else \ + export XDEBUG_SRC="xdebug"; \ + fi; \ docker build \ --build-arg PHP_VERSION=$${version} \ --build-arg XDEBUG_REMOTE_HOST=$${XDEBUG_REMOTE_HOST:-host.docker.internal} \ --build-arg XDEBUG_REMOTE_PORT=$${XDEBUG_REMOTE_PORT:-9009} \ --build-arg WORKDIR=${PWD} \ + --build-arg XDEBUG_SRC=$${XDEBUG_SRC} \ + --progress plain \ config/containers/php \ --tag lucatume/di52-dev:php-v$${version}; \ done