Skip to content

Keep .git/ in the sim image for revision tracking#40

Merged
YWHyuk merged 1 commit into
mainfrom
claude/keep-git-in-sim-image
May 19, 2026
Merged

Keep .git/ in the sim image for revision tracking#40
YWHyuk merged 1 commit into
mainfrom
claude/keep-git-in-sim-image

Conversation

@YWHyuk
Copy link
Copy Markdown

@YWHyuk YWHyuk commented May 19, 2026

Summary

Currently the sim image only carries a single /workspace/.git-rev line because the builder stage runs find -name .git -prune -exec rm -rf {} +. That's enough to identify a tag but not to do real debugging: no git log for context, no git submodule status for submodule SHAs (chakra, ns-3, etc.), no git diff for hotfix verification.

This patch keeps .git/ (main repo + recursive submodules), installs git in the runtime stage, and runs git gc --aggressive --prune=now everywhere to compact packs.

Changes

  • scripts/sim.Dockerfile builder stage: replace the .git wipe with git gc --aggressive --prune=now on the main repo plus git submodule foreach --recursive 'git gc --aggressive --prune=now' so submodule .git/modules/<name>/ packs (the bulk of the footprint) get compacted too. The submodule foreach is wrapped in a subshell + || true so a single submodule failure doesn't abort the build, scoped so the rest of the && chain still aborts on real errors.
  • Runtime stage: install git, add git config --system --add safe.directory '*' (root-owned .git tree may now be inspected by enroot --user / docker -u UIDs).
  • Update Dockerfile header comment + .dockerignore comment to document the new contract.

After this lands

docker run --rm <image> bash -lc 'cd /workspace && git log -3 --oneline'
docker run --rm <image> bash -lc 'cd /workspace && git submodule status --recursive'
docker run --rm <image> cat /workspace/.git-rev

Size impact (measured)

Smoke test on a full dev clone of this repo (deep history; CI runs are shallower):

.git/ total
Before gc 305 MB
After gc 210 MB (~31% reduction)

The root .git/ shrinks ~1 MB because it's already packed; the real win is on .git/modules/* (278 MB of submodule packs in this dev clone -> ~180 MB after submodule foreach gc).

CI shallow checkouts (actions/checkout with default fetch-depth: 1 + submodules: recursive) start much smaller, so the runtime image overhead from published builds will be well below 210 MB.

Interaction with #39

Both PRs touch scripts/sim.Dockerfile. #39 adds ARG GIT_SHA + an OCI label for fast version inspection without running the container; this PR adds the full .git/ tree for deep debugging. They're complementary, but whichever merges second will need a tiny rebase (the header comment block and the same RUN step). No semantic conflict.

Test plan

  • PR build succeeds on linux/amd64 and linux/arm64.
  • After merge: docker run --rm ghcr.io/psal-postech/llmservingsimspec/sim:latest cat /workspace/.git-rev returns the merge commit SHA.
  • After merge: docker run --rm <image> bash -lc 'cd /workspace && git log -1 --format=%H' matches that SHA.
  • After merge: docker run --rm <image> bash -lc 'cd /workspace && git submodule status --recursive' lists every submodule with its SHA -- including astra-sim and the sub-submodules under astra-sim/extern/.
  • After merge: docker image inspect <image> --format '{{.Size}}' is within ~250 MB of the previous published image size (sanity check on .git bloat).

Generated by Claude Code

Debugging which commit a running container was built from currently
requires reading /workspace/.git-rev (single SHA, no log/diff context)
because the builder stage explicitly wiped every .git/ subtree before
the COPY --from=builder. That's enough to identify a release tag in
the abstract but useless when the user wants to know which submodule
SHAs went into ASTRA-Sim, whether a hotfix patch landed, or what the
last few commits actually changed.

Changes:

- scripts/sim.Dockerfile builder stage: drop the
  ``find -name .git -prune -exec rm -rf {} +`` and replace with
  ``git gc --aggressive --prune=now`` on the main repo plus
  ``git submodule foreach --recursive 'git gc --aggressive
  --prune=now'`` so submodule .git/modules/<name>/ packs get
  compacted too (the bulk of the .git footprint).
- scripts/sim.Dockerfile runtime stage: install git, add
  ``git config --system --add safe.directory '*'`` (containers run as
  root for build but the .git was created in stage 1; safe.directory
  also covers the enroot --user / docker -u case).
- Update header comment + .dockerignore comment to reflect the new
  contract (".git/ KEPT, gc'd").

After this lands, every published sim image can self-report:

  docker run --rm <image> bash -lc 'cd /workspace && git log -3 --oneline'
  docker run --rm <image> bash -lc 'cd /workspace && git submodule status --recursive'
  docker run --rm <image> bash -lc 'cat /workspace/.git-rev'

Size impact (measured on a full dev clone of this repo):

  before gc: 305 MB total .git/  (root + .git/modules/* packs)
  after gc:  210 MB               (~31% reduction)

CI shallow checkouts (actions/checkout default ``fetch-depth: 1``
with ``submodules: recursive``) start much smaller, so the runtime
image overhead from the published builds will be well below 210 MB.
@YWHyuk YWHyuk merged commit e0d0409 into main May 19, 2026
3 checks passed
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.

2 participants