mlocati / docker-php-extension-installer

Easily install PHP extensions in Docker containers
MIT License
4.26k stars 384 forks source link

Problem with installing imagick #967

Closed adam3278 closed 1 month ago

adam3278 commented 1 month ago

Version of install-php-extensions

2.4.0

Error description

Hi, I'm facing problems with using your installer. Sometimes it stucks at compiling some extensions (in this case imagick) and the whole process is terminated, but the docker image is being built without any problem. As the result, my builds have random issues I cannot predict. I'm using kaniko builder with gitlab for building docker images. Thank you for this awesome project, but there should be some option to automatic retry of installing extensions.

Error:

Unterminated preprocessor conditions
make: *** [Makefile:196: /tmp/pear/temp/imagick/Imagick_arginfo.h] Error 1
ERROR: `make -j6 INSTALL_ROOT="/tmp/pear/temp/pear-build-defaultuserlKFCJD/install-imagick-3.7.0" install' failed

Docker image

php:8.3-fpm-alpine

Minimal Dockerfile

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

RUN apk update; \
    apk upgrade; \
    apk add --no-cache \
    g++ make autoconf bash yaml yaml-dev icu-dev imagemagick imagemagick-libs imagemagick-dev git libpq mysql-client nano

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN install-php-extensions @fix_letsencrypt; \
    install-php-extensions opcache imagick memcached exif intl zip mysqli excimer yaml;\
    install-php-extensions @composer
mlocati commented 1 month ago
RUN install-php-extensions @fix_letsencrypt; \
    install-php-extensions opcache imagick memcached exif intl zip mysqli excimer yaml;\
    install-php-extensions @composer

As stated in the README, imagick is not (yet) supported with PHP 8.3+ - see https://github.com/mlocati/docker-php-extension-installer/pull/811 and https://github.com/Imagick/imagick/issues/640

install-php-extensions fails to install imagick on PHP 8.3+, and it exits with an error code.

The problem is in your dockerfile:

RUN install-php-extensions @fix_letsencrypt; \
    install-php-extensions opcache imagick memcached exif intl zip mysqli excimer yaml;\
    install-php-extensions @composer

With the above lines, you are saying:

  1. run
    install-php-extensions @fix_letsencrypt
  2. then ignore any errors (because you are using ;) and run
    install-php-extensions opcache imagick memcached exif intl zip mysqli excimer yaml
  3. then ignore any errors (because you are using ;) and run
    install-php-extensions @composer

since the last command succeeded, docker doesn't abort the build process.

You should instead have the following in your dockerfile:

RUN install-php-extensions @fix_letsencrypt && \
    install-php-extensions opcache imagick memcached exif intl zip mysqli excimer yaml && \
    install-php-extensions @composer

(remark the use of && instead of ;) which means: run the install-php-extensions commands but abort with an error if any of them fails.