Publishing worked; everything after it did not. Four things were wrong and each was silent in its own way. Versions were compared as text, so asking for "gromacs" with 2024.9 and 2024.10 published returned 2024.9. The whole meaning of an unversioned reference is "the newest one", and it was a wrong answer rather than a missing one - invisible until somebody noticed they had spent a week on last year's build. A recipe could hold one version while the catalogue could hold many, so an update either destroyed what it replaced or grew a parallel directory sharing nothing with the first. Recipes now carry a list, and the single-version form is read into the same shape, so nothing downstream knows which was written. An image was named by a mutable tag. Whoever repushes gromacs:2024.4 changed what every rebuilt cluster received, silently, and the record meant to freeze the cluster froze only its opinion of it. Two hashes are now recorded because they are checkable in different places: the manifest digest answers "has this moved" from the control plane, and the SIF hash is the only one a head can check with no network and no credential - which matters, because the head is where a wrong image does harm. Pulling by digest is deliberately not done: whether this Apptainer accepts an @sha256: reference is not established, and a provision failing at its last task over untested syntax would be worse than the problem. Module and binaries had been in the catalogue since it was written and were read by nothing - Module was referenced nowhere in the program. So a tenant was handed /opt/apps/gromacs.sif and left to work out Apptainer. They now become a wrapper per binary and an Lmod modulefile, and the answer is `module load gromacs`. Whether to pass --nv is decided on the node at run time: passing it without a driver fails outright, and omitting it where there is one leaves the job on the CPU saying nothing at all, which is the dangerous one. Four states replace `published:`. A withdrawn entry stays in the catalogue file, because dropping it would make it indistinguishable from one that never existed - and that difference is what an operator needs when a cluster is found still holding it. A pinned reference to one is refused with the recorded reason instead of "no application", which would send the user hunting for a typo in a correct name. The portal re-reads the catalogue when it changes, so publishing an application no longer needs a restart - the step that is invisible when forgotten. C20 ships the catalogue, which nothing did. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
252 lines
9.6 KiB
YAML
252 lines
9.6 KiB
YAML
---
|
|
# Fetch the application images this cluster was asked for.
|
|
#
|
|
# The catalogue lives on the control plane, because deciding what exists and
|
|
# what it requires is a platform question. By the time a cluster is
|
|
# provisioned those names have already been resolved, so what arrives here is
|
|
# a list of image references and nothing else - the head needs no catalogue,
|
|
# no credentials for one, and no opinion about what an application is.
|
|
#
|
|
# Images land in /opt/apps. /opt is exported read-only to the compute nodes
|
|
# already (see the slurm role's NFS exports), so pulling once on the head
|
|
# makes an image visible on every node without copying it anywhere.
|
|
|
|
- name: Install the container runtime on the head
|
|
ansible.builtin.dnf:
|
|
name: apptainer
|
|
state: present
|
|
# Not apptainer-suid. The node image makes the same choice for the same
|
|
# reason: a setuid-root binary on a machine running other people's jobs
|
|
# is an attack surface that user namespaces make unnecessary.
|
|
install_weak_deps: false
|
|
tags: [install]
|
|
|
|
- name: Refuse to run with a setuid starter present
|
|
ansible.builtin.command:
|
|
cmd: rpm -q apptainer-suid
|
|
register: apps_suid
|
|
changed_when: false
|
|
failed_when: apps_suid.rc == 0
|
|
tags: [install]
|
|
|
|
- name: Make the shared application directory
|
|
ansible.builtin.file:
|
|
path: "{{ apps_dir }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
|
|
# Pulled one at a time rather than in a shell loop so a failure names the
|
|
# application that failed. An image that cannot be fetched fails the
|
|
# provision: a cluster that comes up without the software it was requested
|
|
# for looks healthy and is useless, which is worse than not coming up.
|
|
- name: Fetch each application image
|
|
ansible.builtin.command:
|
|
cmd: >-
|
|
apptainer pull --allow-unsigned
|
|
{{ apps_dir }}/{{ item.name }}.sif {{ item.image }}
|
|
creates: "{{ apps_dir }}/{{ item.name }}.sif"
|
|
loop: "{{ cluster_apps | default([], true) }}"
|
|
loop_control:
|
|
label: "{{ item.name }}"
|
|
environment:
|
|
APPTAINER_CACHEDIR: /var/cache/apptainer
|
|
|
|
- name: Make the images readable on the nodes
|
|
ansible.builtin.file:
|
|
path: "{{ apps_dir }}/{{ item.name }}.sif"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
loop: "{{ cluster_apps | default([], true) }}"
|
|
loop_control:
|
|
label: "{{ item.name }}"
|
|
|
|
# Check the bytes against what the control plane recorded when this cluster
|
|
# was allocated.
|
|
#
|
|
# A tag is mutable. oras://.../gromacs:2024.4 names whatever was last pushed
|
|
# under that name, so a cluster rebuilt after somebody repushed it gets
|
|
# different software while every record still says 2024.4. The hash is the
|
|
# only thing that notices.
|
|
#
|
|
# The file, not the manifest digest: checking the digest would mean a
|
|
# registry round trip and a credential from a tenant's head node, and the
|
|
# file is what the jobs will actually run.
|
|
- name: Hash each application image
|
|
ansible.builtin.stat:
|
|
path: "{{ apps_dir }}/{{ item.name }}.sif"
|
|
checksum_algorithm: sha256
|
|
get_checksum: true
|
|
register: apps_hashes
|
|
loop: "{{ cluster_apps | default([], true) }}"
|
|
loop_control:
|
|
label: "{{ item.name }}"
|
|
|
|
# Fails the provision rather than warning. An image that is not the one this
|
|
# cluster was allocated is not a smaller version of the right cluster; it is
|
|
# a different cluster, and the tenant has no way to find that out later.
|
|
- name: Refuse an image that is not the one this cluster was allocated
|
|
ansible.builtin.assert:
|
|
that:
|
|
- item.0.stat.checksum == item.1.sif_sha256
|
|
fail_msg: >-
|
|
{{ item.1.name }}: {{ apps_dir }}/{{ item.1.name }}.sif is
|
|
sha256:{{ item.0.stat.checksum }}, but this cluster was allocated
|
|
sha256:{{ item.1.sif_sha256 }}. The tag has moved since then.
|
|
success_msg: "{{ item.1.name }}: matches what was allocated"
|
|
when: item.1.sif_sha256 | default('') | length > 0
|
|
loop: "{{ apps_hashes.results | zip(cluster_apps | default([], true)) | list }}"
|
|
loop_control:
|
|
label: "{{ item.1.name }}"
|
|
|
|
# Said out loud rather than passed over. An application published before the
|
|
# hash was recorded cannot be checked, and "not checked" must not read the
|
|
# same as "checked and correct".
|
|
- name: Say which images could not be checked
|
|
ansible.builtin.debug:
|
|
msg: >-
|
|
{{ unverifiable | join(', ') }}: no hash was recorded when this cluster
|
|
was allocated, so what arrived could not be compared with what was
|
|
published. Republish through image/apps/build-push.sh to fix that.
|
|
vars:
|
|
unverifiable: >-
|
|
{{ cluster_apps | default([], true)
|
|
| rejectattr('sif_sha256', 'defined')
|
|
| map(attribute='name') | list
|
|
+ cluster_apps | default([], true)
|
|
| selectattr('sif_sha256', 'defined')
|
|
| selectattr('sif_sha256', 'equalto', '')
|
|
| map(attribute='name') | list }}
|
|
when: unverifiable | length > 0
|
|
|
|
# --- Make them runnable ----------------------------------------------------
|
|
# Up to here the cluster has files. A tenant asked for an application.
|
|
#
|
|
# The catalogue has carried a module name and a list of binaries since it was
|
|
# written and nothing ever read either of them, so what a user actually got
|
|
# was a SIF and no documented way to run it. These tasks turn those two
|
|
# fields into a wrapper per binary and an Lmod modulefile, so the answer to
|
|
# "how do I run this" is `module load gromacs`.
|
|
#
|
|
# Under /opt like the images, because /opt is already exported read-only to
|
|
# the compute nodes. A wrapper written anywhere else would need a second
|
|
# distribution path for it.
|
|
- name: Make the wrapper and module directories
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
loop:
|
|
- "{{ apps_dir }}/bin"
|
|
- "{{ apps_dir }}/modulefiles"
|
|
|
|
- name: Make a directory for each application's wrappers
|
|
ansible.builtin.file:
|
|
path: "{{ apps_dir }}/bin/{{ item.name }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
loop: "{{ cluster_apps | default([], true) }}"
|
|
loop_control:
|
|
label: "{{ item.name }}"
|
|
when: item.binaries | default([]) | length > 0
|
|
|
|
# One wrapper per binary rather than one that dispatches on $0: a user who
|
|
# types `which gmx_mpi` should see something that names gmx_mpi.
|
|
- name: Write a wrapper for each binary
|
|
ansible.builtin.template:
|
|
src: wrapper.sh.j2
|
|
dest: "{{ apps_dir }}/bin/{{ item.0.name }}/{{ item.1 }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
vars:
|
|
app: "{{ item.0 }}"
|
|
binary: "{{ item.1 }}"
|
|
loop: "{{ cluster_apps | default([], true) | subelements('binaries', skip_missing=True) }}"
|
|
loop_control:
|
|
label: "{{ item.0.name }}/{{ item.1 }}"
|
|
|
|
# One directory per module name. template does not create intermediate
|
|
# directories, and the version is a file inside the module's directory rather
|
|
# than part of its name - so without this the task fails with "Destination
|
|
# directory does not exist", in the middle of a provision.
|
|
- name: Make a directory for each module
|
|
ansible.builtin.file:
|
|
path: "{{ apps_dir }}/modulefiles/{{ item.module }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
loop: "{{ cluster_apps | default([], true) }}"
|
|
loop_control:
|
|
label: "{{ item.module | default('') }}"
|
|
when:
|
|
- item.module | default('') | length > 0
|
|
- item.binaries | default([]) | length > 0
|
|
|
|
# Named <module>/<version>, which is what Lmod shows and what a user types.
|
|
# An application that declares no module name gets no modulefile: the
|
|
# wrappers are still there, and inventing a name would put something in
|
|
# `module avail` that the catalogue never promised.
|
|
- name: Write a modulefile for each application
|
|
ansible.builtin.template:
|
|
src: modulefile.j2
|
|
dest: "{{ apps_dir }}/modulefiles/{{ item.module }}/{{ item.version | default('default', true) }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
vars:
|
|
app: "{{ item }}"
|
|
loop: "{{ cluster_apps | default([], true) }}"
|
|
loop_control:
|
|
label: "{{ item.module | default('') }}/{{ item.version | default('') }}"
|
|
when:
|
|
- item.module | default('') | length > 0
|
|
- item.binaries | default([]) | length > 0
|
|
|
|
- name: Put the applications on MODULEPATH at login
|
|
ansible.builtin.template:
|
|
src: profile.sh.j2
|
|
dest: /etc/profile.d/zz-hpcod-apps.sh
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
|
|
# Run one wrapper. A template that rendered, a directory that exists and a
|
|
# file that is executable are three things that are all true of a wrapper
|
|
# which dies on its first invocation - and the first invocation would
|
|
# otherwise be inside a job that had already queued, waited and started.
|
|
#
|
|
# --version is not universal, so the test is that the wrapper reaches the
|
|
# binary at all: `command -v` inside the image, through the same path the
|
|
# wrapper takes.
|
|
- name: Confirm a wrapper actually reaches its binary
|
|
ansible.builtin.command:
|
|
cmd: >-
|
|
apptainer exec {{ apps_dir }}/{{ item.0.name }}.sif
|
|
sh -c "command -v {{ item.1 }}"
|
|
changed_when: false
|
|
loop: "{{ cluster_apps | default([], true) | subelements('binaries', skip_missing=True) }}"
|
|
loop_control:
|
|
label: "{{ item.0.name }}/{{ item.1 }}"
|
|
|
|
# Read back what landed. An image that downloaded as an error page is still a
|
|
# file, and the first sign of it would otherwise be a user's job failing.
|
|
# No --type flag: this apptainer does not have one, and passing it made the
|
|
# check fail on a perfectly good image - the check reporting its own bug as
|
|
# the system's. Bare inspect is enough and was measured to discriminate:
|
|
# exit 0 on a real SIF, 255 on a file that merely exists.
|
|
- name: Confirm each image is a container
|
|
ansible.builtin.command:
|
|
cmd: apptainer inspect {{ apps_dir }}/{{ item.name }}.sif
|
|
loop: "{{ cluster_apps | default([], true) }}"
|
|
loop_control:
|
|
label: "{{ item.name }}"
|
|
changed_when: false
|