fix(docker): enhance PHP extension installation with retry logic and use prebuilt binaries

This commit is contained in:
hamed
2026-06-28 10:09:32 +03:30
parent 26fe7c4fc0
commit 8ae35b1c8f
+12 -9
View File
@@ -33,17 +33,20 @@ FROM php:8.2-fpm-alpine AS runtime
# System deps + PHP extensions.
# pdo_mysql -> MariaDB, intl -> Symfony, opcache -> perf, redis -> Messenger/cache transport
# apk/pecl fetch over the network; on busy build hosts the mirror occasionally
# drops a connection. retry() wraps each network step so a transient failure
# doesn't abort the whole deploy.
#
# Extensions are installed via mlocati/install-php-extensions, which fetches
# PREBUILT binaries instead of compiling from source. The previous approach
# (pecl install redis + docker-php-ext-install) compiled redis/intl/pdo_mysql
# on every build — minutes of CPU that intermittently overran Coolify's build
# timeout (exit 255). The prebuilt path is seconds and needs no .build-deps.
RUN set -eu; \
retry() { for i in 1 2 3 4 5; do "$@" && return 0; echo "retry $i: $*"; sleep 5; done; return 1; }; \
retry apk add --no-cache nginx supervisor icu-libs \
&& retry apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev \
&& docker-php-ext-install pdo_mysql intl opcache \
&& retry pecl install redis \
&& docker-php-ext-enable redis \
&& apk del .build-deps
retry apk add --no-cache nginx supervisor \
&& retry curl -sSLf https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions \
-o /usr/local/bin/install-php-extensions \
&& chmod +x /usr/local/bin/install-php-extensions \
&& install-php-extensions pdo_mysql intl opcache redis \
&& rm -f /usr/local/bin/install-php-extensions
WORKDIR /app