# Stage n°1: builder. # Cette étape ne sert qu'à l'installation et la compilation des extensions php. # Une fois fait, on copie les fichiers compilés vers le stage base, # et on supprime celui-là qui n'est donc plus utile, on gagne à peu près ~653MB. FROM php:8.5.4-fpm-alpine AS builder # Utilisation de l'image docker php:8.5.4-fpm-alpine: https://hub.docker.com/layers/library/php/8.5.4-fpm-alpine/images # Bien plus légère que l'ancienne image php:8.5.4-apache-trixie. # Récupération de la valeur de l'argument passé lors de la commande pour utiliser notre proxy. ARG http_proxy # Définit des variables d'environnement dans l'image sous plusieurs formats car ça peu varier selon les outils. ENV http_proxy=${http_proxy} \ https_proxy=${http_proxy} \ HTTP_PROXY=${http_proxy} \ HTTPS_PROXY=${http_proxy} # Installation des packages nécessaires à la compilation des extensions php. RUN apk add --no-cache \ unzip \ freetype-dev jpeg-dev libpng-dev libwebp-dev libxpm-dev \ zlib-dev icu-dev libxslt-dev libzip-dev \ imagemagick-dev \ libmemcached-dev cyrus-sasl-dev \ openldap-dev \ oniguruma-dev gettext-dev gmp-dev \ linux-headers \ g++ autoconf libtool pkgconfig alpine-sdk # Installation des extensions php natives. RUN docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype \ && docker-php-ext-configure zip --with-zip \ && docker-php-ext-install -j"$(nproc)" \ exif \ gd \ gettext \ intl \ mysqli \ pdo_mysql \ xsl \ zip \ bcmath \ ldap \ gmp # PECL maintenant déprécié, on installe directement les extensions souhaitée depuis github. RUN \ curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.8.1.tar.gz -o /tmp/imagick.tar.gz & \ curl -fsSL https://github.com/php-memcached-dev/php-memcached/archive/refs/tags/v3.4.0.tar.gz -o /tmp/memcached.tar.gz & \ curl -fsSL https://github.com/phpredis/phpredis/archive/refs/tags/6.3.0.tar.gz -o /tmp/redis.tar.gz & \ curl -fsSL https://github.com/xdebug/xdebug/archive/refs/tags/3.5.1.tar.gz -o /tmp/xdebug.tar.gz & \ curl -fsSL https://github.com/krakjoe/pcov/archive/refs/tags/v1.0.12.tar.gz -o /tmp/pcov.tar.gz & \ wait \ \ && tar -xzf /tmp/imagick.tar.gz -C /tmp \ && cd /tmp/imagick-3.8.1 \ && phpize && ./configure && make -j"$(nproc)" && make install \ && rm -rf /tmp/imagick* \ \ && tar -xzf /tmp/memcached.tar.gz -C /tmp \ && cd /tmp/php-memcached-3.4.0 \ && phpize && ./configure && make -j"$(nproc)" && make install \ && rm -rf /tmp/memcached* \ \ && tar -xzf /tmp/redis.tar.gz -C /tmp \ && cd /tmp/phpredis-6.3.0 \ && phpize && ./configure && make -j"$(nproc)" && make install \ && rm -rf /tmp/redis* \ \ && tar -xzf /tmp/xdebug.tar.gz -C /tmp \ && cd /tmp/xdebug-3.5.1 \ && phpize && ./configure && make -j"$(nproc)" && make install \ && rm -rf /tmp/xdebug* \ \ && tar -xzf /tmp/pcov.tar.gz -C /tmp \ && cd /tmp/pcov-1.0.12 \ && phpize && ./configure && make -j"$(nproc)" && make install \ && rm -rf /tmp/pcov* # Installation composer + Installation bun (sous alpine). RUN curl -fsSL https://getcomposer.org/installer -o /tmp/composer-installer & \ curl -fsSL -o /tmp/bun.zip "https://github.com/oven-sh/bun/releases/download/bun-v1.2.10/bun-linux-x64-musl.zip" & \ wait \ \ && php /tmp/composer-installer --install-dir=/usr/local/bin --filename=composer --version=2.9.7 \ \ && rm /tmp/composer-installer \ && unzip -oqd /tmp/bun-extracted /tmp/bun.zip \ && mv $(find /tmp/bun-extracted -type f -name 'bun' -perm /a+x | head -n1) /usr/local/bin/bun \ && chmod +x /usr/local/bin/bun \ && rm -rf /tmp/bun.zip /tmp/bun-extracted # Stage n°2: base. # Image finale qui sera utilisée sans compilateurs. FROM php:8.5.4-fpm-alpine AS base # Récupération de la valeur de l'argument passé lors de la commande pour utiliser notre proxy. ARG http_proxy # Définit des variables d'environnement dans l'image sous plusieurs formats car ça peu varier selon les outils. ENV http_proxy=${http_proxy} \ https_proxy=${http_proxy} \ HTTP_PROXY=${http_proxy} \ HTTPS_PROXY=${http_proxy} \ LC_ALL=fr_FR.UTF-8 \ LANG=fr_FR.UTF-8 \ LANGUAGE=fr_FR.UTF-8:fr \ SHELL=/bin/zsh # Installation des packages runtime + utilitaires + outils QA. RUN apk add --no-cache \ ca-certificates curl \ git unzip zip nano vim zsh htop \ apache2 apache2-proxy apache2-http2 apache2-ssl apache2-brotli \ nodejs npm \ freetype libjpeg libpng libwebp libxpm \ icu-libs libxslt libzip \ imagemagick \ libcurl libmemcached \ libldap \ musl-locales musl-locales-lang \ mariadb-client \ oniguruma \ shadow man-db \ gmp gettext-libs \ zsh-vcs # Copie des extensions compilées depuis le stage builder. COPY --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/ COPY --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/ COPY --from=builder /usr/local/bin/composer /usr/local/bin/composer COPY --from=builder /usr/local/bin/bun /usr/local/bin/bun # Active les extensions PECL copiées + supprime xdebug.ini auto-généré car on veut utiliser notre propre fichier de config. RUN docker-php-ext-enable imagick memcached redis xdebug pcov \ && rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && mkdir -p /app/logs && chmod 777 /app/logs # Installation omzsh + plugin + theme. RUN sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" \ && git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions \ && sed -i 's/plugins=(git)/plugins=(git laravel zsh-autosuggestions)/g' ~/.zshrc \ && sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="agnoster"/g' ~/.zshrc \ && chsh -s /bin/zsh # Configuration des modules apache sans duplication (par défaut dans alpine c'est commenté, on décommente juste ce dont on a besoin), # + supprime ssl.conf auto-généré car on veut utiliser notre propre fichier de config. RUN sed -i \ -e 's/#LoadModule proxy_module/LoadModule proxy_module/' \ -e 's/#LoadModule proxy_fcgi_module/LoadModule proxy_fcgi_module/' \ -e 's/#LoadModule rewrite_module/LoadModule rewrite_module/' \ -e 's/#LoadModule remoteip_module/LoadModule remoteip_module/' \ -e 's/#LoadModule headers_module/LoadModule headers_module/' \ -e 's/#LoadModule http2_module/LoadModule http2_module/' \ -e 's/#LoadModule expires_module/LoadModule expires_module/' \ -e 's/#LoadModule deflate_module/LoadModule deflate_module/' \ -e 's/#LoadModule mime_module/LoadModule mime_module/' \ -e 's/#LoadModule brotli_module/LoadModule brotli_module/' \ -e 's/^Listen 80/#Listen 80/' \ /etc/apache2/httpd.conf \ \ && rm -f /etc/apache2/conf.d/ssl.conf # Copie des fichiers de configuration. COPY conf/php.ini /usr/local/etc/php/conf.d/app.ini COPY conf/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini COPY conf/vhost.conf /etc/apache2/conf.d/vhost.conf COPY conf/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf COPY conf/common-apache.conf /etc/apache2/conf.d/z-app.conf COPY conf/common-ports.conf /etc/apache2/conf.d/ports.conf COPY conf/common-security.conf /etc/apache2/conf.d/security.conf # Définit le répertoire de travail par défaut dans le conteneur. WORKDIR /app/srcs # Entrypoint custom pour démarrer php-fpm et apache (en executable seule). COPY --chmod=755 conf/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]