# SPDX-License-Identifier: Apache-2.0
# THE KATA CI RUNNER: ARC's runner image plus the CPU golden image's tool set (ansible roles/ephemeral-runner/files/
# ci-eph-golden, the base bake for class cpu): build tools and Python headers, git-lfs, gh, the Docker CLI with buildx
# and compose at the golden's pins (ARC's older plugins in /usr/local/lib removed: they shadowed apt's; the daemon is
# the pod's dind sidecar, in the same Kata guest), uv, Playwright's OS libraries, and Python 3.10-3.12 / node 18 and
# 20 pre-seeded in the actions tool cache. No GPU bits (no driver, no nvidia-container-toolkit) and no registry-proxy
# CA (kubeadm workers pull registry.arbi.work over its public name).
# Plus the job-started hook ci-git-seed.sh (the node's git mirror -> the job's workspace, see the script).
# Built and pushed once per content tag by .github/workflows/ci-kata-runner-image.yml; argocd-apps pins it by digest
# (clusters/kubeadm/apps/arc-ci-kata-kubeadm.yaml).
FROM ghcr.io/actions/actions-runner:2.338.2@sha256:6d0b2d80d80f143f77dcb676e50920100bbb547e39e883454d57f45ab8c31300
ARG DOCKER_VERSION=29.5.3
ARG BUILDX_VERSION=0.39.0
USER root
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN . /etc/os-release \
 && export DEBIAN_FRONTEND=noninteractive \
 && apt-get update -q \
 && apt-get install -y -q --no-install-recommends ca-certificates curl gnupg jq git git-lfs zstd unzip rsync \
      python3 python3-venv python3-pip python3-dev build-essential pkg-config \
 && install -m 0755 -d /etc/apt/keyrings \
 && curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc \
 && echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $VERSION_CODENAME stable" >/etc/apt/sources.list.d/docker.list \
 && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /etc/apt/keyrings/gh.gpg \
 && echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/gh.gpg] https://cli.github.com/packages stable main" >/etc/apt/sources.list.d/gh.list \
 && apt-get update -q \
 && apt-get install -y -q --no-install-recommends gh docker-compose-plugin \
      "docker-ce-cli=5:${DOCKER_VERSION}-1~ubuntu.${VERSION_ID}~${VERSION_CODENAME}" \
      "docker-buildx-plugin=${BUILDX_VERSION}-1~ubuntu.${VERSION_ID}~${VERSION_CODENAME}" \
 && apt-get install -y -q --no-install-recommends libasound2t64 libatk-bridge2.0-0t64 libatk1.0-0t64 libatspi2.0-0t64 \
      libcairo2 libcups2t64 libdbus-1-3 libdrm2 libgbm1 libglib2.0-0t64 libnspr4 libnss3 libpango-1.0-0 libx11-6 libxcb1 \
      libxcomposite1 libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 xvfb fonts-noto-color-emoji fonts-unifont \
      libfontconfig1 libfreetype6 xfonts-cyrillic xfonts-scalable fonts-liberation fonts-ipafont-gothic fonts-wqy-zenhei \
      fonts-tlwg-loma-otf fonts-freefont-ttf \
 && rm -rf /var/lib/apt/lists/* \
 && rm -f /usr/local/lib/docker/cli-plugins/docker-buildx /usr/local/lib/docker/cli-plugins/docker-compose \
 && docker buildx version | grep -q " v${BUILDX_VERSION} " && docker compose version
RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh
ENV RUNNER_TOOL_CACHE=/opt/hostedtoolcache AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache
COPY tool-cache.py /tmp/tool-cache.py
RUN mkdir -p /opt/hostedtoolcache && python3 /tmp/tool-cache.py && rm /tmp/tool-cache.py \
 && chown -R runner:runner /opt/hostedtoolcache
COPY --chmod=0755 ci-git-seed.sh /opt/ci-kata/ci-git-seed.sh
ENV ACTIONS_RUNNER_HOOK_JOB_STARTED=/opt/ci-kata/ci-git-seed.sh
RUN . /etc/os-release && echo "image base: $PRETTY_NAME, $(python3 -V), $(git --version), $(docker --version)"
USER runner
