diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1bae771f79..a652b1ea5d 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -5,8 +5,9 @@ # The images our CI infrastructure uses, described under `.gitlab/ci/docker/`, # are built on the distributions we test CMake against and are minimized for # CI use. Prepare the environment from scratch on Ubuntu instead: it offers -# the broadest ecosystem of packages and tooling for development, including a -# recent `cmake` and the `clang-format` version our style rules require. +# the broadest ecosystem of packages and tooling for development, including +# the `clang-format` version our style rules require and the Kitware APT +# repository through which CMake itself is published. ARG BASE_IMAGE=ubuntu:26.04 FROM ${BASE_IMAGE} @@ -15,6 +16,21 @@ ARG USERNAME=cmake-dev ARG USER_UID=1000 ARG USER_GID=${USER_UID} +# The SHA-256 of the signing key `apt.kitware.com` publishes. Kitware rotates +# that key every few years; updating this hash both approves the new key and +# forces the step below to fetch it again rather than reuse a cached layer. +# Read the current value with: +# curl -fsSL https://apt.kitware.com/keys/kitware-archive-latest.asc | sha256sum +ARG KITWARE_PUBLIC_KEY_SHA256=801bc629e356c3c96f184351272914222ce427777400fa7d1baed3ab180b3e3b + +# Add the Kitware APT repository, which carries CMake releases newer than the +# ones the distribution provides, before installing anything from it below. +RUN --mount=type=bind,source=install_kitware_archive.sh,target=/root/install_kitware_archive.sh \ + --mount=type=bind,source=docker-clean,target=/etc/apt/apt.conf.d/docker-clean \ + --mount=type=cache,target=/var/lib/apt/lists,sharing=locked \ + --mount=type=cache,target=/var/cache/apt,sharing=locked \ + sh /root/install_kitware_archive.sh ${KITWARE_PUBLIC_KEY_SHA256} + # Install the packages needed to build CMake, run its test suite, build its # documentation, and satisfy its style rules, along with a few more that make # the container a comfortable place to work. diff --git a/.devcontainer/install_kitware_archive.sh b/.devcontainer/install_kitware_archive.sh new file mode 100755 index 0000000000..d120d7cc08 --- /dev/null +++ b/.devcontainer/install_kitware_archive.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# Add the Kitware APT repository, which carries CMake releases newer than the +# ones the distribution provides. See `Help/dev/devcontainer.rst`. + +set -e + +readonly key_sha256="$1" + +if test -z "$key_sha256"; then + echo "usage: $0 " >&2 + exit 1 +fi + +# Install without asking questions. +export DEBIAN_FRONTEND=noninteractive + +# `VERSION_CODENAME` names the suite the repository provides for the +# distribution the container is based on. +. /etc/os-release + +readonly sources=/etc/apt/sources.list.d/kitware.sources +readonly keyring=/usr/share/keyrings/kitware-archive-keyring +readonly key_url=https://apt.kitware.com/keys/kitware-archive-latest.asc + +# Describe the repository, verified with the keyring named as the argument. +write_sources() { + cat > "$sources" <