From 09813cad770c7d8be82dc6cf048bd5797d75b1a7 Mon Sep 17 00:00:00 2001 From: MBorne Date: Mon, 2 Dec 2024 18:59:59 +0100 Subject: [PATCH] chore(docker): rebase on ubuntu:24.04 --- .docker/Dockerfile | 64 +++++++++++++++++++++++++++++++------- .docker/apache2-foreground | 32 +++++++++++++++++++ .docker/php.ini | 3 ++ 3 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 .docker/apache2-foreground diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 8240f92..f779767 100755 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -1,7 +1,8 @@ #---------------------------------------------------------------------- # Download vendor from composer.json in dedicated layer #---------------------------------------------------------------------- -FROM composer:latest AS vendor +ARG registry=docker.io +FROM ${registry}/library/composer:latest AS vendor RUN mkdir -p /opt/validator-api WORKDIR /opt/validator-api @@ -9,9 +10,9 @@ COPY composer.json . RUN composer install --no-scripts --prefer-dist --ignore-platform-req=ext-pcntl #---------------------------------------------------------------------- -# Create base layer for dev and production +# Create application container #---------------------------------------------------------------------- -FROM php:8.3-apache AS base +FROM ${registry}/library/ubuntu:24.04 ENV DEBIAN_FRONTEND=noninteractive ENV LANG=fr_FR.UTF-8 @@ -34,21 +35,61 @@ RUN apt-get update \ && apt-get install --no-install-recommends -y \ unzip zip \ curl \ + file \ + postgresql-client \ + && rm -rf /var/lib/apt/lists/* + + +#------------------------------------------------------------------------ +# Configure https://packages.sury.org/php/ to get latests PHP versions +#------------------------------------------------------------------------ +RUN apt-get update \ + && apt-get install --no-install-recommends -y gnupg2 software-properties-common \ + && add-apt-repository -y ppa:ondrej/php \ + && apt-get remove -y software-properties-common \ && rm -rf /var/lib/apt/lists/* #---------------------------------------------------------------------- -# Configure PHP +# Install Apache, PHP and its extensions +# TODO : php8.3-pcntl ? #---------------------------------------------------------------------- -COPY .docker/php.ini /usr/local/etc/php/conf.d/app.ini +RUN apt-get update \ + && apt-get install --no-install-recommends -y \ + apache2 php8.3 libapache2-mod-php8.3 \ + php8.3-opcache php8.3-xml \ + php8.3-pdo php8.3-pgsql php8.3-zip \ + && rm -rf /var/lib/apt/lists/* + +#------------------------------------------------------------------------ +# Add helper script to start apache +# (see https://github.com/docker-library/php) +#------------------------------------------------------------------------ +COPY .docker/apache2-foreground /usr/local/bin/apache2-foreground +RUN chmod +x /usr/local/bin/apache2-foreground + +#------------------------------------------------------------------------ +# Create apache2 repository +# (see https://github.com/docker-library/php) +#------------------------------------------------------------------------ +RUN mkdir -p /var/run/apache2 && chown -R www-data:www-data /var/run/apache2 \ + && mkdir -p /var/lock/apache2 && chown -R www-data:www-data /var/lock/apache2 \ + && mkdir -p /var/log/apache2 && chown -R www-data:www-data /var/log/apache2 + +#------------------------------------------------------------------------ +# Redirects logs to stdout / stderr +# (see https://github.com/docker-library/php) +#------------------------------------------------------------------------ +RUN ln -sfT /dev/stderr "/var/log/apache2/error.log" \ + && ln -sfT /dev/stdout "/var/log/apache2/access.log" \ + && ln -sfT /dev/stdout "/var/log/apache2/other_vhosts_access.log" \ + && chown www-data:www-data /var/log/apache2/*.log + #---------------------------------------------------------------------- -# Install PHP extensions +# Configure PHP #---------------------------------------------------------------------- -RUN apt-get update -qq \ - && apt-get install --no-install-recommends -y postgresql-client libpq-dev libzip-dev \ - && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ - && docker-php-ext-install opcache pdo pdo_pgsql pgsql zip pcntl \ - && rm -rf /var/lib/apt/lists/* +COPY .docker/php.ini /etc/php/8.3/apache2/php.ini +# TODO .docker/php.ini /etc/php/8.3/cli/php.ini #---------------------------------------------------------------------- # Configure apache @@ -59,6 +100,7 @@ COPY .docker/apache-vhost.conf /etc/apache2/sites-available/000-default.conf RUN a2enmod rewrite remoteip + #---------------------------------------------------------------------- # Setup validator-cli.jar dependencies (java & ogr2ogr) #---------------------------------------------------------------------- diff --git a/.docker/apache2-foreground b/.docker/apache2-foreground new file mode 100644 index 0000000..b662e4e --- /dev/null +++ b/.docker/apache2-foreground @@ -0,0 +1,32 @@ +#!/bin/bash +set -e + +# Adapted from docker/php removing folders creation at runtime (requires root) +# src : https://github.com/docker-library/php/blob/master/8.3/bullseye/apache/apache2-foreground + +: "${APACHE_CONFDIR:=/etc/apache2}" +: "${APACHE_ENVVARS:=$APACHE_CONFDIR/envvars}" +if test -f "$APACHE_ENVVARS"; then + . "$APACHE_ENVVARS" +fi + +# Apache gets grumpy about PID files pre-existing +: "${APACHE_RUN_DIR:=/var/run/apache2}" +: "${APACHE_PID_FILE:=$APACHE_RUN_DIR/apache2.pid}" +rm -f "$APACHE_PID_FILE" + +# Start apache forwarding SIGINT and SIGTERM to SIGWINCH +APACHE2_PID="" +function stop_apache() +{ + if [ ! -z "$APACHE2_PID" ]; + then + kill -s WINCH $APACHE2_PID + fi +} + +trap stop_apache SIGINT SIGTERM SIGWINCH + +apache2 -DFOREGROUND "$@" & +APACHE2_PID=$! +wait $APACHE2_PID diff --git a/.docker/php.ini b/.docker/php.ini index b3564c5..c5ed415 100755 --- a/.docker/php.ini +++ b/.docker/php.ini @@ -1,6 +1,9 @@ ; config/php.ini date.timezone = Europe/Paris +# hide php version +expose_php = off + opcache.enable = 1 opcache.enable_cli = 1 opcache.memory_consumption = 128