ARG DOCKER_PHP_VERSION

FROM php:${DOCKER_PHP_VERSION}-apache-bullseye

ARG DOCKER_NODE_VERSION
ENV DOCKER_NODE_VERSION="${DOCKER_NODE_VERSION}"

# Installer les dépendances et extensions PHP nécessaires
RUN apt-get update && apt-get install -y \
        libicu-dev \
        libpq-dev \
        libpng-dev \
        libzip-dev \
        libxml2-dev \
        ca-certificates \
        gnupg \
        libbz2-dev \
        libgmp-dev \
        libldap2-dev \
        libonig-dev \
        libsodium-dev \
        libxslt1-dev \
        unixodbc-dev \
        libsqlite3-dev \
        zlib1g-dev \
        libssl-dev \
        libc-client-dev \
        libkrb5-dev \
        freetds-dev \
        vim \
        tcpdump \
        dnsutils \
        wget \
        git \
        unzip \
        qpdf \
    && docker-php-ext-install -j$(nproc) \
            intl \
            zip \
            bcmath \
            bz2 \
            calendar \
            exif \
            gd \
            gettext \
            gmp \
            ldap \
#            mysqli \
            pcntl \
            pdo_pgsql \
#            pdo_mysql \
#            pdo_sqlite \
#            pdo_sqlsrv \
            soap \
            sockets \
            sysvsem \
            xsl


# Installation de node
RUN wget -qO-  "https://nodejs.org/dist/v${DOCKER_NODE_VERSION}/node-v${DOCKER_NODE_VERSION}-linux-x64.tar.xz" | tar xJC /tmp/ && \
    cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/bin /usr/ && \
    cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/include /usr/ && \
    cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/lib /usr/ && \
    cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/share /usr/ && \
    npm install --global yarn

# installation/activation d'extensions php
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug && \
    docker-php-ext-install zip && \
    docker-php-ext-install gd && \
    docker-php-ext-install soap && \
    docker-php-ext-configure intl && \
    docker-php-ext-install intl

# Configuration spéciale pour quelques extensions
# RUN docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr && \
#     docker-php-ext-install pdo_odbc \
RUN docker-php-ext-enable opcache

# Configurer Oracle OCI8 (nécessite le SDK Oracle, à installer manuellement ou à lier via les dépendances)
#RUN apt-get update && apt-get -y install wget unzip libaio1 && \
#    wget https://download.oracle.com/otn_software/linux/instantclient/2340000/instantclient-basic-linux.x64-23.4.0.24.05.zip && \
#    unzip -o instantclient-basic-linux.x64-23.4.0.24.05.zip -d /usr/local && \
#    wget https://download.oracle.com/otn_software/linux/instantclient/2340000/instantclient-sdk-linux.x64-23.4.0.24.05.zip && \
#    unzip -o instantclient-sdk-linux.x64-23.4.0.24.05.zip -d /usr/local
#
#RUN echo 'instantclient,/usr/local/instantclient_23_4' | pecl install oci8-3.4.0 \
#    && docker-php-ext-enable oci8
#
#ENV ORACLE_BASE /usr/local/instantclient_23_4
#ENV LD_LIBRARY_PATH /usr/local/instantclient_23_4
#ENV TNS_ADMIN /usr/local/instantclient_23_4
#ENV ORACLE_HOME /usr/local/instantclient_23_4


# Configuration pour utiliser Kerberos avec IMAP (si nécessaire)
# RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
#    && docker-php-ext-install imap

# installation de composer
RUN rm -rf /var/cache/apk/* && rm -rf /tmp/* && \
    curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer

# Création de la structure du projet
RUN mkdir /var/www/html/LOG

# Activation du module pour Apache2 proxy_http et rewrite
RUN a2enmod proxy_http && \
    a2enmod rewrite

###> User ###
ARG CURRENT_UID
ARG CURRENT_GID
# mapping du user host avec www-data
RUN usermod -o -u ${CURRENT_UID} www-data && groupmod -o -g ${CURRENT_GID} www-data
RUN chown www-data:www-data -R /var/www/*
RUN chown www-data:www-data -R /var/www/.*
###< User ###

RUN rm -rf \
        /var/lib/apt/lists/* \
        /tmp/* \
        /var/tmp/*

WORKDIR /var/www/html

EXPOSE 80
