FROM composer:2.10.2@sha256:4d71c3c2109c61d5415544264b59ad4087e4c5b7244481723664138fd36d5040 AS composer

FROM node:22.23.2-bookworm-slim@sha256:d649c27dae7ba0137b3cef5dd75baa422c08dc3d9e3fc0c23dfb172dc3cc6436 AS node

FROM moodlehq/moodle-php-apache:8.4@sha256:07cac70e0ed3f96f334ffeece92075b98adfbe4110312a3a9308b95eab8e2080

ARG MOODLE_PLUGIN_CI_COMMIT=9276f968746960275b12190b4ef8e47b1e6af674
ARG MOODLE_PLUGIN_CI_LOCK_SHA256=e5c8ce77b90f43a057ee717c52e856bf81d43387834dab36083a1c1b17a24be4

COPY --from=composer /usr/bin/composer /usr/local/bin/composer
COPY --from=node /usr/local/bin/node /usr/local/bin/node
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules

RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
    && ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \
    && apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends postgresql-client \
    && rm -rf /var/lib/apt/lists/* \
    && locale-gen en_AU.UTF-8 \
    && git init /opt/moodle-plugin-ci \
    && git -C /opt/moodle-plugin-ci remote add origin https://github.com/moodlehq/moodle-plugin-ci.git \
    && git -C /opt/moodle-plugin-ci fetch --depth 1 origin "${MOODLE_PLUGIN_CI_COMMIT}" \
    && git -C /opt/moodle-plugin-ci checkout --detach FETCH_HEAD \
    && test "$(git -C /opt/moodle-plugin-ci rev-parse HEAD)" = "${MOODLE_PLUGIN_CI_COMMIT}" \
    && echo "${MOODLE_PLUGIN_CI_LOCK_SHA256}  /opt/moodle-plugin-ci/composer.lock" | sha256sum --check \
    && COMPOSER_ALLOW_SUPERUSER=1 composer install \
        --working-dir=/opt/moodle-plugin-ci \
        --no-dev \
        --no-interaction \
        --prefer-dist \
        --classmap-authoritative \
    && ln -s /opt/moodle-plugin-ci/bin/moodle-plugin-ci /usr/local/bin/moodle-plugin-ci

COPY . /plugin

ENV LANG=en_AU.UTF-8

WORKDIR /workspace
