cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Alpine builds on Docker fail

Open FaimMedia opened this issue 3 years ago • 6 comments

Hi,

Since a few weeks my Docker builds on Alpine doesn't seem to work anymore. This is my (partial) Dockerfile:

FROM php:8.2-fpm-alpine

ARG PHALCON_VERSION=5.2.1

RUN set -xe && \
        apk add --no-cache --virtual .build-deps \
            autoconf \
            g++ \
            make \
        && \
        docker-php-source extract && \
        # Install ext-phalcon
	cd / && \
        curl -LO https://github.com/phalcon/cphalcon/archive/v${PHALCON_VERSION}.tar.gz && \
        tar xzf /v${PHALCON_VERSION}.tar.gz && \
        docker-php-ext-install -j $(getconf _NPROCESSORS_ONLN) \
            /cphalcon-${PHALCON_VERSION}/build/phalcon \
        && \
        # Remove all temp files
        rm -r \
            /v${PHALCON_VERSION}.tar.gz \
            /cphalcon-${PHALCON_VERSION} \
        && \
        docker-php-source delete && \
        apk del .build-deps

I've also tried the official approach via PECL (as described on the website), but this giving me the same results:

FROM php:8.2-fpm-alpine

RUN apk update && \
 	apk --no-cache --virtual .build-deps add pcre-dev ${PHPIZE_DEPS}

RUN pecl channel-update pecl.php.net \
	&& pecl install phalcon-5.2.1

This gives me a lot (500+) of compile errors which will eventually quit:

In file included from /usr/local/include/php/main/php.h:35,
                 from /cphalcon-5.2.1/build/phalcon/phalcon.zep.c:46:
/usr/local/include/php/Zend/zend_API.h:2182:71: note: expected 'zval **' {aka 'struct _zval_struct **'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
 2182 | static zend_always_inline bool zend_parse_arg_array(zval *arg, zval **dest, bool check_null, bool or_object)
      |                                                                ~~~~~~~^~~~
In file included from /usr/local/include/php/Zend/zend_types.h:25,
                 from /usr/local/include/php/Zend/zend.h:27,
                 from /usr/local/include/php/main/php.h:31,
                 from /cphalcon-5.2.1/build/phalcon/phalcon.zep.c:46:
/cphalcon-5.2.1/build/phalcon/phalcon.zep.c: In function 'zim_Phalcon_Session_Adapter_Redis___construct':
/usr/local/include/php/Zend/zend_API.h:1558:60: warning: passing argument 2 of 'zend_parse_arg_array' from incompatible pointer type [-Wincompatible-pointer-types]
 1558 |                 if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
/usr/local/include/php/Zend/zend_portability.h:364:52: note: in definition of macro 'UNEXPECTED'
  364 | # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0)
      |                                                    ^~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:1565:9: note: in expansion of macro 'Z_PARAM_ARRAY_EX2'
 1565 |         Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
      |         ^~~~~~~~~~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:1568:9: note: in expansion of macro 'Z_PARAM_ARRAY_EX'
 1568 |         Z_PARAM_ARRAY_EX(dest, 0, 0)
      |         ^~~~~~~~~~~~~~~~
/cphalcon-5.2.1/build/phalcon/phalcon.zep.c:219202:17: note: in expansion of macro 'Z_PARAM_ARRAY'
219202 |                 Z_PARAM_ARRAY(options)
       |                 ^~~~~~~~~~~~~
In file included from /usr/local/include/php/main/php.h:35,
                 from /cphalcon-5.2.1/build/phalcon/phalcon.zep.c:46:
/usr/local/include/php/Zend/zend_API.h:2182:71: note: expected 'zval **' {aka 'struct _zval_struct **'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
 2182 | static zend_always_inline bool zend_parse_arg_array(zval *arg, zval **dest, bool check_null, bool or_object)
      |                                                                ~~~~~~~^~~~
In file included from /usr/local/include/php/Zend/zend_types.h:25,
                 from /usr/local/include/php/Zend/zend.h:27,
                 from /usr/local/include/php/main/php.h:31,
                 from /cphalcon-5.2.1/build/phalcon/phalcon.zep.c:46:
/cphalcon-5.2.1/build/phalcon/phalcon.zep.c: In function 'zim_Phalcon_Session_Adapter_Stream___construct':
/usr/local/include/php/Zend/zend_API.h:1558:60: warning: passing argument 2 of 'zend_parse_arg_array' from incompatible pointer type [-Wincompatible-pointer-types]
 1558 |                 if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
/usr/local/include/php/Zend/zend_portability.h:364:52: note: in definition of macro 'UNEXPECTED'
  364 | # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0)
      |                                                    ^~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:1565:9: note: in expansion of macro 'Z_PARAM_ARRAY_EX2'
 1565 |         Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
      |         ^~~~~~~~~~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:1568:9: note: in expansion of macro 'Z_PARAM_ARRAY_EX'
 1568 |         Z_PARAM_ARRAY_EX(dest, 0, 0)
      |         ^~~~~~~~~~~~~~~~
/cphalcon-5.2.1/build/phalcon/phalcon.zep.c:219271:17: note: in expansion of macro 'Z_PARAM_ARRAY'
219271 |                 Z_PARAM_ARRAY(options)
       |                 ^~~~~~~~~~~~~
In file included from /usr/local/include/php/main/php.h:35,
                 from /cphalcon-5.2.1/build/phalcon/phalcon.zep.c:46:
/usr/local/include/php/Zend/zend_API.h:2182:71: note: expected 'zval **' {aka 'struct _zval_struct **'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
 2182 | static zend_always_inline bool zend_parse_arg_array(zval *arg, zval **dest, bool check_null, bool or_object)
      |                                                                ~~~~~~~^~~~
In file included from /usr/local/include/php/Zend/zend_types.h:25,
                 from /usr/local/include/php/Zend/zend.h:27,
                 from /usr/local/include/php/main/php.h:31,
                 from /cphalcon-5.2.1/build/phalcon/phalcon.zep.c:46:
/cphalcon-5.2.1/build/phalcon/phalcon.zep.c: In function 'zim_Phalcon_Session_Adapter_Stream_getArrVal':
/usr/local/include/php/Zend/zend_API.h:1558:60: warning: passing argument 2 of 'zend_parse_arg_array' from incompatible pointer type [-Wincompatible-pointer-types]
 1558 |                 if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
/usr/local/include/php/Zend/zend_portability.h:364:52: note: in definition of macro 'UNEXPECTED'
  364 | # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0)
      |                                                    ^~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:1565:9: note: in expansion of macro 'Z_PARAM_ARRAY_EX2'
 1565 |         Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
      |         ^~~~~~~~~~~~~~~~~
/usr/local/include/php/Zend/zend_API.h:1568:9: note: in expansion of macro 'Z_PARAM_ARRAY_EX'
 1568 |         Z_PARAM_ARRAY_EX(dest, 0, 0)
      |         ^~~~~~~~~~~~~~~~
/cphalcon-5.2.1/build/phalcon/phalcon.zep.c:219600:17: note: in expansion of macro 'Z_PARAM_ARRAY'
219600 |                 Z_PARAM_ARRAY(collection)
       |                 ^~~~~~~~~~~~~

Also tried using Phalcon 5.1, PHP 8.0 and 8.1, Alpine 3.16, all with the same result. Tried the -DALPINE_LINUX=1 CFLAG, but seems to have no effect.

What is the issue here? Seems to be related to #16213.

When using the Zephir to compile, the build takes forever:

FROM php:8.2-fpm-alpine

RUN apk update && \
 	apk --no-cache --virtual .build-deps add pcre-dev ${PHPIZE_DEPS}

ARG PHALCON_VERSION=5.2.1

# pecl:
RUN pecl channel-update pecl.php.net \
	&& pecl install zephir_parser

RUN echo "extension=zephir_parser.so" > /usr/local/etc/php/conf.d/zephir.ini

RUN cd / \
	&& curl -LO https://github.com/zephir-lang/zephir/releases/download/0.17.0/zephir.phar \
	&& mv zephir.phar /usr/local/bin/zephir \
	&& chmod a+x /usr/local/bin/zephir

RUN cd / \
	&& curl -LO https://github.com/phalcon/cphalcon/archive/v${PHALCON_VERSION}.tar.gz \
	&& tar xzf /v${PHALCON_VERSION}.tar.gz \
	&& rm -rf /v${PHALCON_VERSION}.tar.gz

RUN cd /cphalcon-${PHALCON_VERSION} \
	&& zephir fullclean \
	&& zephir compile \
	&& cd ext \
	&& phpize \
	&& ./configure \
	&& make \
	&& make install \
	&& cd .. \
	&& zephir install

Could someone please provide me with a solution here :-)

Greetings, Tim

FaimMedia avatar Apr 19 '23 20:04 FaimMedia

I have the same warnings, but if you wait a while then everything is fine.

Everything works for me and my colleagues. https://github.com/yesworld/starter-phalcon5-php8-docker

yesworld avatar May 31 '23 14:05 yesworld

Just keep in mind that compile from docker might be resource hungry, took me a while to figure out that I was running out of memory, after allocating 4GB was able to complete the build.

Nazariy avatar Jun 01 '23 16:06 Nazariy

As @Nazariy said Phalcon will require at least 2Gb of RAM during compilation process. In case you are building docker image inside small virtual machine - add swap file with 2Gb.

@FaimMedia, I just finished to compile Phalcon inside aline, I suggest you to install it via pecl instead of git, as it way to straight forward, requires less steps and at the end docker image weights less.

Here are my commands:

docker run -it --rm php:8.2-fpm-alpine sh
apk update && apk add ${PHPIZE_DEPS}
pecl install phalcon
docker-php-ext-enable phalcon

Check if extension was enabled:

php --ri phalcon

with next output:

/var/www/html # php --ri phalcon

phalcon


Phalcon is a full stack PHP framework, delivered as a PHP extension, offering lower resource consumption and high performance.
phalcon => enabled
Author => Phalcon Team and contributors
Version => 5.2.1
Build Date => Jun  3 2023 14:33:36
Powered by Zephir => Version 0.17.0-$Id$

If you want to speed up compilation, set env variable with number of CPU cores of your compilation machine (before pecl install command):

export MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"

Jeckerson avatar Jun 03 '23 14:06 Jeckerson

Hi, propably i have the same problem.

Building phalcon in docker stop working this days. And Iam sure, that cca one week before everything works and i dont make any changes in docker file.

Commands @Jeckerson write...

docker run -it --rm php:8.2-fpm-alpine sh
apk update && apk add ${PHPIZE_DEPS}
pecl install phalcon
docker-php-ext-enable phalcon

...doesnt work now. Compilation failed with lot of errors.

I thing about some required libraries is missing or updated.

Druid33 avatar Dec 13 '24 14:12 Druid33

@Druid33 confirm on alpine. I'll try to investigate route of problem, for now you might change to php:8.2-fpm tag, as it successfully builds on Debian/Ubuntu.

Jeckerson avatar Dec 14 '24 12:12 Jeckerson

Sorry guys, but this is still a bug/ missing requirement. Using Alpine makes imposible to install phalcon. I've tried with updated versions: Phalcon 5.9.2 and PHP 8.4.6

FROM php:8.4.6-fpm-alpine

ENV PHALCON_VERSION=5.9.2

# Install dependencies
RUN apk update && apk add --no-cache \
  nginx \
  supervisor \
  zlib-dev \
  libzip-dev \
  libpng-dev \
  gettext \
  libcap2 \
  pkgconf \
  php-pear \
  autoconf \
  make \
  g++ \
  gcc \
  libtool \
  re2c \
  file \
  libstdc++ \
  pcre-dev \
  yaml-dev \
  curl-dev \
  libxml2-dev \
  openssl-dev \
  libcurl \
  oniguruma-dev

RUN apk add --no-cache ${PHPIZE_DEPS}

RUN pear channel-update pecl.php.net

# Install Phalcon extension
RUN pecl install phalcon-${PHALCON_VERSION} && docker-php-ext-enable phalcon

It's result has tons of errors about unexpected macro(s) during phalcon install:

       → /usr/local/include/php/Zend/zend_API.h:2300:76: note: expected 'zend_string **' {aka 'struct _zend_string **'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
       →  2300 | static zend_always_inline bool zend_parse_arg_str(zval *arg, zend_string **dest, bool check_null, uint32_t arg_num)
       →       |                                                              ~~~~~~~~~~~~~~^~~~
       → /tmp/pear/temp/phalcon/phalcon.zep.c: In function 'zim_Phalcon_Encryption_Security_JWT_Token_Token_verify':
       → /usr/local/include/php/Zend/zend_API.h:2080:58: error: passing argument 2 of 'zend_parse_arg_str' from incompatible pointer type [-Wincompatible-pointer-types]
       →  2080 |                 if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null, _i))) { \
       → /usr/local/include/php/Zend/zend_portability.h:387:52: note: in definition of macro 'UNEXPECTED'
       →   387 | # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0)
       →       |                                                    ^~~~~~~~~
       → /usr/local/include/php/Zend/zend_API.h:2087:9: note: in expansion of macro 'Z_PARAM_STR_EX'
       →  2087 |         Z_PARAM_STR_EX(dest, 0, 0)
       →       |         ^~~~~~~~~~~~~~
       → /tmp/pear/temp/phalcon/phalcon.zep.c:206811:17: note: in expansion of macro 'Z_PARAM_STR'
       → 206811 |                 Z_PARAM_STR(key)
       →        |                 ^~~~~~~~~~~
       → /usr/local/include/php/Zend/zend_API.h:2300:76: note: expected 'zend_string **' {aka 'struct _zend_string **'} but argument is of type 'zval *' {aka 'struct _zval_struct *'}
       →  2300 | static zend_always_inline bool zend_parse_arg_str(zval *arg, zend_string **dest, bool check_null, uint32_t arg_num)
       →       |                                                              ~~~~~~~~~~~~~~^~~~
       → /tmp/pear/temp/phalcon/phalcon.zep.c: In function 'php_zephir_init_globals':
       → /tmp/pear/temp/phalcon/phalcon.zep.c:208204:57: error: assignment to 'zend_string *' {aka 'struct _zend_string *'} from incompatible pointer type 'char *' [-Wincompatible-pointer-types]
       → 208204 |         phalcon_globals->orm.resultset_prefetch_records = ZSTR_VAL(zend_string_init(ZEND_STRL("0"), 0));
       →        |                                                         ^
       → make: *** [Makefile:208: phalcon.lo] Error 1
       → ERROR: `make' failed
     
     ERROR IN: [ 5/26] RUN pecl install phalcon-5.9.2 && docker-php-ext-enable phalcon

got unexpected error during build/deploy: ImageBuild: process "/bin/sh -c pecl install phalcon-${PHALCON_VERSION} && docker-php-ext-enable phalcon" did not complete successfully: exit code: 1
Build Failed: ImageBuild: process "/bin/sh -c pecl install phalcon-${PHALCON_VERSION} && docker-php-ext-enable phalcon" did not complete successfully: exit code: 1

daniel-ionita-gl avatar Apr 20 '25 20:04 daniel-ionita-gl