From f540e652d3e2f22beb99e1294f412a2fa7338a34 Mon Sep 17 00:00:00 2001 From: Claude Code AI - Gitea MCP <3+claude@noreply.git.rkdr.net> Date: Sun, 25 Oct 2026 12:10:03 +0000 Subject: [PATCH] feat(image): bake the ansible-test sanity virtualenvs into the ci image `ansible-test sanity --requirements` builds one virtualenv per test under ~/.ansible/test/venv (keyed by the requirements hash) on every run: about 25s of the Build job. Prime them at image build time with --prime-venvs against a stub collection, for the controller Python and the baked 3.11 and 3.13, and copy ~/.ansible/test into the final image as its own layer. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm --- images/ci/Dockerfile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/images/ci/Dockerfile b/images/ci/Dockerfile index e59aac5..8ab5900 100644 --- a/images/ci/Dockerfile +++ b/images/ci/Dockerfile @@ -16,6 +16,8 @@ # - /opt/pre-commit: every hook environment of .pre-commit-config.yaml, installed by # `pre-commit install-hooks` (gitleaks and actionlint are built from source by # pre-commit, which downloads a Go toolchain: that is most of the time saved). +# - /root/.ansible/test: the ansible-test sanity virtualenvs, primed against a stub +# collection (`ansible-test sanity --prime-venvs`), so a run only reuses them. # - Python 3.11 and 3.13 as python3.11 / python3.13 on PATH, so that # `ansible-test sanity` runs its compile test for them instead of skipping it. # They come from python-build-standalone through uv, pinned by the uv version. @@ -93,6 +95,23 @@ RUN set -eu; \ find /opt/pre-commit -maxdepth 1 -mindepth 1 -exec du -sh {} + | sort -h; \ du -sh /opt/venv /opt/python /opt/pre-commit +# ansible-test builds one virtualenv per sanity test under ~/.ansible/test/venv, keyed +# by the hash of the test's requirements (so by the ansible-core pin), and reuses it on +# later runs. --prime-venvs creates them without running any test; it needs a +# collection tree, so a stub one is used. The target interpreters must be on PATH +# first, as in the final image. +RUN set -eu; \ + for v in 3.11 3.13; do \ + ln -s "$(echo /opt/python/cpython-${v}.*/bin/python${v})" "/usr/local/bin/python${v}"; \ + done; \ + mkdir -p /tmp/ac/ansible_collections/mortis/kamino; \ + cd /tmp/ac/ansible_collections/mortis/kamino; \ + printf -- '---\nnamespace: mortis\nname: kamino\nversion: 0.0.0\nreadme: README.md\nauthors:\n - ci\n' > galaxy.yml; \ + : > README.md; \ + PATH=/opt/venv/bin:$PATH ansible-test sanity --prime-venvs --requirements --color no; \ + rm -rf /tmp/ac; \ + du -sh /root/.ansible/test/venv/* /root/.ansible/test + FROM os AS final @@ -108,6 +127,8 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \ COPY --from=build /opt/venv /opt/venv COPY --from=build /opt/python /opt/python COPY --from=build /opt/pre-commit /opt/pre-commit +# The primed ansible-test sanity virtualenvs and its pip bootstrap cache. +COPY --from=build /root/.ansible/test /root/.ansible/test # The target interpreters ansible-test looks for on PATH, and the pin record. COPY --from=build /src/requirements-dev.txt /src/.pre-commit-config.yaml /opt/ci-pins/