imagick icon indicating copy to clipboard operation
imagick copied to clipboard

Transient Error when Building Imagick in php 8.3.x on amd64 on alpine

Open en-jschuetze opened this issue 1 year ago • 23 comments

A follow up of 582

Building on linux/amd64 the Dockerfile:

FROM alpine:edge
RUN apk add php83 php83-pear php83-openssl php83-sockets
RUN apk add --no-cache binutils build-base openssl-dev autoconf pcre2-dev automake libtool linux-headers imagemagick imagemagick-dev imagemagick-libs php83-dev~=8.3.0 --virtual .build-deps     && MAKEFLAGS="-j $(nproc)" pecl83 install imagick     && strip --strip-all /usr/lib/php83/modules/imagick.so     && echo "extension=imagick" > /etc/php83/conf.d/00_imagick.ini     && apk del --no-network .build-deps     && apk add --no-cache imagemagick imagemagick-libs libgomp

and the error is (not happening every time, but 75% of all runs):

38 10.77 cc -shared  .libs/imagick_file.o .libs/imagick_class.o .libs/imagickdraw_class.o .libs/imagickpixel_class.o .libs/imagickpixeliterator_class.o .libs/imagick_helpers.o .libs/imagick.o .libs/imagickkernel_class.o .libs/shim_im6_to_im7.o  -lgomp -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI  -Wl,-soname -Wl,imagick.so -o .libs/imagick.so
#38 10.82 creating imagick.la
#38 10.82 (cd .libs && rm -f imagick.la && ln -s ../imagick.la imagick.la)
#38 10.82 /bin/sh /tmp/pear/temp/pear-build-defaultuserhbpaOF/imagick-3.7.0/libtool --mode=install cp ./imagick.la /tmp/pear/temp/pear-build-defaultuserhbpaOF/imagick-3.7.0/modules
#38 10.84 cp ./.libs/imagick.so /tmp/pear/temp/pear-build-defaultuserhbpaOF/imagick-3.7.0/modules/imagick.so
#38 10.84 cp ./.libs/imagick.lai /tmp/pear/temp/pear-build-defaultuserhbpaOF/imagick-3.7.0/modules/imagick.la
#38 10.85 PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/pear-build-defaultuserhbpaOF/imagick-3.7.0/modules
#38 10.85 ----------------------------------------------------------------------
#38 10.85 Libraries have been installed in:
#38 10.85    /tmp/pear/temp/pear-build-defaultuserhbpaOF/imagick-3.7.0/modules
#38 10.85 
#38 10.85 If you ever happen to want to link against installed libraries
#38 10.85 in a given directory, LIBDIR, you must either use libtool, and
#38 10.85 specify the full pathname of the library, or use the `-LLIBDIR'
#38 10.85 flag during linking and do at least one of the following:
#38 10.85    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
#38 10.85      during execution
#38 10.85    - add LIBDIR to the `LD_RUN_PATH' environment variable
#38 10.85      during linking
#38 10.85    - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
#38 10.85 
#38 10.85 See any operating system documentation about shared libraries for
#38 10.85 more information, such as the ld(1) and ld.so(8) manual pages.
#38 10.85 ----------------------------------------------------------------------
#38 10.86 
#38 10.86 Build complete.
#38 10.86 Don't forget to run 'make test'.
#38 10.86 
#38 10.86 running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-defaultuserhbpaOF/install-imagick-3.7.0" install
#38 10.87 Parse /tmp/pear/temp/imagick/ImagickDraw.stub.php to generate /tmp/pear/temp/imagick/ImagickDraw_arginfo.h
#38 10.87 Parse /tmp/pear/temp/imagick/ImagickPixelIterator.stub.php to generate /tmp/pear/temp/imagick/ImagickPixelIterator_arginfo.h
#38 10.87 Parse /tmp/pear/temp/imagick/ImagickPixel.stub.php to generate /tmp/pear/temp/imagick/ImagickPixel_arginfo.h
#38 10.88 Parse /tmp/pear/temp/imagick/Imagick.stub.php to generate /tmp/pear/temp/imagick/Imagick_arginfo.h
#38 10.91 Connecting to github.com (140.82.112.4:443)
#38 11.06 Connecting to codeload.github.com (140.82.113.10:443)
#38 11.23 saving to 'v5.0.0alpha3.tar.gz'
#38 11.28 v5.0.0alpha3.tar.gz  100% |********************************|  157k  0:00:00 ETA
#38 11.28 'v5.0.0alpha3.tar.gz' saved
#38 11.28 PHP-Parser-5.0.0alpha3/
#38 11.28 PHP-Parser-5.0.0alpha3/.php-cs-fixer.dist.php
#38 11.28 PHP-Parser-5.0.0alpha3/LICENSE
[sniiiipppppp]
#38 11.32 PHP-Parser-5.0.0alpha3/lib/PhpParser/PrettyPrinterAbstract.php
#38 11.32 PHP-Parser-5.0.0alpha3/lib/PhpParser/Token.php
#38 11.32 PHP-Parser-5.0.0alpha3/lib/PhpParser/compatibility_tokens.php
#38 11.32 PHP-Parser-5.0.0alpha3/phpstan-baseline.neon
#38 11.32 PHP-Parser-5.0.0alpha3/phpstan.neon.dist
#38 11.34 Saved /tmp/pear/temp/imagick/ImagickPixel_arginfo.h
#38 11.34 Saved /tmp/pear/temp/imagick/ImagickPixelIterator_arginfo.h
#38 11.35 Parse /tmp/pear/temp/imagick/ImagickKernel.stub.php to generate /tmp/pear/temp/imagick/ImagickKernel_arginfo.h
#38 11.35 Saved /tmp/pear/temp/imagick/ImagickDraw_arginfo.h
#38 11.38 In /tmp/pear/temp/imagick/Imagick.stub.php:
#38 11.38 Unterminated preprocessor conditions
#38 11.39 make: *** [Makefile:196: /tmp/pear/temp/imagick/Imagick_arginfo.h] Error 1
#38 11.39 make: *** Waiting for unfinished jobs....
#38 11.41 Saved /tmp/pear/temp/imagick/ImagickKernel_arginfo.h
#38 11.41 Installing header files:          /tmp/pear/temp/pear-build-defaultuserhbpaOF/install-imagick-3.7.0/usr/include/php83/
#38 11.44 ERROR: `make INSTALL_ROOT="/tmp/pear/temp/pear-build-defaultuserhbpaOF/install-imagick-3.7.0" install' failed
#38 ERROR: process "/bin/sh -c apk add --no-cache binutils build-base openssl-dev autoconf pcre2-dev automake libtool linux-headers imagemagick imagemagick-dev imagemagick-libs ${PHP_PACKAGE_BASENAME}-dev~=${PHP_VERSION} --virtual .build-deps     && MAKEFLAGS=\"-j $(nproc)\" pecl83 install imagick     && strip --strip-all /usr/lib/$PHP_PACKAGE_BASENAME/modules/imagick.so     && echo \"extension=imagick\" > /etc/$PHP_PACKAGE_BASENAME/conf.d/00_imagick.ini     && apk del --no-network .build-deps     && apk add --no-cache imagemagick imagemagick-libs libgomp" did not complete successfully: exit code: 1

it does not happen ever on arm architecture.

for reference an example run in a "real" world at https://github.com/Endava/docker-php/actions/runs/7009886813/job/19071577630

en-jschuetze avatar Nov 29 '23 08:11 en-jschuetze

mee to

mryfan avatar Nov 30 '23 05:11 mryfan

It is because of this?

https://github.com/Imagick/imagick/pull/641

All my pipelines fail sporadic and not every time.

K2ouMais avatar Nov 30 '23 09:11 K2ouMais

If you're looking for a workaround, you can explicitly use PHP 8.2. Here's an example of how I've done that in my workflow.

Until this gets merged, I am using a workaround in my automated builds to explicitly fix the PHP version to 8.2. This is suggested by Composer:

PHP version & extensions

(optimal) create your own build image and install Composer inside it. Note: Docker 17.05 introduced multi-stage builds, simplifying this enormously: COPY --from=composer /usr/bin/composer /usr/bin/composer

In my Dockerfile I had:

FROM composer:2.5 as composer_base

I've updated it to copy Composer from their image into a PHP 8.2 image in order to build with that version:

FROM composer:2.5

# TODO: Revert back to image `composer:2.5`
FROM php:8.2-alpine as composer_base
COPY --from=composer /usr/bin/composer /usr/bin/composer

dantheman2865 avatar Nov 30 '23 14:11 dantheman2865

@dantheman2865

Can you explain what effect this has on the imagick extension?

en-jschuetze avatar Nov 30 '23 14:11 en-jschuetze

Can you explain what effect this has on the imagick extension?

@en-jschuetze I've updated the comment to be more clear. I'm hoping to help folks who need a workaround because their automated builds are broken (as mine were).

dantheman2865 avatar Nov 30 '23 14:11 dantheman2865

Ah I see. You avoid php 8.3 :)

en-jschuetze avatar Nov 30 '23 14:11 en-jschuetze

This is the workaround I used the last time:

RUN curl -L -o /tmp/imagick.tar.gz https://github.com/Imagick/imagick/archive/7088edc353f53c4bc644573a79cdcd67a726ae16.tar.gz \
    && tar --strip-components=1 -xf /tmp/imagick.tar.gz \
    && phpize \
    && ./configure \
    && make \
    && make install \
    && echo "extension=imagick.so" > /usr/local/etc/php/conf.d/ext-imagick.ini \
    && rm -rf /tmp/* \

The package is the commit from #641

daFish avatar Nov 30 '23 18:11 daFish

What is the status of this one? Is it close to be done?

fpetrovic avatar Jan 24 '24 17:01 fpetrovic

Same problem, Debian 12 images. The workaround below worked for us (thx @daFish).

# build
docker build -t localhost:5000/poc-8.3-imagick - <<EOF
FROM php:8.3

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

RUN \
  set -eux; \
  install-php-extensions https://codeload.github.com/Imagick/imagick/tar.gz/7088edc353f53c4bc644573a79cdcd67a726ae16

EOF

# verify
docker run --rm localhost:5000/poc-8.3-imagick php -r 'var_export(phpversion("imagick"));'

0x6D682D7331 avatar Jan 27 '24 02:01 0x6D682D7331

This is the workaround I used the last time:

RUN curl -L -o /tmp/imagick.tar.gz https://github.com/Imagick/imagick/archive/7088edc353f53c4bc644573a79cdcd67a726ae16.tar.gz \
    && tar --strip-components=1 -xf /tmp/imagick.tar.gz \
    && phpize \
    && ./configure \
    && make \
    && make install \
    && echo "extension=imagick.so" > /usr/local/etc/php/conf.d/ext-imagick.ini \
    && rm -rf /tmp/* \

The package is the commit from #641

This works also if you use 3.7.0 as commit id. So I guess I am fine for my project for now, but it would be awesome to get it fixed in a pecl release, too.

en-jschuetze avatar Feb 07 '24 07:02 en-jschuetze

not happening every time, but 75% of all runs

It is very odd that it passes some of the time.

For the record, this doesn't happen on my computer compiling either inside a docker Ubuntu box, or natively on OSX.

I've possibly fixed it, though would prefer to see it compiling in the Github actions....which appear to be broken for something that is not my fault.

Danack avatar Feb 08 '24 21:02 Danack

@Danack Any updates on this issue. Is there anything we can do to help related to the Github actions you mentioned in the last comment?

grEvenX avatar Mar 04 '24 09:03 grEvenX

Same issue here, waiting resolution to use PHP 8.3 in production.

apoca avatar Mar 12 '24 22:03 apoca

This is the workaround I used the last time:

RUN curl -L -o /tmp/imagick.tar.gz https://github.com/Imagick/imagick/archive/7088edc353f53c4bc644573a79cdcd67a726ae16.tar.gz \
    && tar --strip-components=1 -xf /tmp/imagick.tar.gz \
    && phpize \
    && ./configure \
    && make \
    && make install \
    && echo "extension=imagick.so" > /usr/local/etc/php/conf.d/ext-imagick.ini \
    && rm -rf /tmp/* \

The package is the commit from #641

This solution works, but it is very temporary :D

radziejewicz avatar Mar 30 '24 14:03 radziejewicz

I have encountered the same problem, when building multiplatform image on linux + AMD CPU. Build for linux/amd64 was successull, but for linux/arm64/v8 it ended up with this error.

Interestingly, when I tried to build it within container FROM docker:latest, it completed successfully for both platforms.

Is there any progress or indication, where the problem might be?

vaclavekp avatar Apr 30 '24 08:04 vaclavekp

OK, so we are waiting for imagick to release new version where this bug is fixed. Until then, there is temporary solution to use unreleased version of imagick.

Source: https://github.com/Imagick/imagick/issues/640

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions imagick/imagick@master

vaclavekp avatar Apr 30 '24 19:04 vaclavekp

Is there any progress in this issue? We also have the same problem. Using the workaround for now.

abcRede avatar Jun 11 '24 12:06 abcRede

Just here to say, this problem seems to be happening already for a few months but nobody seems to be working on it?

david-zamora-minderest avatar Jun 13 '24 08:06 david-zamora-minderest

This worked for me.

RUN set -eux; \
	install-php-extensions \
		Imagick/imagick@master ;

cizordj avatar Jun 25 '24 18:06 cizordj

failing also in arm architecture from this image: FROM --platform=linux/arm64 php:8.3-fpm-alpine

msucevan avatar Jul 23 '24 15:07 msucevan

This solution worked for me:

RUN set -ex && \
        apk add --no-cache --virtual .build-deps \
        libxml2-dev \
        shadow \
        autoconf \
        g++ \
        make \
    && apk add php83-pecl-imagick --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
    && apk --update add imagemagick imagemagick-dev libwebp-dev libde265-dev libgomp \
    && pecl install imagick \
    && docker-php-ext-enable imagick \
    && apk del .build-deps

andreinocenti avatar Jul 30 '24 20:07 andreinocenti

any updates on this issue? My builds are failing like 75% of the time because of this, re-running the builds sometimes work. Sometimes I have to wat 5-10 min and rerun again

ingLomeland avatar Aug 15 '24 11:08 ingLomeland

install-php-extensions \
		Imagick/imagick@master ;

Hi @ingLomeland , I have used this approach with success, someone mentioned it above. As far as I know, the problem hasn't been solved yet.

david-zamora-minderest avatar Aug 16 '24 07:08 david-zamora-minderest

Or if you want to pick a specific commit:

RUN set -eux; \
	install-php-extensions \
		Imagick/imagick@28f27044e435a2b203e32675e942eb8de620ee58 ;

This way you avoid breaking your build even if the master changes

cizordj avatar Aug 21 '24 10:08 cizordj