Merge branch 'update-build-time' into 'master'

fix: 🧑‍💻 update build time and size of docker images

Closes #5

See merge request ldc-web/projets/ldc-web-images-docker!2
This commit is contained in:
Vincent BRIDIER 2026-09-24 12:46:12 +02:00
commit bcc288e289
24 changed files with 791 additions and 6177 deletions

View file

@ -76,14 +76,6 @@ docker-build:prod-7.3:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $BUILD_NAME == "PROD-7.3"
docker-build:qa-8.5:
extends: .docker-build
variables:
IMAGE_DIR: "PHP8.5/QA"
IMAGE_NAME: "uwil-qa-8.5"
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $BUILD_NAME == "QA-8.5"
docker-build:ci-8.5:
extends: .docker-build
variables:

View file

@ -1,114 +1,179 @@
FROM php:8.5.4-apache-trixie
ENV DEBIAN_FRONTEND=noninteractive
FROM php:8.5.4-fpm-alpine AS builder
ARG http_proxy
ENV http_proxy=${http_proxy}
ENV https_proxy=${http_proxy}
ENV HTTP_PROXY=${http_proxy}
ENV HTTPS_PROXY=${http_proxy}
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 update && apk upgrade --no-cache && 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 \
oniguruma-dev gettext-dev gmp-dev \
linux-headers \
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 \
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 \
&& 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* \
\
&& curl -fsSL https://github.com/xdebug/xdebug/archive/refs/tags/3.5.1.tar.gz -o /tmp/xdebug.tar.gz \
&& 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* \
\
&& 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*
# 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 \
&& php /tmp/composer-installer --install-dir=/usr/local/bin --filename=composer --version=2.9.7 \
\
&& curl -fsSL -o /tmp/bun.zip "https://github.com/oven-sh/bun/releases/download/bun-v1.2.10/bun-linux-x64-musl.zip" \
&& unzip -q /tmp/bun.zip -d /tmp/bun-extracted \
&& mv /tmp/bun-extracted/bun-linux-x64-musl/bun /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
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
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/*
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 \
XDEBUG_MODE=develop,debug \
XDEBUG_CONFIG="client_host=host.docker.internal client_port=9003"
# 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 update && apk upgrade --no-cache && apk add --no-cache \
bash \
ca-certificates curl \
git unzip zip nano vim zsh htop \
apache2 apache2-proxy apache2-brotli \
nodejs npm \
freetype libjpeg libpng libwebp libxpm \
icu-libs libxslt libzip \
imagemagick \
libcurl libmemcached \
musl-locales musl-locales-lang \
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/*
# 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
# 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)
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 \
# Installation ohmyzsh + plugin + theme.
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended \
&& 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
# Copie des extensions PHP compilées + conf PHP + Composer + Bun 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
# Set default shell to zsh
RUN chsh -s /bin/zsh
# 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
# 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
# Copie des fichiers de configuration + Entrypoint
COPY conf/php-fpm.conf /usr/local/etc/php-fpm.d/www.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/conf.d/vhost.conf
COPY conf/common-apache.conf /etc/apache2/conf.d/z-app.conf
COPY conf/common-security.conf /etc/apache2/conf.d/security.conf
COPY --chmod=755 conf/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Enable Apache modules and configuration
RUN a2enmod rewrite remoteip headers http2 && \
a2enconf z-app
# 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 expires_module/LoadModule expires_module/' \
-e 's/#LoadModule deflate_module/LoadModule deflate_module/' \
-e 's/#LoadModule mime_module/LoadModule mime_module/' \
-e 's/#LoadModule mpm_event_module/LoadModule mpm_event_module/' \
-e 's/LoadModule mpm_prefork_module/#LoadModule mpm_prefork_module/' \
-e 's/^[[:space:]]*#*[[:space:]]*LoadModule[[:space:]]\+ssl_module/#LoadModule ssl_module/' \
-e 's/^[[:space:]]*Listen[[:space:]]\+443/#Listen 443/' \
/etc/apache2/httpd.conf \
&& printf '\nPidFile /tmp/httpd.pid\n' >> /etc/apache2/httpd.conf \
&& if [ -f /etc/apache2/conf.d/ssl.conf ]; then \
mv /etc/apache2/conf.d/ssl.conf \
/etc/apache2/conf.d/ssl.conf.disabled; \
fi \
&& find /etc/apache2 -type f \( -name '*.conf' -o -name 'httpd.conf' \) \
-exec sed -i \
-e 's!^[[:space:]]*CustomLog[[:space:]].*!CustomLog /proc/self/fd/1 combined!' \
-e 's!^[[:space:]]*TransferLog[[:space:]].*!CustomLog /proc/self/fd/1 combined!' \
-e 's!^[[:space:]]*ErrorLog[[:space:]].*!ErrorLog /proc/self/fd/2!' \
-e 's/^[[:space:]]*#*[[:space:]]*LoadModule[[:space:]]\+lbmethod_heartbeat_module/#LoadModule lbmethod_heartbeat_module/' \
-e 's/^[[:space:]]*#*[[:space:]]*LoadModule[[:space:]]\+lbmethod_/#&/' \
-e 's/^[[:space:]]*#*[[:space:]]*LoadModule[[:space:]]\+proxy_balancer_module/#&/' \
{} \; \
&& httpd -t
# XDEBUG LOGS
RUN mkdir -p /app/logs/
# Création des répertoires avec les bons droits.
RUN mkdir -p /app/tmp /app/tmp/sessions /app/logs /app/srcs \
&& chown -R www-data:www-data /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).
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

View file

@ -1,47 +1,26 @@
#User noroot
#Group noroot
#
# Timeout: The number of seconds before receives and sends time out.
#
ServerName localhost
Timeout 300
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
DefaultType None
HostnameLookups Off
ErrorLog /proc/self/fd/2
CustomLog /proc/self/fd/1 combined
LogLevel warn
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
SetEnvIf Request_URI "^check_http" dontlog
SetEnvIf Remote_Addr "127.0.0.1" dontlog
SetEnvIf Remote_Addr "::1" dontlog
SetEnvIf Remote_Addr "127\.0\.0\.1" loopback
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
# Block .git composer and npm files
<FilesMatch "^composer\.(json|lock)">
Require all denied
</FilesMatch>
@ -53,62 +32,4 @@ AccessFileName .htaccess
</FilesMatch>
<DirectoryMatch "^\.|\/\.">
Require all denied
</Directorymatch>
#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value. If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
# It is also possible to omit any default MIME type and let the
# client's browser guess an appropriate action instead. Typically the
# browser will decide based on the file's extension then. In cases
# where no good assumption can be made, letting the default MIME type
# unset is suggested instead of forcing the browser to accept
# incorrect metadata.
#
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).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
SetEnvIf Remote_Addr "127\.0\.0\.1" loopback
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
</Directorymatch>

View file

@ -1,8 +0,0 @@
# If you just change the port or add more ports here, you will likely also
# 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

View file

@ -1,74 +1,3 @@
#
# Disable access to the entire file system except for the directories that
# are explicitly allowed later.
#
# This currently breaks the configurations that come with some web application
# Debian packages.
#
#<Directory />
# AllowOverride None
# Order Deny,Allow
# Deny from all
#</Directory>
# Changing the following options will not really affect the security of the
# server, but might make attacks slightly more difficult in some cases.
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minimal | Minor | Major | Prod
# where Full conveys the most information, and Prod the least.
#ServerTokens Minimal
ServerTokens Prod
#ServerTokens Full
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#ServerSignature Off
ServerSignature Off
#
# Allow TRACE method
#
# Set to "extended" to also reflect the request body (only for testing and
# diagnostic purposes).
#
# Set to one of: On | Off | extended
TraceEnable Off
#TraceEnable On
#
# Forbid access to version control directories
#
# If you use version control systems in your document root, you should
# probably deny access to their directories. For example, for subversion:
#
#<DirectoryMatch "/\.svn">
# Require all denied
#</DirectoryMatch>
#
# Setting this header will prevent MSIE from interpreting files as something
# else than declared by the content type in the HTTP headers.
# Requires mod_headers to be enabled.
#
#Header set X-Content-Type-Options: "nosniff"
#
# Setting this header will prevent other sites from embedding pages from this
# site as frames. This defends against clickjacking attacks.
# Requires mod_headers to be enabled.
#
#Header set X-Frame-Options: "sameorigin"
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
TraceEnable Off

View file

@ -0,0 +1,20 @@
#!/bin/sh
set -e
# Démarrer php-fpm en arrière-plan (flag -D = --daemonize).
php-fpm -D
# Attendre que php-fpm soit prêt (max 10s, échec si timeout).
for i in $(seq 1 10); do
if pgrep -f "php-fpm" > /dev/null 2>&1; then
break
fi
if [ "$i" -eq 10 ]; then
echo "ERROR: php-fpm failed to start within 10 seconds" >&2
exit 1
fi
sleep 1
done
# Démarrer apache au premier plan (flag -D = -Define <variable_name>).
exec httpd -D FOREGROUND

View file

@ -0,0 +1,33 @@
[global]
; php-fpm est lancé en arrière-plan dans l'entrypoint.sh,
; c'est apache qui reste au premier plan et est surveillé par docker.
daemonize = no
error_log = /proc/self/fd/2
log_level = warning
[www]
catch_workers_output = yes
decorate_workers_output = no
; Utilisateur par défaut sous alpine.
user = www-data
group = www-data
; 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_flag[log_errors] = on
php_admin_value[error_log] = /proc/self/fd/2
php_admin_value[expose_php] = Off

File diff suppressed because it is too large Load diff

View file

@ -1,18 +1,26 @@
<VirtualHost *:443>
Protocols h2 h2c http/1.1
ServerAdmin contact@ldc.fr
DocumentRoot /app/${DOCUMENTROOT}
<VirtualHost *:80>
Protocols http/1.1
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).
<FilesMatch "\.php$">
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
<Directory /app/${DOCUMENTROOT}>
Options +MultiViews -Indexes +FollowSymLinks
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
SetEnvIf X_FORWARDED_PROTO https HTTPS=on
</Directory>
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
# + Logs sur stdout/stderr (pour docker logs)
ErrorLog "|/usr/bin/tee -a /proc/self/fd/2"
CustomLog "|/usr/bin/tee -a /proc/self/fd/1" combined
</VirtualHost>

71
PHP8.5/DEV/tests.sh Normal file
View file

@ -0,0 +1,71 @@
#!/usr/bin/env bash
# Import shared utilities.
source "$(pwd)/PHP8.5/utils.sh"
start_tests
# 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 "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"
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"
section "User"
run "default user = www-data" "test \"\$(id -un)\" = 'www-data'" www-data
end_tests

View file

@ -1,98 +1,140 @@
FROM php:8.5.4-apache-trixie
FROM php:8.5.4-fpm-alpine AS builder
ARG http_proxy
ENV http_proxy=${http_proxy}
ENV https_proxy=${http_proxy}
ENV HTTP_PROXY=${http_proxy}
ENV HTTPS_PROXY=${http_proxy}
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 update && apk upgrade --no-cache && 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 \
oniguruma-dev gettext-dev gmp-dev \
linux-headers \
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 \
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
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
ARG http_proxy
# PECL PROXY HACK
RUN if [ -n "${http_proxy}" ]; then \
pear config-set http_proxy "${http_proxy}"; \
fi
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
RUN apk update && apk upgrade --no-cache && apk add --no-cache \
bash \
ca-certificates curl \
unzip zip vim \
apache2 apache2-proxy apache2-brotli \
freetype libjpeg libpng libwebp libxpm \
icu-libs libxslt libzip \
imagemagick \
libcurl libmemcached \
musl-locales musl-locales-lang \
oniguruma \
gmp gettext-libs \
libcap
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
# Copie des fichiers de configuration.
COPY conf/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf
COPY conf/php.ini /usr/local/etc/php/conf.d/app.ini
COPY conf/vhost.conf /etc/apache2/conf.d/vhost.conf
COPY conf/common-apache.conf /etc/apache2/conf.d/z-app.conf
COPY conf/common-security.conf /etc/apache2/conf.d/security.conf
COPY --chmod=755 conf/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
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 expires_module/LoadModule expires_module/' \
-e 's/#LoadModule deflate_module/LoadModule deflate_module/' \
-e 's/#LoadModule mime_module/LoadModule mime_module/' \
-e 's/#LoadModule mpm_event_module/LoadModule mpm_event_module/' \
-e 's/LoadModule mpm_prefork_module/#LoadModule mpm_prefork_module/' \
-e 's/^[[:space:]]*#*[[:space:]]*LoadModule[[:space:]]\+ssl_module/#LoadModule ssl_module/' \
-e 's/^[[:space:]]*Listen[[:space:]]\+443/#Listen 443/' \
/etc/apache2/httpd.conf \
&& printf '\nPidFile /tmp/httpd.pid\n' >> /etc/apache2/httpd.conf \
&& if [ -f /etc/apache2/conf.d/ssl.conf ]; then \
mv /etc/apache2/conf.d/ssl.conf \
/etc/apache2/conf.d/ssl.conf.disabled; \
fi \
&& find /etc/apache2 -type f \( -name '*.conf' -o -name 'httpd.conf' \) \
-exec sed -i \
-e 's!^[[:space:]]*CustomLog[[:space:]].*!CustomLog /proc/self/fd/1 combined!' \
-e 's!^[[:space:]]*TransferLog[[:space:]].*!CustomLog /proc/self/fd/1 combined!' \
-e 's!^[[:space:]]*ErrorLog[[:space:]].*!ErrorLog /proc/self/fd/2!' \
-e 's/^[[:space:]]*#*[[:space:]]*LoadModule[[:space:]]\+lbmethod_heartbeat_module/#LoadModule lbmethod_heartbeat_module/' \
-e 's/^[[:space:]]*#*[[:space:]]*LoadModule[[:space:]]\+lbmethod_/#&/' \
-e 's/^[[:space:]]*#*[[:space:]]*LoadModule[[:space:]]\+proxy_balancer_module/#&/' \
{} \; \
&& httpd -t
RUN a2enmod rewrite remoteip headers http2 expires deflate mime brotli && \
a2enconf z-app
RUN mkdir -p /app/tmp && chmod -R 770 /app/tmp && chown -R www-data:www-data /app
#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/tmp/sessions /app/logs /app/srcs \
&& chown -R www-data:www-data /app \
&& chmod 770 /app/tmp /app/logs \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/httpd
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).
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

View file

@ -1,47 +1,26 @@
#User noroot
#Group noroot
#
# Timeout: The number of seconds before receives and sends time out.
#
ServerName localhost
Timeout 300
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
DefaultType None
HostnameLookups Off
ErrorLog /proc/self/fd/2
CustomLog /proc/self/fd/1 combined
LogLevel warn
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
SetEnvIf Request_URI "^check_http" dontlog
SetEnvIf Remote_Addr "127.0.0.1" dontlog
SetEnvIf Remote_Addr "::1" dontlog
SetEnvIf Remote_Addr "127\.0\.0\.1" loopback
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
# Block .git composer and npm files
<FilesMatch "^composer\.(json|lock)">
Require all denied
</FilesMatch>
@ -53,62 +32,4 @@ AccessFileName .htaccess
</FilesMatch>
<DirectoryMatch "^\.|\/\.">
Require all denied
</Directorymatch>
#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value. If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
# It is also possible to omit any default MIME type and let the
# client's browser guess an appropriate action instead. Typically the
# browser will decide based on the file's extension then. In cases
# where no good assumption can be made, letting the default MIME type
# unset is suggested instead of forcing the browser to accept
# incorrect metadata.
#
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).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
SetEnvIf Remote_Addr "127\.0\.0\.1" loopback
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
</Directorymatch>

View file

@ -1,7 +0,0 @@
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

View file

@ -1,74 +1,3 @@
#
# Disable access to the entire file system except for the directories that
# are explicitly allowed later.
#
# This currently breaks the configurations that come with some web application
# Debian packages.
#
#<Directory />
# AllowOverride None
# Order Deny,Allow
# Deny from all
#</Directory>
# Changing the following options will not really affect the security of the
# server, but might make attacks slightly more difficult in some cases.
#
# ServerTokens
# This directive configures what you return as the Server HTTP response
# Header. The default is 'Full' which sends information about the OS-Type
# and compiled in modules.
# Set to one of: Full | OS | Minimal | Minor | Major | Prod
# where Full conveys the most information, and Prod the least.
#ServerTokens Minimal
ServerTokens Prod
#ServerTokens Full
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#ServerSignature Off
ServerSignature Off
#
# Allow TRACE method
#
# Set to "extended" to also reflect the request body (only for testing and
# diagnostic purposes).
#
# Set to one of: On | Off | extended
TraceEnable Off
#TraceEnable On
#
# Forbid access to version control directories
#
# If you use version control systems in your document root, you should
# probably deny access to their directories. For example, for subversion:
#
#<DirectoryMatch "/\.svn">
# Require all denied
#</DirectoryMatch>
#
# Setting this header will prevent MSIE from interpreting files as something
# else than declared by the content type in the HTTP headers.
# Requires mod_headers to be enabled.
#
#Header set X-Content-Type-Options: "nosniff"
#
# Setting this header will prevent other sites from embedding pages from this
# site as frames. This defends against clickjacking attacks.
# Requires mod_headers to be enabled.
#
#Header set X-Frame-Options: "sameorigin"
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
TraceEnable Off

View file

@ -0,0 +1,20 @@
#!/bin/sh
set -e
# Démarrer php-fpm en arrière-plan (flag -D = --daemonize).
php-fpm -D
# Attendre que php-fpm soit prêt (max 10s, échec si timeout).
for i in $(seq 1 10); do
if pgrep -f "php-fpm" > /dev/null 2>&1; then
break
fi
if [ "$i" -eq 10 ]; then
echo "ERROR: php-fpm failed to start within 10 seconds" >&2
exit 1
fi
sleep 1
done
# Démarrer apache au premier plan (flag -D = -Define <variable_name>).
exec httpd -D FOREGROUND

View file

@ -0,0 +1,33 @@
[global]
; php-fpm est lancé en arrière-plan dans l'entrypoint.sh,
; c'est apache qui reste au premier plan et est surveillé par docker.
daemonize = no
error_log = /proc/self/fd/2
log_level = warning
[www]
catch_workers_output = yes
decorate_workers_output = no
; Utilisateur par défaut sous alpine.
user = www-data
group = www-data
; 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_flag[log_errors] = on
php_admin_value[error_log] = /proc/self/fd/2
php_admin_value[expose_php] = Off

File diff suppressed because it is too large Load diff

View file

@ -1,16 +1,23 @@
<VirtualHost *:80>
Protocols h2c http/1.1
ServerAdmin contact@ldc.fr
Protocols 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).
<FilesMatch "\.php$">
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
<Directory /app/srcs/public>
Options +MultiViews -Indexes +FollowSymLinks
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
</Directory>
# Logs sur stdout/stderr (pour docker logs)
ErrorLog /proc/self/fd/2
CustomLog /proc/self/fd/1 combined
</VirtualHost>

61
PHP8.5/PROD/tests.sh Normal file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Import shared utilities.
source "$(pwd)/PHP8.5/utils.sh"
start_tests
# 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 "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 "Utilities"
run "curl disponible" "curl --version"
run "unzip disponible" "unzip -v"
section "Paths"
run "WORKDIR = /app/srcs" "[ \"\$(pwd)\" = '/app/srcs' ]"
run "docker-entrypoint present" "test -x /usr/local/bin/docker-entrypoint.sh"
section "User"
run "default user = www-data" "test \"\$(id -un)\" = 'www-data'" www-data
end_tests

View file

@ -1,101 +0,0 @@
FROM php:8.5-cli-trixie
ARG http_proxy
ENV http_proxy=${http_proxy}
ENV https_proxy=${http_proxy}
ENV HTTP_PROXY=${http_proxy}
ENV 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 \
zip \
#GMP
libgmp-dev \
# Imagick
libmagick++-dev \
libmagickwand-dev \
# Memcached
libmemcached-dev \
# ldap
ldap-utils libldap2-dev \
# locales
locales
# 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
RUN docker-php-ext-configure gd \
--enable-gd \
--with-webp \
--with-jpeg \
--with-xpm \
--with-freetype
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
# PECL PROXY HACK
RUN if [ -n "${http_proxy}" ]; then \
pear config-set http_proxy "${http_proxy}"; \
fi
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
# 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
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
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
WORKDIR /project

File diff suppressed because it is too large Load diff

12
PHP8.5/common.sh Normal file
View file

@ -0,0 +1,12 @@
# Common tests between images.
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'"

87
PHP8.5/utils.sh Normal file
View file

@ -0,0 +1,87 @@
# 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.
# ex: run <label> <command>
run() {
local label="$1";
local labelColored="${NC} ${label}"
local command="$2"
local user="${3:-root}"
if docker run --rm --user "$user" --entrypoint /bin/sh "$IMAGE" -c "$command" > /dev/null 2>&1; then
echo -e " ${GREEN}✔ ${labelColored}"
(( PASS++ )) || true
else
echo -e " ${RED}✘ ${labelColored}"
ERRORS+=("$label")
(( FAIL++ )) || true
fi
}
# Functions to test element in target image with output.
# ex: run_output <label> <command>
run_output() {
local label="$1";
local labelColored="${NC} ${label}"
local command="$2"
local user="${3:-root}"
local out
if out=$(docker run --rm --user "$user" --entrypoint /bin/sh "$IMAGE" -c "$command" 2>&1); then
echo -e " ${GREEN}✔ ${labelColored}${CYAN} → $(echo "$out" | head -1)${NC}"
(( PASS++ )) || true
else
echo -e " ${RED}✘ ${labelColored}"
echo -e " ${YELLOW}↳ $out${NC}"
ERRORS+=("$label")
(( FAIL++ )) || true
fi
}
# Functions to display section.
# ex: section <label>
section() {
echo ""
echo -e "${CYAN}▶ $1${NC}"
}
# Functions to display a starting section of tests.
start_tests() {
# valid image
echo ""
echo -e " Image: ${YELLOW}${IMAGE}${NC}"
if ! docker image inspect "$IMAGE" > /dev/null 2>&1; then
echo -e "${RED}✘ Image not found: ${IMAGE}${NC}"
echo ""
echo " To create a new docker image: docker build -t ${IMAGE} ."
exit 1
fi
}
# Functions to display an ending section of tests with results.
end_tests() {
TOTAL=$(( PASS + FAIL ))
echo ""
echo -e "${GREEN}▶ ${PASS}/${TOTAL} tests passed${NC} $([ $FAIL -gt 0 ] || echo "")\n"
if [ ${#ERRORS[@]} -gt 0 ]; then
echo -e "${RED}▶ ${FAIL} tests failed:${NC}"
for e in "${ERRORS[@]}"; do
echo -e " ${RED}✘ ${NC} $e"
done
echo ""
exit 1
fi
exit 0
}

78
README.md Normal file
View file

@ -0,0 +1,78 @@
# UWIL Docker images
## Table des matières
- [Depuis environnement de travail LDC](#depuis-environnement-de-travail-ldc)
- [Comparatif des images 8.5](#comparatif-des-images-85)
- [Explication des Dockerfiles pour images 8.5](#explication-des-dockerfiles-pour-images-85)
- [Stage n°1: builder](#stage-n1-builder)
- [Stage n°2: base](#stage-n2-base)
## Depuis environnement de travail LDC
Voici quelques commandes:
- pour **build** une image:
```bash
docker build [--no-cache] [--build-arg http_proxy=http://proxy-app.lesidc.com:8080] -t <nom_image> ./PHPX.X/DEV/
```
- pour **tester l'image** build :
```bash
docker run --rm <nom_image>:<version>
```
- pour **tester les outils** d'une image build (se positionner à la racine) :
```bash
bash PHPX.X/PROD/tests.sh <nom_image>
```
## Comparatif des images 8.5
Voici deux tableaux résumant le gain du temps de build ainsi que la réduction du poids par rapport aux anciennes images utilisées :
| Image | Ancien build | Nouveau build | Gain build |
| :------: | :----------: | :-----------: | :-------------: |
| DEV | ~235s | ~159s | **-76s (-32%)** |
| PROD | ~212s | ~142s | **-70s (-33%)** |
| QA | ~224s | ~125s | **-99s (-44%)** |
| Image | Ancien poids | Nouveau poids | Réduction poids |
| :------: | :----------: | :-----------: | :-----------------: |
| DEV | 1.44 GB | 457 MB | **-983 MB (-68%)** |
| PROD | 1.19 GB | 212 MB | **-978 MB (-82%)** |
| QA | 1.27 GB | 270 MB | **-1.00 GB (-79%)** |
## Explication des Dockerfiles pour images 8.5
Les images sont construites selon une approche [multi-stage](https://docs.docker.com/build/building/multi-stage/), afin de séparer les éléments nécessaires à la construction de l'image de ceux réellement utiles à son exécution.
Cette séparation permet de :
- réduire la taille de l'image finale,
- éviter d'embarquer les compilateurs et outils de compilation en production,
- accélérer les builds grâce à une meilleure séparation des étapes,
- conserver une image d'exécution plus propre et plus légère.
Voici un exemple concret résultant de cette approche grâce au [comparatif des images 8.5](#comparatif-des-images-8.5).
### Stage n°1: builder
Le premier stage est dédié à la **construction de l'environnement**.
Il contient l'ensemble des dépendances et outils nécessaires pour compiler les composants qui ne sont pas directement disponibles dans l'image de base.
On y retrouve donc certaines actions :
- installation des dépendances nécessaires à la compilation,
- compilation et installation des composants complémentaires,
- installation des outils nécessaires au projet.
### Stage n°2: base
Le second stage constitue la **base de l'image finale**. Il repart d'une image PHP minimale et n'embarque pas les outils de compilation du stage précédent.
Les éléments produits lors du build sont récupérés depuis le premier stage et copiés dans cette image, on bénéficie ainsi des composants compilés sans conserver l'environnement ayant servi à les compiler.
On y retrouve donc certaines actions :
* installation des dépendances nécessaires au runtime,
* configuration de PHP,
* configuration du serveur web,
* configuration des différents services et outils nécessaires,
* définition des permissions,
* etc…