# Volume-free GitHub Actions org runner, for Railway replicas.
# Railway: "Replicas are not available for attached volumes", and each replica is its own container
# with its own pids cgroup, so runner capacity scales by replica count instead of being capped at
# 3-4 runners per mesh VM. Build context is the repository root (`railway up` uploads the linked
# project; RAILWAY_DOCKERFILE_PATH=deploy/ci-runner-image/Dockerfile) so the image reuses the mesh VMs' own package list, toolchain installer, sudo shim, Chrome wrapper
# and job hook: one definition of a runner's environment, two hosts.
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
COPY deploy/mesh-vm/ci-runners/boot.sh deploy/mesh-vm/ci-runners/boot-pkgs-browser.txt /tmp/ci/
RUN pkgs=$(sed -n 's/^NEED_PKGS="\([^"$]*\)"$/\1/p' /tmp/ci/boot.sh | head -1) \
 && test -n "$pkgs" \
 && apt-get update -qq \
 && apt-get install -y -qq --no-install-recommends $pkgs $(tr '\n' ' ' < /tmp/ci/boot-pkgs-browser.txt) util-linux \
 && rm -rf /var/lib/apt/lists/*
COPY deploy/mesh-vm/ci-runners/install-toolchain.sh /tmp/ci/
RUN bash /tmp/ci/install-toolchain.sh /opt/ci/bin /opt/ci/opt \
 && PATH="/opt/ci/opt/node/bin:$PATH" PLAYWRIGHT_BROWSERS_PATH=/opt/ci/ms-playwright /opt/ci/opt/node/bin/npx -y playwright@1.52.0 install chromium \
 && chmod -R a+rX /opt/ci/ms-playwright \
 && mkdir -p /opt/actions-runner-dist \
 && curl -fsSL https://github.com/actions/runner/releases/download/v2.338.2/actions-runner-linux-x64-2.338.2.tar.gz \
    | tar -xz -C /opt/actions-runner-dist
# (the runner's .NET dependencies, libicu74/libkrb5-3/zlib1g, are in boot.sh's NEED_PKGS above)
# Each slot runs as runner1..N with its own private root:slotN 0710 cache box (#417), so no
# group-writable shared toolcache, Python dir or Playwright cache is exposed across slots.
RUN useradd -m -s /bin/bash runner \
 && chmod 0750 /home/runner \
 && for b in /opt/ci/bin/*; do ln -sfn "$b" "/usr/local/bin/$(basename "$b")"; done
COPY deploy/mesh-vm/ci-runners/sudo-shim.sh /opt/ci/bin/sudo
COPY deploy/mesh-vm/ci-runners/google-chrome-wrapper.sh /opt/ci/bin/google-chrome
COPY deploy/mesh-vm/ci-runners/ci-job-started.sh /opt/ci/ci-job-started.sh
COPY deploy/ci-runner-image/entrypoint.sh /opt/ci/entrypoint.sh
RUN chmod 0755 /opt/ci/bin/sudo /opt/ci/bin/google-chrome /opt/ci/ci-job-started.sh /opt/ci/entrypoint.sh \
 && ln -sfn /opt/ci/bin/google-chrome /opt/ci/bin/chromium \
 && rm -rf /tmp/ci
ENTRYPOINT ["/opt/ci/bin/tini", "--", "/opt/ci/entrypoint.sh"]
