Skip to content

perf: keep build caches out of the image (uv/go/cargo/apt) - #16

Open
ai-anant wants to merge 1 commit into
cyfinoid:mainfrom
ai-anant:perf/cache-hygiene
Open

perf: keep build caches out of the image (uv/go/cargo/apt)#16
ai-anant wants to merge 1 commit into
cyfinoid:mainfrom
ai-anant:perf/cache-hygiene

Conversation

@ai-anant

@ai-anant ai-anant commented Aug 2, 2026

Copy link
Copy Markdown

Summary

The aidc image was shipping build-time caches that serve no runtime purpose, inflating every project image by roughly 0.5–1.5 GB depending on toolchains:

  • uv download cache (/root/.cache/uv) — semgrep + ast-grep wheels (~100s MB)
  • Go build + module cache after compiling gosec (~/.cache/go-build, ~/go)
  • Cargo registry + git + target after compiling cargo-audit --locked from source (~1 GB)
  • apt archives and stale gem cache from bundler-audit

Changes (templates/devcontainer/Dockerfile.tmpl)

  • uv steps use BuildKit cache mounts (RUN --mount=type=cache,target=/root/.cache/uv) — downloaded wheels live in the builder cache (fast rebuilds) but never land in the image.
  • Go toolchain: GOPATH=/tmp/gopath GOCACHE=/tmp/go-build for the gosec compile, then rm -rf — keeps the module cache out of ~/.cache / ~/go.
  • Rust toolchain: CARGO_TARGET_DIR=/tmp/cargo-target for the cargo-audit compile, then removes /tmp/cargo-target, ~/.cargo/registry, ~/.cargo/git. The installed cargo-audit binary (symlinked into ~/.local/bin) survives.
  • apt: added apt-get clean + remove /var/cache/apt/archives/*.deb in the base layer; the toolchain loop already cleans apt lists.
  • Ruby: drops the gem cache after bundler-audit.
  • uv security tools (checkov, bandit): uv cache clean after install (no cache mount there since they run as vscode).

Requires BuildKit (Docker 23+ default; compose v2 uses it automatically). docker build --check passes.

Expected impact

  • ~0.5–1.5 GB smaller images (biggest win on Rust projects).
  • Rebuilds stay fast (uv wheels cached in BuildKit, not re-downloaded).
  • No behavior change: all installed binaries (semgrep, gosec, cargo-audit, bandit, checkov) remain on PATH.

Test plan

  • docker build --check on the template (BuildKit parse, no warnings)
  • Toolchain loop bash fragment syntax-checked
  • bash -n, shellcheck -x, bash-3.2 compat check — clean
  • tests/resolve-oauth-token.test.sh — 7/7 pass

Closes #10

The image accumulated build-time caches that serve no runtime purpose:
- uv download cache (semgrep/ast-grep wheels) in /root/.cache/uv
- go build+module cache after compiling gosec (~/.cache, ~/go)
- cargo registry+git+target after compiling cargo-audit (~1GB)
- apt archives and stale gem cache

Move uv downloads to BuildKit cache mounts (--mount=type=cache) so they
live in the builder cache, not the image; point GOCACHE/GOPATH and
CARGO_TARGET_DIR at /tmp and remove them after install; apt-get clean +
drop apt archives and gem cache.

Refs cyfinoid#10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image size: clean uv/go/cargo/apt caches out of image layers (BuildKit cache mounts)

1 participant