Merge pull request 'fix(image): drop the Go toolchains from the ci image's hook cache' (#4) from fix/ci-image-layer-size into main
Build / build (push) Successful in 51s
Molecule image / image (Dockerfile, molecule-ubuntu2404, images/molecule-ubuntu2404) (push) Successful in 29s
Lint / lint (push) Successful in 1m21s
Molecule image / image (images/ci/Dockerfile, ci, ) (push) Failing after 1m44s

Reviewed-on: #4
Reviewed-by: Defame1297 <[email protected]>
This commit was merged in pull request #4.
This commit is contained in:
Defame1297 committed 2026-10-25 11:13:48 +00:00
commit 03d2c1dc91
1 file changed
+37 -21
+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
# 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 <env>/.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 <env>/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