ARG DRUPAL_IMAGE=drupal:11.4.10-php8.4-apache-trixie
FROM ${DRUPAL_IMAGE}

# Fetch the release directly so a PECL outage cannot block local startup.
RUN curl --fail --silent --show-error --location \
       --retry 5 --retry-all-errors --retry-delay 2 --retry-max-time 120 \
       --connect-timeout 20 --max-time 60 \
       --output /tmp/xdebug.tgz \
       https://xdebug.org/files/xdebug-3.5.3.tgz \
    && pecl install /tmp/xdebug.tgz \
    && docker-php-ext-enable xdebug \
    && rm /tmp/xdebug.tgz
ENV XDEBUG_MODE=off

WORKDIR /opt/drupal
# Resolve runtime and test tools together to avoid incompatible partial locks.
RUN composer config \
       allow-plugins.dealerdirect/phpcodesniffer-composer-installer true \
    && composer config allow-plugins.phpstan/extension-installer true \
    && composer require --no-interaction --no-update \
       'drupal/key:^1.22' 'litesaml/lightsaml:^6.1' 'drush/drush:^13' \
    && composer require --dev --no-interaction --no-update \
       'drupal/core-dev:^11.4' 'drupal/coder:^8.3' \
    && composer update --with-all-dependencies --no-interaction --prefer-dist \
    && mkdir -p /opt/drupal/private/saml \
    && chown -R www-data:www-data /opt/drupal/private
ENV PATH="/opt/drupal/vendor/bin:${PATH}"
