# pb-ci — the Linux image package-ci.sh and scripts/engine-suite.sh run in.
#
# Build:  docker build -t pb-ci:latest harness/engine/scripts/ci-image
#
# Why this file exists (2026-10-09, fix/package-ci): pb-ci was built by hand on
# 2026-10-02 with Ubuntu's nodejs (v18) and no uv or PHP, and no definition was
# committed. package-ci gate 6 then failed two example scenarios on missing
# tools rather than on anything the engine did, and nobody could rebuild the
# image. The toolchain below mirrors the GitHub `stack-pack-examples` job in
# .github/workflows/harness-orchestrator-suites.yml, so a local run and CI agree.
#
#   bash 5 + GNU userland   Ubuntu 24.04 (the engine's Linux support target)
#   node 22.18+             the vue example's node:test suite needs type stripping
#   python 3.12 + uv        the stack-python-uv pack runs its gates via `uv run`
#   php 8.3 + composer      the stack-laravel pack; without them the scenario
#                           falls back to docker shims, and there is no docker here
#   shellcheck              package-ci gate 1 runs it when installed

ARG NODE_IMAGE=node:22.23.3-bookworm-slim
ARG UV_IMAGE=ghcr.io/astral-sh/uv:0.8.22

FROM ${NODE_IMAGE} AS node
FROM ${UV_IMAGE} AS uv

FROM ubuntu:24.04

RUN apt-get update -qq \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
      git jq python3 python3-venv ca-certificates procps psmisc file shellcheck \
      php8.3-cli php8.3-mbstring php8.3-xml composer \
 && rm -rf /var/lib/apt/lists/* \
 && ln -sf /usr/bin/python3 /usr/local/bin/python

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 -sf ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
 && ln -sf ../lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx \
 && node -e 'if (!process.features.typescript) { console.error("node " + process.version + " lacks type stripping (need 22.18+)"); process.exit(1) }'

COPY --from=uv /uv /uvx /usr/local/bin/

# A UTF-8 locale: shellcheck aborts on every script with a non-ASCII character
# (the engine's comments use em-dashes) under the default POSIX locale
# ("commitBuffer: invalid argument (invalid character)"), which read as a red
# gate 1 rather than as shellcheck findings.
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

RUN git config --global user.email ci@example.invalid \
 && git config --global user.name ci \
 && git config --global core.autocrlf false \
 && git config --global init.defaultBranch main \
 && git config --global --add safe.directory '*'

WORKDIR /repo
