phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.77k stars 1.97k forks source link

Alpine builds on Docker fail #16327

Closed FaimMedia closed 1 year ago

FaimMedia commented 1 year ago

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

yesworld commented 1 year ago

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

Nazariy commented 1 year ago

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.

Jeckerson commented 1 year ago

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)"