Skip to content

Commit b6938e4

Browse files
KingPinKingPin
authored andcommitted
fix(dockerfile): add retry logic for install-php-extensions download in v1
Adds 3-attempt retry loop with 5s/10s/20s exponential backoff for: 1. install-php-extensions script download from GitHub 2. PHP extension compilation and installation This addresses transient network timeouts that occur on both Alpine and Debian builds. The retry logic handles: - Network timeouts during curl download - Compilation/installation failures due to transient issues - Clear logging of retry attempts and failures Each layer has independent retry loops for robustness.
1 parent 9caf66b commit b6938e4

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

Dockerfile.v1

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,39 @@ RUN if [ "$BASEOS" = "bullseye" ]; then \
2424
apk add --no-cache curl git zip unzip ghostscript imagemagick optipng gifsicle pngcrush jpegoptim libjpeg-turbo libjpeg-turbo-utils pngquant libwebp-tools; \
2525
fi
2626

27-
# Add all needed PHP extensions
28-
RUN curl -sSLf -o /usr/local/bin/install-php-extensions \
29-
https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \
30-
chmod +x /usr/local/bin/install-php-extensions && \
31-
install-php-extensions amqp bcmath bz2 calendar ctype exif intl imagick imap json mbstring ldap mcrypt memcached mongodb \
32-
mysqli opcache pdo_mysql pdo_pgsql pgsql redis snmp soap sockets tidy timezonedb uuid vips xsl yaml zip zstd @composer
27+
# Add all needed PHP extensions with retry logic for transient network failures
28+
RUN for ATTEMPT in 1 2 3; do \
29+
if curl -sSLf -o /usr/local/bin/install-php-extensions \
30+
https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions; then \
31+
break; \
32+
else \
33+
if [ $ATTEMPT -lt 3 ]; then \
34+
SLEEP_TIME=$((5 * 2 ** (ATTEMPT - 1))); \
35+
echo "Download attempt $ATTEMPT failed, retrying in ${SLEEP_TIME}s..."; \
36+
sleep $SLEEP_TIME; \
37+
rm -f /usr/local/bin/install-php-extensions; \
38+
else \
39+
echo "Failed to download install-php-extensions after 3 attempts"; \
40+
exit 1; \
41+
fi; \
42+
fi; \
43+
done && \
44+
chmod +x /usr/local/bin/install-php-extensions && \
45+
for ATTEMPT in 1 2 3; do \
46+
if install-php-extensions amqp bcmath bz2 calendar ctype exif intl imagick imap json mbstring ldap mcrypt memcached mongodb \
47+
mysqli opcache pdo_mysql pdo_pgsql pgsql redis snmp soap sockets tidy timezonedb uuid vips xsl yaml zip zstd @composer; then \
48+
break; \
49+
else \
50+
if [ $ATTEMPT -lt 3 ]; then \
51+
SLEEP_TIME=$((5 * 2 ** (ATTEMPT - 1))); \
52+
echo "Extension installation attempt $ATTEMPT failed, retrying in ${SLEEP_TIME}s..."; \
53+
sleep $SLEEP_TIME; \
54+
else \
55+
echo "Failed to install PHP extensions after 3 attempts"; \
56+
exit 1; \
57+
fi; \
58+
fi; \
59+
done
3360

3461
# Enable Apache rewrite mod, if applicable
3562
RUN if command -v a2enmod; then a2enmod rewrite; fi

0 commit comments

Comments
 (0)