fix(image): drop the Go toolchains from the ci image's hook cache #4

Merged
Defame1297 merged 1 commits from fix/ci-image-layer-size into main 2026-10-25 11:13:49 +00:00
+37 -21
View File
@@ -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 # 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 # 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 # the cache is found from any checkout.
# and complete (a missing environment would be rebuilt, which needs the network). #
RUN git init -q /tmp/hooks \ # The Go hooks (gitleaks, actionlint) are built by pre-commit with a Go toolchain it
&& cp .pre-commit-config.yaml /tmp/hooks/ \ # downloads into <env>/.go, about 170 MB per environment, which alone pushed the
&& cd /tmp/hooks \ # /opt/pre-commit layer past Cloudflare's 100 MB limit (413 on the first push). At run
&& /opt/venv/bin/pre-commit install-hooks \ # time only the built binaries in <env>/bin run, so the toolchains and the Go build
&& printf -- '---\nkey: value\n' > ok.yaml \ # cache are deleted. The three hooks run on a staged sample before and after the
&& git add ok.yaml \ # deletion: a cache that is incomplete (a missing environment would be rebuilt, which
&& /opt/venv/bin/pre-commit run yamllint --all-files \ # needs the network) or no longer works fails the image build, not the jobs.
&& rm -rf /root/.cache/go-build /tmp/hooks \ RUN set -eu; \
&& find /opt/pre-commit -maxdepth 1 -mindepth 1 -exec du -sh {} + | sort -h \ git init -q /tmp/hooks; \
&& du -sh /opt/venv /opt/python /opt/pre-commit 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 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. # 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/ COPY --from=build /src/requirements-dev.txt /src/.pre-commit-config.yaml /opt/ci-pins/
RUN for v in 3.11 3.13; do \ RUN set -eu; \
ln -s "$(echo /opt/python/cpython-${v}.*/bin/python${v})" "/usr/local/bin/python${v}" \ for v in 3.11 3.13; do \
&& "python${v}" --version; \ ln -s "$(echo /opt/python/cpython-${v}.*/bin/python${v})" "/usr/local/bin/python${v}"; \
done \ "python${v}" --version; \
&& cd /opt/ci-pins \ done; \
&& sha256sum requirements-dev.txt .pre-commit-config.yaml > /opt/ci-pins.sha256 \ cd /opt/ci-pins; \
&& ansible --version | head -n1 \ sha256sum requirements-dev.txt .pre-commit-config.yaml > /opt/ci-pins.sha256; \
&& pre-commit --version \ ansible --version | head -n1; \
&& shellcheck --version | sed -n 2p pre-commit --version; \
shellcheck --version | sed -n 2p