From 5319ceff2f91da0067574fba2b656d08f164bb9c Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 13 Apr 2026 17:05:56 +0200 Subject: [PATCH 01/10] =?UTF-8?q?fix:=20=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB?= =?UTF-8?q?=20update=20build=20time=20and=20size=20of=20dev=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP8.5/DEV/Dockerfile | 250 +++++++++++++++++---------- PHP8.5/DEV/conf/common-apache.conf | 4 +- PHP8.5/DEV/conf/common-ports.conf | 1 - PHP8.5/DEV/conf/docker-entrypoint.sh | 13 ++ PHP8.5/DEV/conf/php-fpm.conf | 24 +++ PHP8.5/DEV/conf/vhost.conf | 21 ++- 6 files changed, 208 insertions(+), 105 deletions(-) create mode 100644 PHP8.5/DEV/conf/docker-entrypoint.sh create mode 100644 PHP8.5/DEV/conf/php-fpm.conf diff --git a/PHP8.5/DEV/Dockerfile b/PHP8.5/DEV/Dockerfile index a489edd..7523775 100644 --- a/PHP8.5/DEV/Dockerfile +++ b/PHP8.5/DEV/Dockerfile @@ -1,114 +1,178 @@ -FROM php:8.5.4-apache-trixie - -ENV DEBIAN_FRONTEND=noninteractive +# 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 -ENV http_proxy=${http_proxy} -ENV https_proxy=${http_proxy} -ENV HTTP_PROXY=${http_proxy} -ENV HTTPS_PROXY=${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} -# Install system dependencies and PHP extensions -RUN apt-get update -qq && \ - apt-get install -qy --no-install-recommends \ - nano vim \ - libfreetype6-dev libjpeg62-turbo-dev libpng-dev libwebp-dev libxpm-dev \ - zlib1g-dev libicu-dev g++ \ - libxslt-dev \ - libzip-dev unzip zip \ - libmagick++-dev libmagickwand-dev imagemagick \ - libcurl4-openssl-dev \ - libmemcached-dev \ - ldap-utils libldap2-dev \ - locales \ - git zsh htop \ - ca-certificates curl gnupg \ - mariadb-client \ - libonig-dev \ - build-essential pkg-config autoconf libtool \ - && echo "fr_FR.UTF-8 UTF-8" > /etc/locale.gen \ - && locale-gen fr_FR.UTF-8 \ - && dpkg-reconfigure locales \ - && /usr/sbin/update-locale LANG=fr_FR.UTF-8 +# 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 + && 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 PROXY HACK -RUN if [ -n "${http_proxy}" ]; then \ - pear config-set http_proxy "${http_proxy}"; \ - fi +# 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* -# PECL EXTENSIONS -RUN pecl channel-update pecl.php.net \ - && pecl install imagick-3.8.1 redis-6.3.0 \ - && docker-php-ext-enable imagick redis +# 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 -RUN pecl install xdebug pcov \ - && docker-php-ext-enable xdebug pcov +# Stage n°2: base. +# Image finale qui sera utilisée sans compilateurs. +FROM php:8.5.4-fpm-alpine AS base -# CLEAN UP XDEBUG ENABLE -RUN rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +# Récupération de la valeur de l'argument passé lors de la commande pour utiliser notre proxy. +ARG http_proxy -# CLEANUP -RUN apt-get clean \ - && apt-get purge -y --auto-remove build-essential pkg-config autoconf \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +# 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 -# Set locale environment variables -ENV LC_ALL=fr_FR.UTF-8 -ENV LANG=fr_FR.UTF-8 -ENV LANGUAGE=fr_FR.UTF-8:fr +# 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 -# Install Node.js 24.x -RUN mkdir -p /etc/apt/keyrings \ - && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ - && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \ - && apt-get update -qq \ - && apt-get install -y --no-install-recommends nodejs \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* +# 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 -# Install Bun -RUN set -eux; \ - dir="${BUN_INSTALL:-$HOME/.bun}/bin"; mkdir -p "$dir"; \ - url="https://github.com/oven-sh/bun/releases/latest/download/bun-linux-x64.zip"; \ - curl -fsSL -o /tmp/bun.zip "$url"; \ - unzip -oqd "$dir" /tmp/bun.zip; \ - bunbin=$(find "$dir" -type f -name 'bun*' -perm /a+x | head -n1); \ - [ -n "$bunbin" ] && mv -f "$bunbin" "$dir/bun"; \ - chmod +x "$dir/bun" || true; \ - rm -f /tmp/bun.zip; \ - ln -sf "$dir/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 -# Install Composers -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.9.5 - -# Setup Oh-My-Zsh and plugins (dev only) +# Installation omzsh + plugin + theme. RUN sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" \ - && git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions \ + && 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 + && sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="agnoster"/g' ~/.zshrc \ + && chsh -s /bin/zsh -ENV SHELL=/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 -# Set default shell to zsh -RUN chsh -s /bin/zsh +# 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 -# Copy configuration files -COPY conf/common-apache.conf /etc/apache2/conf-available/z-app.conf -COPY conf/common-ports.conf /etc/apache2/ports.conf -COPY conf/common-security.conf /etc/apache2/conf-enabled/security.conf -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/sites-available/000-default.conf - -# Enable Apache modules and configuration -RUN a2enmod rewrite remoteip headers http2 && \ - a2enconf z-app - -# XDEBUG LOGS -RUN mkdir -p /app/logs/ +# 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"] \ No newline at end of file diff --git a/PHP8.5/DEV/conf/common-apache.conf b/PHP8.5/DEV/conf/common-apache.conf index c2b8a3e..5c1f03f 100644 --- a/PHP8.5/DEV/conf/common-apache.conf +++ b/PHP8.5/DEV/conf/common-apache.conf @@ -73,7 +73,6 @@ AccessFileName .htaccess # DefaultType None - # # HostnameLookups: Log the names of clients or just their IP addresses # e.g., www.apache.org (on) or 204.62.129.132 (off). @@ -89,8 +88,9 @@ HostnameLookups Off # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a # container, that host's errors will be logged there and not here. +# APACHE_LOG_DIR n'existe pas sous alpine. # -ErrorLog ${APACHE_LOG_DIR}/error.log +ErrorLog /var/log/apache2/error.log # # LogLevel: Control the number of messages logged to the error_log. diff --git a/PHP8.5/DEV/conf/common-ports.conf b/PHP8.5/DEV/conf/common-ports.conf index d48cbbd..6f0083f 100644 --- a/PHP8.5/DEV/conf/common-ports.conf +++ b/PHP8.5/DEV/conf/common-ports.conf @@ -2,7 +2,6 @@ # have to change the VirtualHost statement in # /etc/apache2/sites-enabled/000-default.conf -#Listen 80 Listen 443 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet \ No newline at end of file diff --git a/PHP8.5/DEV/conf/docker-entrypoint.sh b/PHP8.5/DEV/conf/docker-entrypoint.sh new file mode 100644 index 0000000..83ec6d5 --- /dev/null +++ b/PHP8.5/DEV/conf/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +mkdir -p /app/logs + +# Vérifier la config php-fpm. +php-fpm -t + +# Démarrer php-fpm en arrière-plan. +php-fpm -D + +# Démarrer apache au premier plan. +exec httpd -D FOREGROUND \ No newline at end of file diff --git a/PHP8.5/DEV/conf/php-fpm.conf b/PHP8.5/DEV/conf/php-fpm.conf new file mode 100644 index 0000000..d4803dc --- /dev/null +++ b/PHP8.5/DEV/conf/php-fpm.conf @@ -0,0 +1,24 @@ +[global] +; Fait en sorte que php fpm reste au premier plan et soit toujours géré par docker. +daemonize = no + +[www] +; Utilisateur par défaut sous alpine. +user = nobody +group = nobody + +; Localhost + port par défaut de php-fpm. +listen = 127.0.0.1:9000 + +; Gestion des processus nécéssaire au bon fonctionnement de php-fpm: +pm = dynamic ; Type de processus. +pm.max_children = 20 ; Nombre maximum de processus en même temps. +pm.start_servers = 4 ; Nombre de processus créés au démarrage. +pm.min_spare_servers = 2 ; Minimum de processus en attente. +pm.max_spare_servers = 6 ; Maximum de processus en attente. + +; Directives php définies dans le scope php-fpm et pas apache. +; Anciennement définies dans le vhost avec le module mod_php. +php_admin_value[open_basedir] = /usr/local/bin/php:/app/srcs/:/app/tmp/ +php_admin_value[upload_tmp_dir] = /app/tmp +php_admin_value[error_log] = /app/logs/app_error_${PROJECT}.log \ No newline at end of file diff --git a/PHP8.5/DEV/conf/vhost.conf b/PHP8.5/DEV/conf/vhost.conf index f15297b..19c8972 100644 --- a/PHP8.5/DEV/conf/vhost.conf +++ b/PHP8.5/DEV/conf/vhost.conf @@ -1,18 +1,21 @@ Protocols h2 h2c http/1.1 - ServerAdmin contact@ldc.fr - DocumentRoot /app/${DOCUMENTROOT} + ServerAdmin digital@ldc.fr + DocumentRoot /app${DOCUMENTROOT} + DirectoryIndex index.php index.html - + # Anciennement activé par défaut via le module d'apachemod_proxy_fcgi, + # sur alpine, on doit l'écrire (php-fpm sur le port 9000). + + SetHandler "proxy:fcgi://127.0.0.1:9000" + + + Options +MultiViews -Indexes +FollowSymLinks AllowOverride All Require all granted - - php_admin_value open_basedir "/usr/local/bin/php:/app/srcs/:/app/tmp/" - php_admin_value upload_tmp_dir /app/tmp - php_admin_value error_log /app/logs/app_error_${PROJECT}.log - ErrorLog /app/logs/error_${PROJECT}.log - CustomLog /app/logs/access_${PROJECT}.log combined + ErrorLog /app/logs/error_${PROJECT}.log + CustomLog /app/logs/access_${PROJECT}.log combined \ No newline at end of file From 8cafe3320a3dfabb27557b47889b6c9c38dd8124 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 1 Jun 2026 16:48:34 +0200 Subject: [PATCH 02/10] =?UTF-8?q?fix:=20=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB?= =?UTF-8?q?=20update=20build=20time=20and=20size=20of=20prod=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP8.5/PROD/Dockerfile | 204 ++++++++++++++++---------- PHP8.5/PROD/conf/common-apache.conf | 7 +- PHP8.5/PROD/conf/docker-entrypoint.sh | 13 ++ PHP8.5/PROD/conf/php-fpm.conf | 24 +++ PHP8.5/PROD/conf/vhost.conf | 15 +- 5 files changed, 173 insertions(+), 90 deletions(-) create mode 100644 PHP8.5/PROD/conf/docker-entrypoint.sh create mode 100644 PHP8.5/PROD/conf/php-fpm.conf diff --git a/PHP8.5/PROD/Dockerfile b/PHP8.5/PROD/Dockerfile index 05c3f1b..4d128c9 100644 --- a/PHP8.5/PROD/Dockerfile +++ b/PHP8.5/PROD/Dockerfile @@ -1,98 +1,144 @@ -FROM php:8.5.4-apache-trixie +# 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 ~574MB. +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 -ENV http_proxy=${http_proxy} -ENV https_proxy=${http_proxy} -ENV HTTP_PROXY=${http_proxy} -ENV HTTPS_PROXY=${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} -RUN apt-get update -qq && \ - apt-get install -qy \ - # Common - nano \ - vim \ - # GD - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libwebp-dev \ - libxpm-dev \ - # INTL - zlib1g-dev libicu-dev g++ \ - # XSL - libxslt-dev \ - # ZIP - libzip-dev \ - unzip \ +# Installation des packages nécessaires à la compilation des extensions php. +RUN apk add --no-cache \ + 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 \ - # Imagick - libmagick++-dev \ - libmagickwand-dev \ - #GMP - libgmp-dev \ - # Memcached - libmemcached-dev \ - # ldap - ldap-utils libldap2-dev \ - # locales - locales \ - # libcap - libcap2-bin && \ - rm -rf /var/cache/apt + bcmath \ + ldap \ + gmp -# LOCALES -ENV DEBIAN_FRONTEND=noninteractive -RUN echo "fr_FR.UTF-8 UTF-8" > /etc/locale.gen && \ - locale-gen fr_FR.UTF-8 && \ - dpkg-reconfigure locales && \ - /usr/sbin/update-locale LANG fr_FR.UTF-8 -ENV LC_ALL=fr_FR.UTF-8 -ENV LANG=fr_FR.UTF-8 -ENV LANGUAGE=fr_FR.UTF-8:fr -# END LOCALES +# PECL maintenant déprécié, on installe directement les extensions souhaitées depuis github. +RUN \ + curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.8.1.tar.gz -o /tmp/imagick.tar.gz \ + && 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* \ + \ + && curl -fsSL https://github.com/php-memcached-dev/php-memcached/archive/refs/tags/v3.4.0.tar.gz -o /tmp/memcached.tar.gz \ + && 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* \ + \ + && curl -fsSL https://github.com/phpredis/phpredis/archive/refs/tags/6.3.0.tar.gz -o /tmp/redis.tar.gz \ + && 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* -RUN docker-php-ext-configure gd \ - --enable-gd \ - --with-webp \ - --with-jpeg \ - --with-xpm \ - --with-freetype +# Stage n°2: base. +# Image finale qui sera utilisée sans compilateurs. +FROM php:8.5.4-fpm-alpine AS base -RUN docker-php-ext-configure intl -RUN docker-php-ext-configure zip --with-zip -RUN docker-php-ext-configure ldap -RUN docker-php-ext-install exif gd gettext intl mysqli pdo_mysql xsl zip bcmath ldap gmp +# Récupération de la valeur de l'argument passé lors de la commande pour utiliser notre proxy. +ARG http_proxy -# PECL PROXY HACK -RUN if [ -n "${http_proxy}" ]; then \ - pear config-set http_proxy "${http_proxy}"; \ - fi +# 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 -RUN pecl channel-update pecl.php.net -RUN pecl install imagick-3.8.1 && docker-php-ext-enable imagick -RUN pecl install memcached-3.4.0 && docker-php-ext-enable memcached -RUN pecl install redis-6.3.0 && docker-php-ext-enable redis +# Installation des packages runtime + utilitaires + outils QA. +RUN apk add --no-cache \ + ca-certificates curl \ + git unzip zip \ + apache2 apache2-proxy apache2-http2 apache2-ssl apache2-brotli \ + freetype libjpeg libpng libwebp libxpm \ + icu-libs libxslt libzip \ + imagemagick \ + libmemcached \ + libldap \ + musl-locales musl-locales-lang \ + mariadb-client \ + oniguruma \ + gmp gettext-libs -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +# 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 conf/common-apache.conf /etc/apache2/conf-available/z-app.conf -COPY conf/common-ports.conf /etc/apache2/ports.conf -COPY conf/common-security.conf /etc/apache2/conf-enabled/security.conf +# Active les extensions PECL copiées. +RUN docker-php-ext-enable imagick memcached redis -COPY conf/php.ini /usr/local/etc/php/php.ini +# Installation composer. +RUN curl -fsSL https://getcomposer.org/installer \ + | php -- --install-dir=/usr/local/bin --filename=composer --version=2.9.5 -COPY conf/vhost.conf /etc/apache2/sites-available/000-default.conf +# Configuration des modules apache sans duplication. +# Par défaut dans alpine c'est commenté, on décommente juste ce dont on a besoin. +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 -RUN a2enmod rewrite remoteip headers http2 expires deflate mime brotli && \ - a2enconf z-app +# Copie des fichiers de configuration. +COPY conf/php.ini /usr/local/etc/php/conf.d/app.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 -RUN mkdir -p /app/tmp && chmod -R 770 /app/tmp && chown -R www-data:www-data /app +# Supprime ssl.conf auto-généré car on veut utiliser notre propre fichier de config. +RUN rm -f /etc/apache2/conf.d/ssl.conf -#Change access righs to conf, logs, bin from root to www-data -RUN chown -hR www-data:www-data /var/log/apache2 -#setcap to bind to privileged ports as non-root -RUN setcap 'cap_net_bind_service=+ep' /usr/sbin/apache2 +# Création des répertoires avec les bons droits. +RUN mkdir -p /app/tmp /app/logs /app/srcs \ + && chown -R apache:apache /app \ + && chmod 770 /app/tmp /app/logs -USER www-data +# 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"] \ No newline at end of file diff --git a/PHP8.5/PROD/conf/common-apache.conf b/PHP8.5/PROD/conf/common-apache.conf index c2b8a3e..1f9a295 100644 --- a/PHP8.5/PROD/conf/common-apache.conf +++ b/PHP8.5/PROD/conf/common-apache.conf @@ -89,8 +89,9 @@ HostnameLookups Off # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a # container, that host's errors will be logged there and not here. +# APACHE_LOG_DIR n'existe pas sous alpine. # -ErrorLog ${APACHE_LOG_DIR}/error.log +ErrorLog /var/log/apache2/error.log # # LogLevel: Control the number of messages logged to the error_log. @@ -108,7 +109,3 @@ SetEnvIf Request_URI "^/haproxytest\.txt$" dontlog SetEnvIf Request_URI "^check_http" dontlog SetEnvIf Remote_Addr "127.0.0.1" dontlog SetEnvIf Remote_Addr "::1" dontlog - -# Include generic snippets of statements -SetEnvIf Remote_Addr "127\.0\.0\.1" loopback -SetEnvIf Request_URI "^/haproxytest\.txt$" dontlog \ No newline at end of file diff --git a/PHP8.5/PROD/conf/docker-entrypoint.sh b/PHP8.5/PROD/conf/docker-entrypoint.sh new file mode 100644 index 0000000..83ec6d5 --- /dev/null +++ b/PHP8.5/PROD/conf/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +mkdir -p /app/logs + +# Vérifier la config php-fpm. +php-fpm -t + +# Démarrer php-fpm en arrière-plan. +php-fpm -D + +# Démarrer apache au premier plan. +exec httpd -D FOREGROUND \ No newline at end of file diff --git a/PHP8.5/PROD/conf/php-fpm.conf b/PHP8.5/PROD/conf/php-fpm.conf new file mode 100644 index 0000000..d4803dc --- /dev/null +++ b/PHP8.5/PROD/conf/php-fpm.conf @@ -0,0 +1,24 @@ +[global] +; Fait en sorte que php fpm reste au premier plan et soit toujours géré par docker. +daemonize = no + +[www] +; Utilisateur par défaut sous alpine. +user = nobody +group = nobody + +; Localhost + port par défaut de php-fpm. +listen = 127.0.0.1:9000 + +; Gestion des processus nécéssaire au bon fonctionnement de php-fpm: +pm = dynamic ; Type de processus. +pm.max_children = 20 ; Nombre maximum de processus en même temps. +pm.start_servers = 4 ; Nombre de processus créés au démarrage. +pm.min_spare_servers = 2 ; Minimum de processus en attente. +pm.max_spare_servers = 6 ; Maximum de processus en attente. + +; Directives php définies dans le scope php-fpm et pas apache. +; Anciennement définies dans le vhost avec le module mod_php. +php_admin_value[open_basedir] = /usr/local/bin/php:/app/srcs/:/app/tmp/ +php_admin_value[upload_tmp_dir] = /app/tmp +php_admin_value[error_log] = /app/logs/app_error_${PROJECT}.log \ No newline at end of file diff --git a/PHP8.5/PROD/conf/vhost.conf b/PHP8.5/PROD/conf/vhost.conf index 6ceed68..61e7060 100644 --- a/PHP8.5/PROD/conf/vhost.conf +++ b/PHP8.5/PROD/conf/vhost.conf @@ -1,16 +1,19 @@ - Protocols h2c http/1.1 - ServerAdmin contact@ldc.fr + Protocols h2 h2c http/1.1 + ServerAdmin digital@ldc.fr DocumentRoot /app/srcs/public + DirectoryIndex index.php index.html + + # Anciennement activé par défaut via le module d'apachemod_proxy_fcgi, + # sur alpine, on doit l'écrire (php-fpm sur le port 9000). + + SetHandler "proxy:fcgi://127.0.0.1:9000" + Options +MultiViews -Indexes +FollowSymLinks AllowOverride All Require all granted - - php_admin_value open_basedir "/usr/local/bin/php:/app/srcs/:/app/tmp/" - php_admin_value upload_tmp_dir /app/tmp - SetEnvIf X_FORWARDED_PROTO https HTTPS=on \ No newline at end of file From 3a8d0a1635351cf4e369eb696e06397df27e7084 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 1 Jun 2026 16:48:59 +0200 Subject: [PATCH 03/10] =?UTF-8?q?fix:=20=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB?= =?UTF-8?q?=20update=20build=20time=20and=20size=20of=20qa=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP8.5/QA/Dockerfile | 185 +++++++++++++----------- PHP8.5/QA/{ => conf}/php-production.ini | 0 2 files changed, 101 insertions(+), 84 deletions(-) rename PHP8.5/QA/{ => conf}/php-production.ini (100%) diff --git a/PHP8.5/QA/Dockerfile b/PHP8.5/QA/Dockerfile index 04347ab..a4d44d0 100644 --- a/PHP8.5/QA/Dockerfile +++ b/PHP8.5/QA/Dockerfile @@ -1,101 +1,118 @@ -FROM php:8.5-cli-trixie +# 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 ~586MB. +FROM php:8.5.4-cli-alpine AS builder +# Utilisation de l'image docker php:8.5-cli-alpine: https://hub.docker.com/layers/library/php/8.5.4-cli-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 -ENV http_proxy=${http_proxy} -ENV https_proxy=${http_proxy} -ENV HTTP_PROXY=${http_proxy} -ENV HTTPS_PROXY=${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} -RUN apt-get update -qq && \ - apt-get install -qy \ - # Common - nano \ - vim \ - # GD - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libwebp-dev \ - libxpm-dev \ - # INTL - zlib1g-dev libicu-dev g++ \ - # XSL - libxslt-dev \ - # ZIP - libzip-dev \ - unzip \ +# Installation des packages nécessaires à la compilation des extensions php. +RUN apk add --no-cache \ + 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 \ - #GMP - libgmp-dev \ - # Imagick - libmagick++-dev \ - libmagickwand-dev \ - # Memcached - libmemcached-dev \ - # ldap - ldap-utils libldap2-dev \ - # locales - locales + bcmath \ + ldap \ + gmp -# LOCALES -ENV DEBIAN_FRONTEND=noninteractive -RUN echo "fr_FR.UTF-8 UTF-8" > /etc/locale.gen && \ - locale-gen fr_FR.UTF-8 && \ - dpkg-reconfigure locales && \ - /usr/sbin/update-locale LANG=fr_FR.UTF-8 -ENV LC_ALL=fr_FR.UTF-8 -ENV LANG=fr_FR.UTF-8 -ENV LANGUAGE=fr_FR.UTF-8:fr -# END LOCALES +# PECL maintenant déprécié, on installe directement les extensions souhaitées depuis github. +RUN \ + curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.8.1.tar.gz -o /tmp/imagick.tar.gz \ + && 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* \ + \ + && curl -fsSL https://github.com/php-memcached-dev/php-memcached/archive/refs/tags/v3.4.0.tar.gz -o /tmp/memcached.tar.gz \ + && 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* \ + \ + && curl -fsSL https://github.com/krakjoe/pcov/archive/refs/tags/v1.0.12.tar.gz -o /tmp/pcov.tar.gz \ + && 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* -RUN docker-php-ext-configure gd \ - --enable-gd \ - --with-webp \ - --with-jpeg \ - --with-xpm \ - --with-freetype +# Stage n°2: base. +# Image finale qui sera utilisée sans compilateurs. +FROM php:8.5.4-cli-alpine AS base -RUN docker-php-ext-configure intl -RUN docker-php-ext-configure zip --with-zip -RUN docker-php-ext-configure ldap -RUN docker-php-ext-install exif gd gettext intl mysqli pdo_mysql xsl zip bcmath ldap gmp +# Récupération de la valeur de l'argument passé lors de la commande pour utiliser notre proxy. +ARG http_proxy -# PECL PROXY HACK -RUN if [ -n "${http_proxy}" ]; then \ - pear config-set http_proxy "${http_proxy}"; \ - fi +# 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 -RUN pecl channel-update pecl.php.net +# Installation des packages runtime + utilitaires + outils QA. +RUN apk add --no-cache \ + ca-certificates curl \ + git unzip zip \ + freetype libjpeg libpng libwebp libxpm \ + icu-libs libxslt libzip \ + imagemagick \ + libmemcached \ + libldap \ + musl-locales musl-locales-lang \ + oniguruma \ + gmp gettext-libs \ + nodejs npm -RUN pecl install imagick-3.8.1 && docker-php-ext-enable imagick -RUN pecl install memcached-3.4.0 && docker-php-ext-enable memcached +# 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/ -# DEV -RUN apt-get install -qy git - -## DEPRECATED -> composer audit -# local-php-security-checker -RUN mkdir /tools && \ - curl -L https://github.com/fabpot/local-php-security-checker/releases/download/v2.0.4/local-php-security-checker_2.0.4_linux_amd64 -o /tools/local-php-security-checker && \ - chmod +x /tools/local-php-security-checker +# Active les extensions copiées. +RUN docker-php-ext-enable imagick memcached pcov +# Vérification des vulnérabilités avec local-php-security-checker (déprécié mais conservé pour compatibilité). +RUN mkdir /tools \ + && curl -fsSL https://github.com/fabpot/local-php-security-checker/releases/download/v2.0.4/local-php-security-checker_2.0.4_linux_amd64 \ + -o /tools/local-php-security-checker \ + && chmod +x /tools/local-php-security-checker ENV PATH="$PATH:/tools" -RUN pecl install pcov && docker-php-ext-enable pcov -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=2.9.5 -## NODE -> penser a bun -RUN apt-get update -qq && \ - apt-get install -qy \ - ca-certificates curl gnupg \ - && mkdir -p /etc/apt/keyrings \ - && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ - && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list -## END NODE -RUN apt-get update -qq && apt-get install -y nodejs && npm install -g audit-ci@^6 -#END DEV +# Installation composer. +RUN curl -fsSL https://getcomposer.org/installer \ + | php -- --install-dir=/usr/local/bin --filename=composer --version=2.9.5 -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -COPY php-production.ini /usr/local/etc/php/conf.d/app.ini +# audit-ci via npm. +RUN npm install -g audit-ci@^6 -WORKDIR /project +COPY ./conf/php-production.ini /usr/local/etc/php/conf.d/app.ini + +WORKDIR /project \ No newline at end of file diff --git a/PHP8.5/QA/php-production.ini b/PHP8.5/QA/conf/php-production.ini similarity index 100% rename from PHP8.5/QA/php-production.ini rename to PHP8.5/QA/conf/php-production.ini From 44bb0ca1a335d0022723e3e949ce87484e5fd8f4 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 1 Jun 2026 16:49:09 +0200 Subject: [PATCH 04/10] =?UTF-8?q?test:=20=E2=9C=85=20add=20some=20tests=20?= =?UTF-8?q?in=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP8.5/DEV/tests.sh | 70 +++++++++++++++++++++++++++++++++++++ PHP8.5/PROD/tests.sh | 64 ++++++++++++++++++++++++++++++++++ PHP8.5/QA/tests.sh | 52 +++++++++++++++++++++++++++ PHP8.5/common.sh | 10 ++++++ PHP8.5/utils.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 279 insertions(+) create mode 100644 PHP8.5/DEV/tests.sh create mode 100644 PHP8.5/PROD/tests.sh create mode 100644 PHP8.5/QA/tests.sh create mode 100644 PHP8.5/common.sh create mode 100644 PHP8.5/utils.sh diff --git a/PHP8.5/DEV/tests.sh b/PHP8.5/DEV/tests.sh new file mode 100644 index 0000000..12264f6 --- /dev/null +++ b/PHP8.5/DEV/tests.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +# Import shared utilities. +source "$(pwd)/PHP8.5/utils.sh" + +startTests + +# Import shared tests. +source "$(pwd)/PHP8.5/common.sh" + +section "PHP extensions" +run "gd" "php -m | grep -qx 'gd'" +run "exif" "php -m | grep -qx 'exif'" +run "gettext" "php -m | grep -qx 'gettext'" +run "intl" "php -m | grep -qx 'intl'" +run "mysqli" "php -m | grep -qx 'mysqli'" +run "pdo_mysql" "php -m | grep -qx 'pdo_mysql'" +run "xsl" "php -m | grep -qx 'xsl'" +run "zip" "php -m | grep -qx 'zip'" +run "bcmath" "php -m | grep -qx 'bcmath'" +run "ldap" "php -m | grep -qx 'ldap'" +run "gmp" "php -m | grep -qx 'gmp'" +run "mbstring" "php -m | grep -qx 'mbstring'" +run "imagick" "php -m | grep -qx 'imagick'" +run "redis" "php -m | grep -qx 'redis'" +run "xdebug" "php -m | grep -qx 'xdebug'" +run "pcov" "php -m | grep -qx 'pcov'" + +section "Compiled extensions" +run "gd: imagecreate" "php -r '\$i = imagecreate(10,10); echo \$i ? \"ok\" : \"fail\";'" +run "imagick: instanciation" "php -r 'new Imagick(); echo \"ok\";'" +run "xdebug: mode configurable" "php -d xdebug.mode=off -m | grep -q xdebug" +run "pcov: driver disponible" "php -m | grep -q pcov" + +section "Apache & PHP-FPM" +run "httpd binaire present" "which httpd" +run "php-fpm binaire present" "which php-fpm" +run "httpd -v" "httpd -v" +run "php-fpm -v" "php-fpm -v" +run "module proxy_fcgi enabled" "grep -r 'proxy_fcgi' /etc/apache2/" +run "module rewrite enabled" "grep -r 'rewrite_module' /etc/apache2/" +run "module remoteip enabled" "grep -r 'remoteip_module' /etc/apache2/" +run "module headers active" "grep -r 'headers_module' /etc/apache2/" +run "vhost.conf present" "test -f /etc/apache2/conf.d/vhost.conf" +run "php-fpm.conf present" "test -f /usr/local/etc/php-fpm.d/www.conf" +run "xdebug.ini present" "test -f /usr/local/etc/php/conf.d/xdebug.ini" + +section "QA tools" +run_output "composer version" "composer --version 2>/dev/null | awk '{print \$1,\$2,\$3}'" +run_output "bun version" "bun --version" +run_output "node version" "node --version" +run_output "npm version" "npm --version" + +section "Utilities" +run "git disponible" "git --version" +run "curl disponible" "curl --version" +run "unzip disponible" "unzip -v" +run "mariadb disponible" "mysql --version" + +section "Shell" +run "zsh disponible" "which zsh" +run "oh-my-zsh installed" "test -d /root/.oh-my-zsh" +run "zsh-autosuggestions" "test -d /root/.oh-my-zsh/custom/plugins/zsh-autosuggestions" +run "SHELL=zsh" "[ \"\$SHELL\" = '/bin/zsh' ]" + +section "Paths" +run "WORKDIR = /app/srcs" "[ \"\$(pwd)\" = '/app/srcs' ]" +run "docker-entrypoint present" "test -x /usr/local/bin/docker-entrypoint.sh" + +endTests \ No newline at end of file diff --git a/PHP8.5/PROD/tests.sh b/PHP8.5/PROD/tests.sh new file mode 100644 index 0000000..3def0b1 --- /dev/null +++ b/PHP8.5/PROD/tests.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# Import shared utilities. +source "$(pwd)/PHP8.5/utils.sh" + +startTests + +# Import shared tests. +source "$(pwd)/PHP8.5/common.sh" + +section "PHP extensions" +run "bcmath" "php -m | grep -qx 'bcmath'" +run "exif" "php -m | grep -qx 'exif'" +run "gd" "php -m | grep -qx 'gd'" +run "gettext" "php -m | grep -qx 'gettext'" +run "gmp" "php -m | grep -qx 'gmp'" +run "imagick" "php -m | grep -qx 'imagick'" +run "ldap" "php -m | grep -qx 'ldap'" +run "mbstring" "php -m | grep -qx 'mbstring'" +run "memcached" "php -m | grep -qx 'memcached'" +run "mysqli" "php -m | grep -qx 'mysqli'" +run "pdo_mysql" "php -m | grep -qx 'pdo_mysql'" +run "redis" "php -m | grep -qx 'redis'" +run "xsl" "php -m | grep -qx 'xsl'" +run "zip" "php -m | grep -qx 'zip'" + +section "Compiled extensions" +run "gd: imagecreate" "php -r '\$i = imagecreate(10,10); echo \$i ? \"ok\" : \"fail\";'" +run "imagick: instanciation" "php -r 'new Imagick(); echo \"ok\";'" + +section "Check: no development tools" +run "pcov absent" "php -m | grep -qx 'pcov' && exit 1 || exit 0" +run "zsh absent" "which zsh 2>/dev/null && exit 1 || exit 0" +run "bun absent" "which bun 2>/dev/null && exit 1 || exit 0" +run "xdebug absent" "php -m | grep -qx 'xdebug' && exit 1 || exit 0" +run "xdebug.ini absent" "test ! -f /usr/local/etc/php/conf.d/xdebug.ini" + +section "Apache & PHP-FPM" +run "httpd binaire present" "which httpd" +run "php-fpm binaire present" "which php-fpm" +run "httpd -v" "httpd -v" +run "php-fpm -v" "php-fpm -v" +run "module proxy_fcgi enabled" "grep -r 'proxy_fcgi' /etc/apache2/" +run "module rewrite enabled" "grep -r 'rewrite_module' /etc/apache2/" +run "module remoteip enabled" "grep -r 'remoteip_module' /etc/apache2/" +run "module headers enabled" "grep -r 'headers_module' /etc/apache2/" +run "vhost.conf present" "test -f /etc/apache2/conf.d/vhost.conf" +run "php-fpm.conf present" "test -f /usr/local/etc/php-fpm.d/www.conf" +run "ssl.conf absent" "test ! -f /etc/apache2/conf.d/ssl.conf" + +section "QA tools" +run_output "composer version" "composer --version 2>/dev/null | awk '{print \$1,\$2,\$3}'" + +section "Utilities" +run "git disponible" "git --version" +run "curl disponible" "curl --version" +run "unzip disponible" "unzip -v" +run "mariadb disponible" "mysql --version" + +section "Paths" +run "WORKDIR = /app/srcs" "[ \"\$(pwd)\" = '/app/srcs' ]" +run "docker-entrypoint present" "test -x /usr/local/bin/docker-entrypoint.sh" + +endTests \ No newline at end of file diff --git a/PHP8.5/QA/tests.sh b/PHP8.5/QA/tests.sh new file mode 100644 index 0000000..ab8c51f --- /dev/null +++ b/PHP8.5/QA/tests.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Import shared utilities. +source "$(pwd)/PHP8.5/utils.sh" + +startTests + +# Import shared tests. +source "$(pwd)/PHP8.5/common.sh" + +section "PHP extensions" +run "bcmath" "php -m | grep -qx 'bcmath'" +run "exif" "php -m | grep -qx 'exif'" +run "gd" "php -m | grep -qx 'gd'" +run "gettext" "php -m | grep -qx 'gettext'" +run "gmp" "php -m | grep -qx 'gmp'" +run "imagick" "php -m | grep -qx 'imagick'" +run "intl" "php -m | grep -qx 'intl'" +run "ldap" "php -m | grep -qx 'ldap'" +run "mbstring" "php -m | grep -qx 'mbstring'" +run "memcached" "php -m | grep -qx 'memcached'" +run "mysqli" "php -m | grep -qx 'mysqli'" +run "pcov" "php -m | grep -qx 'pcov'" +run "pdo_mysql" "php -m | grep -qx 'pdo_mysql'" +run "xsl" "php -m | grep -qx 'xsl'" +run "zip" "php -m | grep -qx 'zip'" + +section "Compiled extensions" +run "gd: imagecreate" "php -r '\$i = imagecreate(10,10); echo \$i ? \"ok\" : \"fail\";'" +run "imagick: instanciation" "php -r 'new Imagick(); echo \"ok\";'" +run "pcov: driver" "php -d pcov.enabled=1 -r 'echo pcov\\\\Collector::start() ? \"ok\" : \"ok\";' 2>/dev/null || true; php -m | grep -q pcov" + +section "QA tools" +run "local-php-security-checker present" "local-php-security-checker -help 2>&1 | grep -qi 'version'" +run_output "composer version" "composer --version 2>/dev/null | awk '{print \$1,\$2,\$3}'" +run_output "audit-ci version" "audit-ci --version 2>/dev/null || npx audit-ci --version 2>/dev/null" +run_output "node version" "node --version" +run_output "npm version" "npm --version" + +section "Utilities" +run "git disponible" "git --version" +run "curl disponible" "curl --version" +run "unzip disponible" "unzip -v" + +section "Paths" +run "WORKDIR = /project" "[ \"\$(pwd)\" = '/project' ]" +run "/tools dans le PATH" "echo \$PATH | grep -q '/tools'" +run "composer dans le PATH" "which composer" +run "audit-ci dans le PATH" "which audit-ci" +run "security-checker dans PATH" "which local-php-security-checker" + +endTests \ No newline at end of file diff --git a/PHP8.5/common.sh b/PHP8.5/common.sh new file mode 100644 index 0000000..d6272d9 --- /dev/null +++ b/PHP8.5/common.sh @@ -0,0 +1,10 @@ +section "PHP version" +run_output "php -v" "php -r 'echo PHP_VERSION;'" +run "php -l (lint)" "php -r 'echo 42;'" +run "php.ini loaded" "php -i | grep -q 'Loaded Configuration'" +run "app.ini loaded" "php -i | grep -q 'app.ini\|/usr/local/etc/php/conf.d/app.ini'" + +section "Locales" +run "LC_ALL=fr_FR.UTF-8" "[ \"\$LC_ALL\" = 'fr_FR.UTF-8' ]" +run "LANG=fr_FR.UTF-8" "[ \"\$LANG\" = 'fr_FR.UTF-8' ]" +run "locale fr_FR disponible" "locale -a 2>/dev/null | grep -qi 'fr_FR'" \ No newline at end of file diff --git a/PHP8.5/utils.sh b/PHP8.5/utils.sh new file mode 100644 index 0000000..f4a0868 --- /dev/null +++ b/PHP8.5/utils.sh @@ -0,0 +1,83 @@ +# Variables +IMAGE="${1:-image-name:latest}" +PASS=0 +FAIL=0 +ERRORS=() +GREEN='\033[0;32m' +RED='\033[0;31m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +NC='\033[0m' + +# Functions to test element in target image. + +## run