Skip to content

Commit

Permalink
Merge pull request #75 from IGNF/validtri-docker-ubuntu
Browse files Browse the repository at this point in the history
Validtri docker ubuntu
  • Loading branch information
cboucheIGN authored Dec 2, 2024
2 parents 139a8a4 + 34815ce commit 722fbf1
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 13 deletions.
68 changes: 55 additions & 13 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#----------------------------------------------------------------------
# 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
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
Expand All @@ -33,22 +34,62 @@ RUN apt-get update && apt-get install --no-install-recommends -y locales \
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
unzip zip \
curl \
curl wget \
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
Expand All @@ -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)
#----------------------------------------------------------------------
Expand All @@ -75,7 +117,7 @@ RUN apt-get update -qq \
#----------------------------------------------------------------------
ARG validator_version=4.4.5
RUN mkdir -p /opt/ign-validator \
&& curl -sS -o ${VALIDATOR_PATH} https://github.com/IGNF/validator/releases/download/v${validator_version}/validator-cli.jar \
&& wget --quiet -O ${VALIDATOR_PATH} https://github.com/IGNF/validator/releases/download/v${validator_version}/validator-cli.jar \
&& echo "validator-cli.jar version : $(java -jar /opt/ign-validator/validator-cli.jar version)"

#----------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions .docker/apache2-foreground
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .docker/php.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 722fbf1

Please sign in to comment.