# CI/CD PHP Image with Firebird Extension
# Purpose: PHPUnit testing in GitLab CI with Firebird database support

FROM webdevops/php-apache-dev:8.4

# Install system dependencies and Firebird client libraries
RUN apt-get update --allow-releaseinfo-change && \
    apt-get install -y \
    software-properties-common \
    firebird-dev \
    firebird3.0-utils \
    libsmbclient \
    libsmbclient-dev \
    git \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Extract PHP source for extension compilation
RUN docker-php-source extract

# Install php-firebird v12.0.0 extension (OO API + opaque objects)
# Note: Batch API (FB_API_VER>=40) and pdo_fbird are NOT compiled with
# FB3 client headers (apt firebird-dev). Install FB5 client to enable
# (see satag-amicron-entity-bundle docker/appserver/Dockerfile).
# OO API PHP files (Firebird\Connection, Database, TBuilder, etc.) required by v12.
RUN git clone --branch v12.0.0 --depth 1 https://github.com/satwareAG/php-firebird.git /usr/src/php/ext/firebird && \
    docker-php-ext-install firebird && \
    mkdir -p /usr/local/lib/php/Firebird && \
    cp /usr/src/php/ext/firebird/src/Firebird/*.php /usr/local/lib/php/Firebird/

# Install libsmbclient PHP extension (optional, for SMB functionality)
RUN git clone --branch 1.1.1 --depth 1 https://github.com/eduardok/libsmbclient-php.git /usr/src/php/ext/libsmbclient-php && \
    docker-php-ext-install libsmbclient-php

# Install PCOV for code coverage (faster than Xdebug)
RUN pecl install pcov && \
    docker-php-ext-enable pcov

# Set up Node.js 22 LTS repository
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 && \
    NODE_MAJOR=22 && \
    echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list

# Set up Yarn repository
RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null && \
    echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list

# Install Node.js and Yarn
RUN apt-get update && \
    apt-get install -y yarn nodejs && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Verify installations
RUN php -m | grep -i firebird && \
    php -v && \
    node --version && \
    yarn --version && \
    which gbak
