diff --git a/images/ci/Dockerfile b/images/ci/Dockerfile index 79df7a1..df42816 100644 --- a/images/ci/Dockerfile +++ b/images/ci/Dockerfile @@ -65,18 +65,33 @@ RUN python3 -m venv /opt/uv-venv \ # pre-commit needs a git repository to resolve a config. The hook repositories are # cloned and built into PRE_COMMIT_HOME, keyed by repository URL and revision, so -# the cache is found from any checkout. The yamllint run proves the cache is usable -# and complete (a missing environment would be rebuilt, which needs the network). -RUN git init -q /tmp/hooks \ - && cp .pre-commit-config.yaml /tmp/hooks/ \ - && cd /tmp/hooks \ - && /opt/venv/bin/pre-commit install-hooks \ - && printf -- '---\nkey: value\n' > ok.yaml \ - && git add ok.yaml \ - && /opt/venv/bin/pre-commit run yamllint --all-files \ - && rm -rf /root/.cache/go-build /tmp/hooks \ - && find /opt/pre-commit -maxdepth 1 -mindepth 1 -exec du -sh {} + | sort -h \ - && du -sh /opt/venv /opt/python /opt/pre-commit +# the cache is found from any checkout. +# +# The Go hooks (gitleaks, actionlint) are built by pre-commit with a Go toolchain it +# downloads into /.go, about 170 MB per environment, which alone pushed the +# /opt/pre-commit layer past Cloudflare's 100 MB limit (413 on the first push). At run +# time only the built binaries in /bin run, so the toolchains and the Go build +# cache are deleted. The three hooks run on a staged sample before and after the +# deletion: a cache that is incomplete (a missing environment would be rebuilt, which +# needs the network) or no longer works fails the image build, not the jobs. +RUN set -eu; \ + git init -q /tmp/hooks; \ + cp .pre-commit-config.yaml /tmp/hooks/; \ + cd /tmp/hooks; \ + git -c user.name=ci -c user.email=ci@localhost commit -q --allow-empty -m init; \ + /opt/venv/bin/pre-commit install-hooks; \ + mkdir -p .gitea/workflows; \ + printf -- '---\nkey: value\n' > ok.yaml; \ + printf -- 'self-hosted-runner:\n labels:\n - kamino-docker\n' > .gitea/actionlint.yaml; \ + printf -- 'on: push\njobs:\n t:\n runs-on: kamino-docker\n steps:\n - run: echo ok\n' > .gitea/workflows/t.yml; \ + git add -A; \ + smoke() { for h in yamllint gitleaks actionlint; do /opt/venv/bin/pre-commit run "$h" --all-files; done; }; \ + smoke; \ + rm -rf /opt/pre-commit/repo*/golangenv-*/.go /root/.cache/go-build; \ + smoke; \ + rm -rf /tmp/hooks; \ + find /opt/pre-commit -maxdepth 1 -mindepth 1 -exec du -sh {} + | sort -h; \ + du -sh /opt/venv /opt/python /opt/pre-commit FROM os AS final @@ -96,12 +111,13 @@ COPY --from=build /opt/pre-commit /opt/pre-commit # 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/ -RUN for v in 3.11 3.13; do \ - ln -s "$(echo /opt/python/cpython-${v}.*/bin/python${v})" "/usr/local/bin/python${v}" \ - && "python${v}" --version; \ - done \ - && cd /opt/ci-pins \ - && sha256sum requirements-dev.txt .pre-commit-config.yaml > /opt/ci-pins.sha256 \ - && ansible --version | head -n1 \ - && pre-commit --version \ - && shellcheck --version | sed -n 2p +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}"; \ + "python${v}" --version; \ + done; \ + cd /opt/ci-pins; \ + sha256sum requirements-dev.txt .pre-commit-config.yaml > /opt/ci-pins.sha256; \ + ansible --version | head -n1; \ + pre-commit --version; \ + shellcheck --version | sed -n 2p