Dockerfile: clean the rosdep layer (#923) (backport #923) - #935
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
apt-get cleanempties/var/cache/apt/archives. It does not touch/var/lib/apt/lists, so the first layer of this image ships the full Ubuntu package index it downloaded. The line that looks like it cleans up isn't cleaning up the thing that costs the most.What that costs, measured
For
ubuntu:24.04's default sources on amd64 —noble,noble-updates,noble-backports,noble-securityacrossmain/restricted/universe/multiverse:binary-amd64/Packagesi18n/Translation-enRead off the
SHA256:sections of Ubuntu's ownReleasefiles rather than estimated, so it's checkable without building anything:universealone is 73.4 MB of that.The rosdep layer
The third
RUNresolves and installs the whole dependency tree and never runsapt-get clean, so that layer keeps every.debit downloaded in/var/cache/apt/archives. I have no container runtime on this machine, so I have not sized it — but it's the layer that installs the most, and it's the only apt layer here with no cleanup at all.What I deliberately did not change, and why
The second
RUN— the one that adds the ROS apt source and installs colcon/rosdep — keeps its lists, on purpose.rosdep installshells out toapt-get installwithout running its ownapt-get update, so removing the lists there would leave the next layer unable to resolve anything. That's a build break, not a saving.It also wouldn't help if it were safe: those lists are written in layer 2, and deleting them from layer 3 only adds a whiteout — the bytes stay in the image. Dropping them properly would mean merging layers 2 and 3 into one
RUN, which is a real restructuring of thegit clone/rosdepblock and a bigger change than I think is worth putting in front of you unasked. Happy to do it as a follow-up if you'd rather have it.So this is two lines:
rm -rf /var/lib/apt/lists/*in layer 1,apt-get cleanin layer 3.What I could not verify
No Docker or Podman on my side, so I have not built this image. The change is two additions to existing
&&chains and adds no new command that can fail on its own, but I'd rather say that than let a green-looking PR imply I ran something I didn't. Everything above about layer ordering is read off the Dockerfile and rosdep's apt installer, not observed in a build.Disclosure: I'm an AI agent. The measurement above is mine and reproducible with the command given; the judgement about layer 2 is the part worth a maintainer's second opinion.
This is an automatic backport of pull request #923 done by Mergify.