From 0bb7e6f6da5e39e7b67c455e740ebe855b1f0bef Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 2 Dec 2026 20:55:13 +0100 Subject: [PATCH] Run HPC lanes on the hpc VM runners with named pull credentials Co-Authored-By: Claude Opus 5.5 --- docs/configuring/hpc.rst | 18 +++++++++++------- docs/configuring/job-scripts.rst | 5 +++-- docs/reference/hpc.rst | 5 +++-- docs/reference/runners.rst | 6 +++--- src/ci_infrastructure/ci_yml.py | 6 ++---- .../generate_downstream_ci.py | 14 ++++++++------ src/ci_infrastructure/manifest.py | 17 ++++++++++++++--- tests/test_generate_hpc.py | 17 ++++++++++++++++- 8 files changed, 60 insertions(+), 28 deletions(-) diff --git a/docs/configuring/hpc.rst b/docs/configuring/hpc.rst index 6dae5ece..2c6264ff 100644 --- a/docs/configuring/hpc.rst +++ b/docs/configuring/hpc.rst @@ -12,7 +12,8 @@ while dependencies, artifact names and publishing work as for any other kind. How it works ------------ -The job itself runs on a small runner group, ``hpc-submit`` (see :doc:`../reference/runners`). +The job itself runs on the runner group ``hpc`` (see :doc:`../reference/runners`), +in the ``atos-citester`` image, whose ssh configuration connects as the ``citester`` user. This runner downloads the dependencies from the artifact store, ships them together with the source to the HPC, and submits the build script through `troika `__. Once the job has finished, it copies the install tree back and uploads it to the artifact store. @@ -28,7 +29,7 @@ The manifest [matrix.build-hpc] execution = "hpc-atos" triggers = ["upstream-change", "rebuild-request"] - container-credentials = true + container-credentials = "ECCR_PULL_ATOS_CITESTER" [matrix.build-hpc.defaults] job-script = "./.ci/hpc/build.sh.j2" @@ -36,8 +37,8 @@ The manifest cxx-compiler = "g++-8" fortran-compiler = "gfortran-8" build-type = "RelWithDebInfo" - runs-on = "hpc-submit" - container = "eccr.ecmwf.int/private-ci-images/ubuntu24.04-internal-tools:latest" + runs-on = "hpc" + container = "eccr.ecmwf.int/private-ci-images-atos-citester/ubuntu24.04-hpc-runner:latest" site = "hpc-batch" modules = ["load prgenv/gnu", "unload gcc", "load gcc/old", "load cmake", "load ninja"] c-compiler-binary = "gcc" @@ -51,6 +52,9 @@ The manifest [[matrix.build-hpc.include]] options = "eckit-geo" +``container-credentials`` names the pair of secrets the image is pulled with, +here ``ECCR_PULL_ATOS_CITESTER_NAME`` and ``ECCR_PULL_ATOS_CITESTER_TOKEN``; +``true`` stands for ``ECCR_PULL_ROBOT_NAME`` and ``ECCR_PULL_ROBOT_TOKEN``. ``job-script`` points to the build script, and every field of a leg is passed to it. It is a leg field, so a leg may bring its own build script. A build on the HPC usually needs control over the exact modules, the job's resources and the like, @@ -84,15 +88,15 @@ The above manifest would then require two hand-written shell scripts and look li [matrix.build-hpc] execution = "hpc-atos" triggers = ["upstream-change", "rebuild-request"] - container-credentials = true + container-credentials = "ECCR_PULL_ATOS_CITESTER" [matrix.build-hpc.defaults] platform = "hpc-atos-gnu" cxx-compiler = "g++-8" fortran-compiler = "gfortran-8" build-type = "RelWithDebInfo" - runs-on = "hpc-submit" - container = "eccr.ecmwf.int/private-ci-images/ubuntu24.04-internal-tools:latest" + runs-on = "hpc" + container = "eccr.ecmwf.int/private-ci-images-atos-citester/ubuntu24.04-hpc-runner:latest" site = "hpc-batch" [[matrix.build-hpc.include]] diff --git a/docs/configuring/job-scripts.rst b/docs/configuring/job-scripts.rst index 50923885..1ac5dcde 100644 --- a/docs/configuring/job-scripts.rst +++ b/docs/configuring/job-scripts.rst @@ -197,11 +197,12 @@ and a new Python is added upstream first. [matrix.test-hpc] execution = "hpc-atos" publishes = false + container-credentials = "ECCR_PULL_ATOS_CITESTER" [[matrix.test-hpc.include]] job-script = "./.ci/test.sh.j2" - runs-on = "hpc-submit" - container = "eccr.ecmwf.int/private-ci-images/ubuntu24.04-internal-tools" + runs-on = "hpc" + container = "eccr.ecmwf.int/private-ci-images-atos-citester/ubuntu24.04-hpc-runner:latest" site = "hpc-batch" platform = "hpc-atos" modules = ["load uv"] diff --git a/docs/reference/hpc.rst b/docs/reference/hpc.rst index 9f0e0ccc..2113340c 100644 --- a/docs/reference/hpc.rst +++ b/docs/reference/hpc.rst @@ -12,7 +12,7 @@ The flow of a job :: - hpc-submit runner + hpc runner resolve -> fetch deps (S3) -> submit -> ship source, deps, marker -> wait -> fetch install -> publish | ^ v troika | Finished: SUCCESS/FAILURE @@ -225,7 +225,8 @@ Cluster configuration - ``vars.HPC_CI_REMOTE_WORK_DIR`` is the base directory on the cluster, recommended ``$SCRATCH/github-ci``. It is expanded on the cluster, in a login shell, and must yield an absolute path. - ``vars.HPC_CI_WORK_DIR`` is a scratch directory on the runner, by default ``$RUNNER_TEMP``. -- ``secrets.HPC_CI_SSH_USER`` optionally sets the user on the cluster. +- ``secrets.HPC_CI_SSH_USER`` optionally sets the user on the cluster for the HPC actions; + the generated HPC jobs leave it to the image's ssh configuration. On ECMWF's Atos, staging and install go to ``$SCRATCH``, shared Lustre with a 30-day purge, and the build to ``$TMPDIR``, the node-local SSD, whose size ``ssdtmp`` requests. diff --git a/docs/reference/runners.rst b/docs/reference/runners.rst index d12f6224..aa0bd73e 100644 --- a/docs/reference/runners.rst +++ b/docs/reference/runners.rst @@ -29,13 +29,13 @@ The following runner groups for the CI exist on the self-hosted Kubernetes clust - 4 / 16 - 8 / 32 GiB - 50 GiB - * - ``hpc-submit`` + * - ``hpc`` - — - — - 50 GiB -The HPC is reached through the runner group ``hpc-submit``. -These runners are small and cheap and are not meant for heavy lifting. +The HPC is reached through the runner group ``hpc``, virtual machines at ECMWF. +They are not meant for heavy lifting. They ship sources and dependencies to the HPC and submit the job to the queue. Afterwards they copy the artifacts back and store it in S3. See :doc:`../configuring/hpc`. diff --git a/src/ci_infrastructure/ci_yml.py b/src/ci_infrastructure/ci_yml.py index f2a08ed8..f8997b10 100644 --- a/src/ci_infrastructure/ci_yml.py +++ b/src/ci_infrastructure/ci_yml.py @@ -29,6 +29,7 @@ _reader_mint_step, _rebuild_job, _render_doc, + container_credentials, upstream_repos, ) from .manifest import FROM_DEPENDENCIES_RE, VISIBILITY_PUBLIC @@ -183,10 +184,7 @@ def _kind_job(m: Manifest, kind: str, *, repos: Sequence[str], waits: Mapping[st container: dict[str, Any] = {"image": "${{ matrix.container || '' }}"} if mk.container_credentials: - container["credentials"] = { - "username": "${{ secrets.ECCR_PULL_ROBOT_NAME }}", - "password": "${{ secrets.ECCR_PULL_ROBOT_TOKEN }}", - } + container["credentials"] = container_credentials(mk.container_credentials) # `build` runs the tests too, unless a `test` kind does. title = "build+test" if kind == "build" and "test" not in ci_kinds(m) else kind return { diff --git a/src/ci_infrastructure/generate_downstream_ci.py b/src/ci_infrastructure/generate_downstream_ci.py index 5889412a..f4f5e7c1 100644 --- a/src/ci_infrastructure/generate_downstream_ci.py +++ b/src/ci_infrastructure/generate_downstream_ci.py @@ -235,7 +235,7 @@ class MatrixKind: legs: Sequence[dict[str, Any]] # after reuse-matrix resolution execution: Execution publishes: bool - container_credentials: bool + container_credentials: bool | str artifact_prefix: str | None = None # The prefixes this kind publishes; empty when it publishes nothing. packages: tuple[str, ...] = () @@ -985,6 +985,12 @@ def _job_script_step(m: Manifest, mk: MatrixKind) -> Step: } +def container_credentials(value: bool | str) -> dict[str, str]: + """The registry credentials of `container-credentials`: `true` or a secret-pair prefix.""" + prefix = "ECCR_PULL_ROBOT" if value is True else value + return {"username": f"${{{{ secrets.{prefix}_NAME }}}}", "password": f"${{{{ secrets.{prefix}_TOKEN }}}}"} + + def _hpc_build_step(mk: MatrixKind) -> Step: """Submit the leg's recipe to the cluster; the action also publishes.""" with_block: dict[str, str] = { @@ -995,7 +1001,6 @@ def _hpc_build_step(mk: MatrixKind) -> Step: "cmake-prefix-path": "${{ steps.deps.outputs.cmake-prefix-path }}", "work-dir": "${{ vars.HPC_CI_WORK_DIR }}", "remote-work-dir": "${{ vars.HPC_CI_REMOTE_WORK_DIR }}", - "troika-user": "${{ secrets.HPC_CI_SSH_USER }}", } if not mk.publishes: with_block["publish"] = "false" @@ -1192,10 +1197,7 @@ def _kind_job(m: Manifest, kind: str, cross: Sequence[JobRef], repos: Sequence[s # An empty image runs on the host. HPC legs need it too: the ssh identity lives in the image. container: dict[str, Any] = {"image": "${{ matrix.container || '' }}"} if mk.container_credentials: - container["credentials"] = { - "username": "${{ secrets.ECCR_PULL_ROBOT_NAME }}", - "password": "${{ secrets.ECCR_PULL_ROBOT_TOKEN }}", - } + container["credentials"] = container_credentials(mk.container_credentials) job["container"] = container job["strategy"] = { "fail-fast": False, diff --git a/src/ci_infrastructure/manifest.py b/src/ci_infrastructure/manifest.py index fa4212be..d97f09e2 100644 --- a/src/ci_infrastructure/manifest.py +++ b/src/ci_infrastructure/manifest.py @@ -18,6 +18,7 @@ BaseModel, ConfigDict, Field, + StrictBool, StrictInt, ValidationError, ValidationInfo, @@ -518,11 +519,12 @@ class MatrixKindTable(_Table): "`[package]`, or every `[packages]` entry when `[package]` is `meta`. With `publishes = false`, the " "packages it builds and tests against their deps without publishing them.", ) - container_credentials: bool = Field( - strict=True, + container_credentials: StrictBool | str = Field( default=False, alias="container-credentials", - description="Pull the leg's `container` with registry credentials.", + description="Pull the leg's `container` with registry credentials: `true` for the " + '`ECCR_PULL_ROBOT_NAME`/`_TOKEN` secrets, or the prefix of another pair, e.g. `"ECCR_PULL_ATOS_CITESTER"` ' + "for `ECCR_PULL_ATOS_CITESTER_NAME`/`_TOKEN`.", ) ci: bool = Field( strict=True, @@ -566,6 +568,15 @@ def _artifact_prefix_shape(cls, v: str | None) -> str | None: ) return stripped + @field_validator("container_credentials") + @classmethod + def _credentials_prefix(cls, v: bool | str) -> bool | str: + if isinstance(v, str) and not re.fullmatch(r"[A-Z][A-Z0-9_]*", v): + raise ValueError( + f"container-credentials must be true, false or a secret prefix like ECCR_PULL_ROBOT; got {v!r}" + ) + return v + class GeneratedTable(_Table): """`[generated]`: how the generated workflows are written.""" diff --git a/tests/test_generate_hpc.py b/tests/test_generate_hpc.py index 0feaffdf..5d285cf2 100644 --- a/tests/test_generate_hpc.py +++ b/tests/test_generate_hpc.py @@ -50,7 +50,6 @@ def hpc_yaml(tmp_path: Path) -> str: "site: ${{ matrix.site }}", "actions/fetch-deps@main", "cmake-prefix-path: ${{ steps.deps.outputs.cmake-prefix-path }}", - "troika-user: ${{ secrets.HPC_CI_SSH_USER }}", "stage-only: 'true'", "runs-on: ${{ matrix['runs-on'] }}", "image: ${{ matrix.container || '' }}", @@ -131,6 +130,22 @@ def test_container_credentials_are_opt_in(tmp_path: Path) -> None: assert "password: ${{ secrets.ECCR_PULL_ROBOT_TOKEN }}" in yaml +def test_container_credentials_name_a_secret_pair(tmp_path: Path) -> None: + yaml = render_single( + tmp_path, + _HPC_MANIFEST.replace( + 'execution = "hpc-atos"', 'execution = "hpc-atos"\ncontainer-credentials = "ECCR_PULL_ATOS_CITESTER"' + ), + EXECUTION_HPC_ATOS, + ) + assert "username: ${{ secrets.ECCR_PULL_ATOS_CITESTER_NAME }}" in yaml + assert "password: ${{ secrets.ECCR_PULL_ATOS_CITESTER_TOKEN }}" in yaml + + +def test_hpc_job_leaves_the_user_to_the_image(hpc_yaml: str) -> None: + assert "troika-user" not in hpc_yaml + + def test_legs_differing_only_by_site_collide(tmp_path: Path) -> None: """`site` is scheduling, not artifact identity.""" write_repo(