FROM php:8.2-fpm

# Installer les dépendances système
RUN apt-get update && apt-get install -y \
        git \
        unzip \
        libpq-dev \
        libicu-dev \
        libzip-dev \
        nginx \
        supervisor \
        netcat-openbsd \
        && docker-php-ext-install pdo pdo_pgsql zip intl opcache \
        && apt-get clean && rm -rf /var/lib/apt/lists/*

# Installer Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Définir le répertoire de travail
WORKDIR /var/www/pollaris

# Cloner Pollaris et passer sur le dernier tag
RUN git clone https://framagit.org/pollaris/pollaris.git . \
    && git checkout $(git describe --tags $(git rev-list --tags --max-count=1)) \
    && composer install --no-dev --optimize-autoloader --no-scripts

RUN mkdir -p /var/www/pollaris/var/cache /var/www/pollaris/var/log \
    && chown -R www-data:www-data /var/www/pollaris/var
    
EXPOSE 80

CMD ["sh", "-c", "php-fpm -F & nginx -g 'daemon off;'"]
