# CI image for unsupervised-scheduler, one tag per PHP version.
#
# Built and published by .gitea/workflows/ci-images.yml to
# git.unsupervised.ca/unsupervised/ci-php:<php-version>. CI and release jobs
# run inside it via `container:`, so nothing installs PHP at job time.
#
# Why: setup-php installs 8.3+ through apt/the ondrej PPA on these arm64
# runners — a ~145s floor against ~35s for 8.1/8.2, with a tail that has
# twice crossed into hard failure (#178). Pulling a ~120MB image from the
# registry in our own cluster replaces that entirely (#187).

ARG PHP_VERSION=8.3
FROM php:${PHP_VERSION}-cli-alpine

# bash and nodejs are not optional: act_runner executes JavaScript actions
# (actions/checkout, actions/cache, actions/upload-artifact) *inside* the job
# container, and shells `run:` steps through bash.
#
# coreutils, gawk, grep, sed and tar replace the busybox applets with the GNU
# ones the workflow scripts are written against (`tac`, `grep --include`).
# tar is not optional: actions/cache shells out to `tar --posix -P`, which
# busybox rejects outright, so every cache step fails without it. zstd is what
# actions/cache prefers over gzip when it is present.
#
# jq, curl, git and zip/unzip are used by release.yml and bin/build-zip.sh.
RUN apk add --no-cache \
        bash \
        coreutils \
        curl \
        gawk \
        git \
        grep \
        jq \
        nodejs \
        sed \
        tar \
        unzip \
        zip \
        zstd \
        icu-libs \
        libzip \
 && apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        icu-dev \
        libzip-dev \
 && docker-php-ext-install -j"$(nproc)" intl zip \
 && apk del --no-network .build-deps

# mbstring is compiled into the official php images; intl and zip are added
# above. That covers what phpunit, phpstan, phpcs and Composer need.

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Jobs run as root inside the container, and never answer prompts.
ENV COMPOSER_ALLOW_SUPERUSER=1 \
    COMPOSER_NO_INTERACTION=1 \
    COMPOSER_HOME=/composer

RUN mkdir -p "$COMPOSER_HOME" \
 && tar --version | head -1 | grep -q 'GNU tar' \
 && php -v \
 && php -m | grep -qx intl \
 && php -m | grep -qx mbstring \
 && composer --version

CMD ["/bin/bash"]
