From 121b3834808f1b1348b5894f2f5c3c1c6f94af6d Mon Sep 17 00:00:00 2001 From: Ian Jenkins Date: Fri, 25 Mar 2022 16:21:58 +0000 Subject: [PATCH] [SETUP] Remove the need for duplicate xdebug dockerfiles. Means we no longer update in both places should we need to add a new extension or something. --- .github/workflows/lint.yml | 3 +- docker-compose.yml | 5 ++- docker/app/.env.dist | 2 +- docker/app/php7.4/Dockerfile | 5 ++- docker/app/php7.4/Dockerfile_xdebug | 57 ----------------------------- docker/app/php8.0/Dockerfile | 5 ++- docker/app/php8.0/Dockerfile_xdebug | 57 ----------------------------- docker/app/php8.1/Dockerfile | 5 ++- docker/app/php8.1/Dockerfile_xdebug | 57 ----------------------------- 9 files changed, 15 insertions(+), 181 deletions(-) delete mode 100644 docker/app/php7.4/Dockerfile_xdebug delete mode 100644 docker/app/php8.0/Dockerfile_xdebug delete mode 100644 docker/app/php8.1/Dockerfile_xdebug diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ef358686..6d8774ef 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,7 +4,6 @@ on: pull_request: paths: - "docker/**/Dockerfile" - - "docker/app/**/Dockerfile_xdebug" push: branches: - main @@ -23,4 +22,4 @@ jobs: - name: "Lint Dockerfile(s)" uses: jbergstroem/hadolint-gh-action@v1 with: - dockerfile: "./docker/**/Dockerfile ./docker/app/**/Dockerfile_xdebug" + dockerfile: "./docker/**/Dockerfile" diff --git a/docker-compose.yml b/docker-compose.yml index 59204d8c..28fff966 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,7 @@ services: volumes: - '.:/var/www/html:cached' extra_hosts: + - host.docker.internal:host-gateway - '${LOOPBACK_HOST_NAME}:192.168.35.10' # IP should match the IP address set for nginx below depends_on: - database @@ -35,15 +36,17 @@ services: app_xdebug: build: context: docker/app - dockerfile: php${PHP_VERSION:-7.4}/Dockerfile_xdebug + dockerfile: php${PHP_VERSION:-7.4}/Dockerfile args: USER_ID: ${USER_ID:-0} GROUP_ID: ${GROUP_ID:-0} + INSTALL_XDEBUG: true env_file: - ./docker/app/.env volumes: - '.:/var/www/html:cached' extra_hosts: + - host.docker.internal:host-gateway - '${LOOPBACK_HOST_NAME}:192.168.35.10' # IP should match the IP address set for nginx below depends_on: - database diff --git a/docker/app/.env.dist b/docker/app/.env.dist index 232c7b03..81acd410 100644 --- a/docker/app/.env.dist +++ b/docker/app/.env.dist @@ -1,6 +1,6 @@ PHP_XDEBUG_ENABLED=1 PHP_XDEBUG_REMOTE_PORT=9002 -# Xdebug remote host likely 192.168.35.1 if not using docker or on linux +# Xdebug remote host likely 192.168.35.1 if not using docker or possibly on linux PHP_XDEBUG_REMOTE_HOST=host.docker.internal PHP_XDEBUG_IDKEY=wordpress PHP_MEMORY_LIMIT=2G diff --git a/docker/app/php7.4/Dockerfile b/docker/app/php7.4/Dockerfile index 6275f158..9180afd6 100644 --- a/docker/app/php7.4/Dockerfile +++ b/docker/app/php7.4/Dockerfile @@ -2,6 +2,7 @@ FROM php:7.4.28-fpm ARG USER_ID ARG GROUP_ID +ARG INSTALL_XDEBUG # Do all apt-get installs on one line so they are installed on the same layer RUN set -eux; \ @@ -9,9 +10,9 @@ RUN set -eux; \ apt-get -y install git less zip unzip zlib1g-dev libicu-dev g++ libpng-dev libzip-dev libmagickwand-dev --no-install-recommends; \ apt-get clean && apt-get autoremove; \ rm -rf /var/lib/apt/lists/*; \ - pecl install memcache-4.0.5.2; \ + pecl install memcache-8.0 && docker-php-ext-enable memcache; \ pecl install imagick && docker-php-ext-enable imagick; \ - docker-php-ext-enable memcache; \ + [ "${INSTALL_XDEBUG:-false}" = true ] && pecl install xdebug && docker-php-ext-enable xdebug; \ docker-php-ext-configure intl; \ docker-php-ext-install -j"$(nproc)" mysqli opcache zip intl gd diff --git a/docker/app/php7.4/Dockerfile_xdebug b/docker/app/php7.4/Dockerfile_xdebug deleted file mode 100644 index 836ffa8a..00000000 --- a/docker/app/php7.4/Dockerfile_xdebug +++ /dev/null @@ -1,57 +0,0 @@ -FROM php:7.4.28-fpm - -ARG USER_ID -ARG GROUP_ID - -# Do all apt-get installs on one line so they are installed on the same layer -RUN set -eux; \ - apt-get -y update; \ - apt-get -y install git less zip unzip zlib1g-dev libicu-dev g++ libpng-dev libzip-dev libmagickwand-dev --no-install-recommends; \ - apt-get clean && apt-get autoremove; \ - rm -rf /var/lib/apt/lists/*; \ - pecl install memcache-4.0.5.2; \ - pecl install imagick && docker-php-ext-enable imagick; \ - pecl install xdebug && docker-php-ext-enable xdebug; \ - docker-php-ext-enable memcache; \ - docker-php-ext-configure intl; \ - docker-php-ext-install -j"$(nproc)" mysqli opcache zip intl gd - -# Composer -COPY --from=composer:2.2.3 /usr/bin/composer /usr/local/bin/composer - -# WP-CLI -COPY --from=wordpress:cli-2.6.0-php7.4 /usr/local/bin/wp /usr/local/bin/wp - -# MhSendmail -RUN set -eux; \ - curl -sSLo /usr/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64; \ - chmod ugo+x /usr/bin/mhsendmail - -# Blackfire -# https://blackfire.io/docs/integrations/docker/php-docker -RUN set -eux; \ - version="$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")" \ - && architecture="$(uname -m)" \ - && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s "https://blackfire.io/api/v1/releases/probe/php/linux/$architecture/$version" \ - && mkdir -p /tmp/blackfire \ - && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \ - && mv /tmp/blackfire/blackfire-*.so "$(php -r "echo ini_get ('extension_dir');")/blackfire.so" \ - && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8307\n" > "$PHP_INI_DIR/conf.d/blackfire.ini" \ - && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz; - -# Set groups and user when on linux -RUN set -eux; \ - if [ "${USER_ID:-0}" -ne 0 ] && [ "${GROUP_ID:-0}" -ne 0 ]; then \ - userdel -f www-data; \ - if getent group www-data ; then groupdel www-data; fi; \ - groupadd -g "${GROUP_ID}" www-data; \ - useradd -l -u "${USER_ID}" -g www-data www-data; \ - install -d -m 0755 -o www-data -g www-data /home/www-data; \ - fi - -COPY ./php-config/*.ini /usr/local/etc/php/conf.d/ - -WORKDIR /var/www/html -RUN chown -R www-data:www-data /var/www -EXPOSE 9000 -CMD ["php-fpm"] diff --git a/docker/app/php8.0/Dockerfile b/docker/app/php8.0/Dockerfile index d8ad7e72..21cc63da 100644 --- a/docker/app/php8.0/Dockerfile +++ b/docker/app/php8.0/Dockerfile @@ -2,6 +2,7 @@ FROM php:8.0.17-fpm ARG USER_ID ARG GROUP_ID +ARG INSTALL_XDEBUG # Do all apt-get installs on one line so they are installed on the same layer RUN set -eux; \ @@ -9,9 +10,9 @@ RUN set -eux; \ apt-get -y install git less zip unzip zlib1g-dev libicu-dev g++ libpng-dev libzip-dev libmagickwand-dev --no-install-recommends; \ apt-get clean && apt-get autoremove; \ rm -rf /var/lib/apt/lists/*; \ - pecl install memcache-8.0; \ + pecl install memcache-8.0 && docker-php-ext-enable memcache; \ pecl install imagick && docker-php-ext-enable imagick; \ - docker-php-ext-enable memcache; \ + [ "${INSTALL_XDEBUG:-false}" = true ] && pecl install xdebug && docker-php-ext-enable xdebug; \ docker-php-ext-configure intl; \ docker-php-ext-install -j"$(nproc)" mysqli opcache zip intl gd diff --git a/docker/app/php8.0/Dockerfile_xdebug b/docker/app/php8.0/Dockerfile_xdebug deleted file mode 100644 index 15687127..00000000 --- a/docker/app/php8.0/Dockerfile_xdebug +++ /dev/null @@ -1,57 +0,0 @@ -FROM php:8.0.17-fpm - -ARG USER_ID -ARG GROUP_ID - -# Do all apt-get installs on one line so they are installed on the same layer -RUN set -eux; \ - apt-get -y update; \ - apt-get -y install git less zip unzip zlib1g-dev libicu-dev g++ libpng-dev libzip-dev libmagickwand-dev --no-install-recommends; \ - apt-get clean && apt-get autoremove; \ - rm -rf /var/lib/apt/lists/*; \ - pecl install memcache-8.0; \ - pecl install imagick && docker-php-ext-enable imagick; \ - pecl install xdebug && docker-php-ext-enable xdebug; \ - docker-php-ext-enable memcache; \ - docker-php-ext-configure intl; \ - docker-php-ext-install -j"$(nproc)" mysqli opcache zip intl gd - -# Composer -COPY --from=composer:2.2.3 /usr/bin/composer /usr/local/bin/composer - -# WP-CLI -COPY --from=wordpress:cli-2.6.0-php7.4 /usr/local/bin/wp /usr/local/bin/wp - -# MhSendmail -RUN set -eux; \ - curl -sSLo /usr/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64; \ - chmod ugo+x /usr/bin/mhsendmail - -# Blackfire -# https://blackfire.io/docs/integrations/docker/php-docker -RUN set -eux; \ - version="$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")" \ - && architecture="$(uname -m)" \ - && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s "https://blackfire.io/api/v1/releases/probe/php/linux/$architecture/$version" \ - && mkdir -p /tmp/blackfire \ - && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \ - && mv /tmp/blackfire/blackfire-*.so "$(php -r "echo ini_get ('extension_dir');")/blackfire.so" \ - && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8307\n" > "$PHP_INI_DIR/conf.d/blackfire.ini" \ - && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz; - -# Set groups and user when on linux -RUN set -eux; \ - if [ "${USER_ID:-0}" -ne 0 ] && [ "${GROUP_ID:-0}" -ne 0 ]; then \ - userdel -f www-data; \ - if getent group www-data ; then groupdel www-data; fi; \ - groupadd -g "${GROUP_ID}" www-data; \ - useradd -l -u "${USER_ID}" -g www-data www-data; \ - install -d -m 0755 -o www-data -g www-data /home/www-data; \ - fi - -COPY ./php-config/*.ini /usr/local/etc/php/conf.d/ - -WORKDIR /var/www/html -RUN chown -R www-data:www-data /var/www -EXPOSE 9000 -CMD ["php-fpm"] diff --git a/docker/app/php8.1/Dockerfile b/docker/app/php8.1/Dockerfile index c13cdafe..f9bee786 100644 --- a/docker/app/php8.1/Dockerfile +++ b/docker/app/php8.1/Dockerfile @@ -2,6 +2,7 @@ FROM php:8.1.4-fpm ARG USER_ID ARG GROUP_ID +ARG INSTALL_XDEBUG # Do all apt-get installs on one line so they are installed on the same layer RUN set -eux; \ @@ -9,9 +10,9 @@ RUN set -eux; \ apt-get -y install git less zip unzip zlib1g-dev libicu-dev g++ libpng-dev libzip-dev libmagickwand-dev --no-install-recommends; \ apt-get clean && apt-get autoremove; \ rm -rf /var/lib/apt/lists/*; \ - pecl install memcache-8.0; \ + pecl install memcache-8.0 && docker-php-ext-enable memcache; \ pecl install imagick && docker-php-ext-enable imagick; \ - docker-php-ext-enable memcache; \ + [ "${INSTALL_XDEBUG:-false}" = true ] && pecl install xdebug && docker-php-ext-enable xdebug; \ docker-php-ext-configure intl; \ docker-php-ext-install -j"$(nproc)" mysqli opcache zip intl gd diff --git a/docker/app/php8.1/Dockerfile_xdebug b/docker/app/php8.1/Dockerfile_xdebug deleted file mode 100644 index 96a9d441..00000000 --- a/docker/app/php8.1/Dockerfile_xdebug +++ /dev/null @@ -1,57 +0,0 @@ -FROM php:8.1.4-fpm - -ARG USER_ID -ARG GROUP_ID - -# Do all apt-get installs on one line so they are installed on the same layer -RUN set -eux; \ - apt-get -y update; \ - apt-get -y install git less zip unzip zlib1g-dev libicu-dev g++ libpng-dev libzip-dev libmagickwand-dev --no-install-recommends; \ - apt-get clean && apt-get autoremove; \ - rm -rf /var/lib/apt/lists/*; \ - pecl install memcache-8.0; \ - pecl install imagick && docker-php-ext-enable imagick; \ - pecl install xdebug && docker-php-ext-enable xdebug; \ - docker-php-ext-enable memcache; \ - docker-php-ext-configure intl; \ - docker-php-ext-install -j"$(nproc)" mysqli opcache zip intl gd - -# Composer -COPY --from=composer:2.2.3 /usr/bin/composer /usr/local/bin/composer - -# WP-CLI -COPY --from=wordpress:cli-2.6.0-php7.4 /usr/local/bin/wp /usr/local/bin/wp - -# MhSendmail -RUN set -eux; \ - curl -sSLo /usr/bin/mhsendmail https://github.com/mailhog/mhsendmail/releases/download/v0.2.0/mhsendmail_linux_amd64; \ - chmod ugo+x /usr/bin/mhsendmail - -# Blackfire -# https://blackfire.io/docs/integrations/docker/php-docker -RUN set -eux; \ - version="$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;")" \ - && architecture="$(uname -m)" \ - && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s "https://blackfire.io/api/v1/releases/probe/php/linux/$architecture/$version" \ - && mkdir -p /tmp/blackfire \ - && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \ - && mv /tmp/blackfire/blackfire-*.so "$(php -r "echo ini_get ('extension_dir');")/blackfire.so" \ - && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8307\n" > "$PHP_INI_DIR/conf.d/blackfire.ini" \ - && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz; - -# Set groups and user when on linux -RUN set -eux; \ - if [ "${USER_ID:-0}" -ne 0 ] && [ "${GROUP_ID:-0}" -ne 0 ]; then \ - userdel -f www-data; \ - if getent group www-data ; then groupdel www-data; fi; \ - groupadd -g "${GROUP_ID}" www-data; \ - useradd -l -u "${USER_ID}" -g www-data www-data; \ - install -d -m 0755 -o www-data -g www-data /home/www-data; \ - fi - -COPY ./php-config/*.ini /usr/local/etc/php/conf.d/ - -WORKDIR /var/www/html -RUN chown -R www-data:www-data /var/www -EXPOSE 9000 -CMD ["php-fpm"]