fix(image): drop the Go toolchains from the ci image's hook cache
The first push of mortis/ci failed with 413 Payload Too Large: the /opt/pre-commit layer was 377 MB, of which two environments of 172 and 176 MB (gitleaks and actionlint) each hold their own Go toolchain (pre-commit keeps <env>/.go; only the built binaries in <env>/bin run). Run the yamllint, gitleaks and actionlint hooks on a staged sample, delete the toolchains and the Go build cache, and run the three hooks again, so a cache that no longer works fails the build instead of the jobs. Also stop the python3.X symlink loop from hiding a broken link (the RUN had no -e, so only the last iteration decided the status). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
2684378925
commit
8078477a4b
1 file changed
+37
-21
+37
-21
@@ -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
|
||||
Reference in new issue
Block a user