From 67cc72da622fa340ff24971b2f7e496e5ca91bad Mon Sep 17 00:00:00 2001 From: Pavel Savushkin Date: Fri, 12 Mar 2021 03:20:32 +0200 Subject: [PATCH] fix(IMAGEMAGICK extension): implement building extension for PHP 8.0 from source We need to build imagemagick extension from sources due the latest version, that supports PHP 8.0 has not been released to PECL. Closes #2861 --- docker-compose.yml | 8 ++++++-- env-example | 4 ++++ laravel-horizon/Dockerfile | 20 +++++++++++++++++++- php-fpm/Dockerfile | 24 +++++++++++++++++++++--- php-worker/Dockerfile | 30 +++++++++++++++++++++++++----- workspace/Dockerfile | 25 +++++++++++++++++++++++-- 6 files changed, 98 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 37b597d4..e3a247c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -93,7 +93,7 @@ services: - NVM_NODEJS_ORG_MIRROR=${WORKSPACE_NVM_NODEJS_ORG_MIRROR} - INSTALL_NODE=${WORKSPACE_INSTALL_NODE} - NPM_REGISTRY=${WORKSPACE_NPM_REGISTRY} - - NPM_FETCH_RETRIES=${WORKSPACE_NPM_FETCH_RETRIES} + - NPM_FETCH_RETRIES=${WORKSPACE_NPM_FETCH_RETRIES} - NPM_FETCH_RETRY_FACTOR=${WORKSPACE_NPM_FETCH_RETRY_FACTOR} - NPM_FETCH_RETRY_MINTIMEOUT=${WORKSPACE_NPM_FETCH_RETRY_MINTIMEOUT} - NPM_FETCH_RETRY_MAXTIMEOUT=${WORKSPACE_NPM_FETCH_RETRY_MAXTIMEOUT} @@ -152,6 +152,7 @@ services: - YARN_VERSION=${WORKSPACE_YARN_VERSION} - DRUSH_VERSION=${WORKSPACE_DRUSH_VERSION} - AST_VERSION=${WORKSPACE_AST_VERSION} + - IMAGEMAGICK_VERSION=${WORKSPACE_IMAGEMAGICK_VERSION} - TZ=${WORKSPACE_TIMEZONE} - BLACKFIRE_CLIENT_ID=${BLACKFIRE_CLIENT_ID} - BLACKFIRE_CLIENT_TOKEN=${BLACKFIRE_CLIENT_TOKEN} @@ -261,6 +262,7 @@ services: - DOWNGRADE_OPENSSL_TLS_AND_SECLEVEL=${PHP_DOWNGRADE_OPENSSL_TLS_AND_SECLEVEL} - PUID=${PHP_FPM_PUID} - PGID=${PHP_FPM_PGID} + - IMAGEMAGICK_VERSION=${PHP_FPM_IMAGEMAGICK_VERSION} - LOCALE=${PHP_FPM_DEFAULT_LOCALE} - PHP_FPM_NEW_RELIC=${PHP_FPM_NEW_RELIC} - PHP_FPM_NEW_RELIC_KEY=${PHP_FPM_NEW_RELIC_KEY} @@ -325,6 +327,7 @@ services: - INSTALL_XMLRPC=${PHP_WORKER_INSTALL_XMLRPC} - PUID=${PHP_WORKER_PUID} - PGID=${PHP_WORKER_PGID} + - IMAGEMAGICK_VERSION=${PHP_WORKER_IMAGEMAGICK_VERSION} volumes: - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG} - ./php-worker/supervisord.d:/etc/supervisord.d @@ -358,6 +361,7 @@ services: - INSTALL_AUDIOWAVEFORM=${LARAVEL_HORIZON_INSTALL_AUDIOWAVEFORM} - PUID=${LARAVEL_HORIZON_PUID} - PGID=${LARAVEL_HORIZON_PGID} + - IMAGEMAGICK_VERSION=${LARAVEL_HORIZON_IMAGEMAGICK_VERSION} volumes: - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER} - ./laravel-horizon/supervisord.d:/etc/supervisord.d @@ -1892,7 +1896,7 @@ services: - "3000:3000" container_name: react stdin_open: true - environment: + environment: - CHOKIDAR_USEPOLLING=true networks: - frontend diff --git a/env-example b/env-example index cf64e758..54a60e96 100644 --- a/env-example +++ b/env-example @@ -157,6 +157,7 @@ WORKSPACE_INSTALL_POWERLINE=false WORKSPACE_INSTALL_SUPERVISOR=false WORKSPACE_INSTALL_IMAGE_OPTIMIZERS=false WORKSPACE_INSTALL_IMAGEMAGICK=false +WORKSPACE_IMAGEMAGICK_VERSION=latest WORKSPACE_INSTALL_TERRAFORM=false WORKSPACE_INSTALL_DUSK_DEPS=false WORKSPACE_INSTALL_PG_CLIENT=false @@ -204,6 +205,7 @@ PHP_FPM_INSTALL_BCMATH=true PHP_FPM_INSTALL_MYSQLI=true PHP_FPM_INSTALL_INTL=true PHP_FPM_INSTALL_IMAGEMAGICK=true +PHP_FPM_IMAGEMAGICK_VERSION=latest PHP_FPM_INSTALL_OPCACHE=true PHP_FPM_INSTALL_IMAGE_OPTIMIZERS=true PHP_FPM_INSTALL_PHPREDIS=true @@ -272,6 +274,7 @@ PHP_FPM_NEW_RELIC_APP_NAME=app_name PHP_WORKER_INSTALL_BZ2=false PHP_WORKER_INSTALL_GD=false PHP_WORKER_INSTALL_IMAGEMAGICK=false +PHP_WORKER_IMAGEMAGICK_VERSION=latest PHP_WORKER_INSTALL_GMP=false PHP_WORKER_INSTALL_PGSQL=false PHP_WORKER_INSTALL_BCMATH=false @@ -312,6 +315,7 @@ LARAVEL_HORIZON_INSTALL_BZ2=false LARAVEL_HORIZON_INSTALL_GD=false LARAVEL_HORIZON_INSTALL_GMP=false LARAVEL_HORIZON_INSTALL_IMAGEMAGICK=false +LARAVEL_HORIZON_IMAGEMAGICK_VERSION=latest LARAVEL_HORIZON_INSTALL_SOCKETS=false LARAVEL_HORIZON_INSTALL_YAML=false LARAVEL_HORIZON_INSTALL_ZIP_ARCHIVE=false diff --git a/laravel-horizon/Dockerfile b/laravel-horizon/Dockerfile index 0066910f..a05137eb 100644 --- a/laravel-horizon/Dockerfile +++ b/laravel-horizon/Dockerfile @@ -74,10 +74,28 @@ RUN if [ ${INSTALL_GMP} = true ]; then \ #Install ImageMagick package: ARG INSTALL_IMAGEMAGICK=false +ARG IMAGEMAGICK_VERSION=latest +ENV IMAGEMAGICK_VERSION ${IMAGEMAGICK_VERSION} RUN set -eux; \ if [ ${INSTALL_IMAGEMAGICK} = true ]; then \ apk add --update --no-cache imagemagick-dev; \ - pecl install imagick; \ + if [ $(php -r "echo PHP_MAJOR_VERSION;") = "8" ]; then \ + apk add --update --no-cache git && \ + cd /tmp && \ + if [ ${IMAGEMAGICK_VERSION} = "latest" ]; then \ + git clone https://github.com/Imagick/imagick; \ + else \ + git clone --branch ${IMAGEMAGICK_VERSION} https://github.com/Imagick/imagick; \ + fi && \ + cd imagick && \ + phpize && \ + ./configure && \ + make && \ + make install && \ + rm -r /tmp/imagick; \ + else \ + pecl install imagick; \ + fi && \ docker-php-ext-enable imagick; \ php -m | grep -q 'imagick'; \ fi diff --git a/php-fpm/Dockerfile b/php-fpm/Dockerfile index a1e7051a..2d8d67ef 100644 --- a/php-fpm/Dockerfile +++ b/php-fpm/Dockerfile @@ -343,7 +343,7 @@ RUN if [ ${INSTALL_XHPROF} = true ]; then \ # Install the php xhprof extension if [ $(php -r "echo PHP_MAJOR_VERSION;") = 7 ]; then \ curl -L -o /tmp/xhprof.tar.gz "https://github.com/tideways/php-xhprof-extension/archive/v5.0.1.tar.gz"; \ - else \ + else \ curl -L -o /tmp/xhprof.tar.gz "https://codeload.github.com/phacility/xhprof/tar.gz/master"; \ fi \ && mkdir -p xhprof \ @@ -684,10 +684,28 @@ RUN if [ ${INSTALL_IMAGE_OPTIMIZERS} = true ]; then \ USER root ARG INSTALL_IMAGEMAGICK=false +ARG IMAGEMAGICK_VERSION=latest +ENV IMAGEMAGICK_VERSION ${IMAGEMAGICK_VERSION} RUN if [ ${INSTALL_IMAGEMAGICK} = true ]; then \ apt-get install -y libmagickwand-dev imagemagick && \ - pecl install imagick && \ + if [ $(php -r "echo PHP_MAJOR_VERSION;") = "8" ]; then \ + apt-get install -y git && \ + cd /tmp && \ + if [ ${IMAGEMAGICK_VERSION} = "latest" ]; then \ + git clone https://github.com/Imagick/imagick; \ + else \ + git clone --branch ${IMAGEMAGICK_VERSION} https://github.com/Imagick/imagick; \ + fi && \ + cd imagick && \ + phpize && \ + ./configure && \ + make && \ + make install && \ + rm -r /tmp/imagick; \ + else \ + pecl install imagick; \ + fi && \ docker-php-ext-enable imagick \ ;fi @@ -928,7 +946,7 @@ RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \ libx11-dev \ libjpeg62 \ libxtst6 \ - fontconfig \ + fontconfig \ libjpeg62-turbo \ xfonts-base \ xfonts-75dpi \ diff --git a/php-worker/Dockerfile b/php-worker/Dockerfile index 64f08298..dcc82458 100644 --- a/php-worker/Dockerfile +++ b/php-worker/Dockerfile @@ -69,11 +69,31 @@ RUN if [ ${INSTALL_GD} = true ]; then \ #Install ImageMagick: ARG INSTALL_IMAGEMAGICK=false -RUN if [ ${INSTALL_IMAGEMAGICK} = true ]; then \ - apk add --update imagemagick-dev imagemagick; \ - pecl install imagick; \ - docker-php-ext-enable imagick \ -;fi +ARG IMAGEMAGICK_VERSION=latest +ENV IMAGEMAGICK_VERSION ${IMAGEMAGICK_VERSION} +RUN set -eux; \ + if [ ${INSTALL_IMAGEMAGICK} = true ]; then \ + apk add --update --no-cache imagemagick-dev; \ + if [ $(php -r "echo PHP_MAJOR_VERSION;") = "8" ]; then \ + apk add --update --no-cache git && \ + cd /tmp && \ + if [ ${IMAGEMAGICK_VERSION} = "latest" ]; then \ + git clone https://github.com/Imagick/imagick; \ + else \ + git clone --branch ${IMAGEMAGICK_VERSION} https://github.com/Imagick/imagick; \ + fi && \ + cd imagick && \ + phpize && \ + ./configure && \ + make && \ + make install && \ + rm -r /tmp/imagick; \ + else \ + pecl install imagick; \ + fi && \ + docker-php-ext-enable imagick; \ + php -m | grep -q 'imagick'; \ + fi #Install GMP package: ARG INSTALL_GMP=false diff --git a/workspace/Dockerfile b/workspace/Dockerfile index c6c51054..91126641 100644 --- a/workspace/Dockerfile +++ b/workspace/Dockerfile @@ -1200,9 +1200,30 @@ USER laradock USER root ARG INSTALL_IMAGEMAGICK=false +ARG IMAGEMAGICK_VERSION=latest +ENV IMAGEMAGICK_VERSION ${IMAGEMAGICK_VERSION} RUN if [ ${INSTALL_IMAGEMAGICK} = true ]; then \ - apt-get install -y imagemagick php-imagick \ + apt-get install -y libmagickwand-dev imagemagick && \ + if [ $(php -r "echo PHP_MAJOR_VERSION;") = "8" ]; then \ + apt-get install -y git && \ + cd /tmp && \ + if [ ${IMAGEMAGICK_VERSION} = "latest" ]; then \ + git clone https://github.com/Imagick/imagick; \ + else \ + git clone --branch ${IMAGEMAGICK_VERSION} https://github.com/Imagick/imagick; \ + fi && \ + cd imagick && \ + phpize && \ + ./configure && \ + make && \ + make install && \ + rm -r /tmp/imagick; \ + else \ + pecl install imagick; \ + fi && \ + echo "extension=imagick.so" >> /etc/php/${LARADOCK_PHP_VERSION}/mods-available/imagick.ini && \ + ln -s /etc/php/${LARADOCK_PHP_VERSION}/mods-available/imagick.ini /etc/php/${LARADOCK_PHP_VERSION}/cli/conf.d/20-imagick.ini \ ;fi ########################################################################### @@ -1428,7 +1449,7 @@ RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \ libx11-dev \ libjpeg62 \ libxtst6 \ - fontconfig \ + fontconfig \ libjpeg-turbo8-dev \ xfonts-base \ xfonts-75dpi \