Skip to content

docker-to-squash.py: let pull-build and push-update share the working directory - #9295

Open
linzch3 wants to merge 3 commits into
apache:masterfrom
linzch3:fix-9292-reuse-working-dir
Open

linzch3 wants to merge 3 commits into
apache:masterfrom
linzch3:fix-9292-reuse-working-dir

Conversation

@linzch3

@linzch3 linzch3 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fixes #9292.

get_working_dir never reuses a directory: if dts-work-dir exists it creates dts-work-dir/docker-to-squash instead. pull-build calls it once per image, so the 1st image goes to dts-work-dir, the 2nd to dts-work-dir/docker-to-squash, and the 3rd fails with [Errno 17] File exists. And push-update then looks under dts-work-dir/docker-to-squash and doesn't find what pull-build pulled.

I kept the subdirectory behavior as the default on purpose: most commands (pull-build-push-update, remove-image, add-remove-tag, ...) rm -rf their working directory at the end, so they shouldn't take over an existing directory like --working-dir /tmp.

Changes:

  • get_working_dir(directory, reuse=False): with reuse=True it creates the directory if needed (exist_ok=True) and returns it as is.
  • pull_build and push_update pass reuse=True. Neither of them removes the working directory, and they're meant to be run one after the other on the same --working-dir.

How was the change tested

  • python -m unittest -v test_docker_to_squash in bin/ with Python 3.9: passes.
  • New tests: calling get_working_dir(..., reuse=True) 3 times returns the same dir; the default still uses a subdirectory of an existing dir; and a pull_build run over 3 images (skopeo/manifest calls mocked) puts all of them directly under the working dir, after which push_update looks for dts-work-dir/ubuntu:22.04/manifest.json. With the fix reverted, the pull/push test fails with [Errno 17] File exists: '.../dts-work-dir/docker-to-squash'.

An AI assistant helped draft this change; I reviewed it and take responsibility for it.

@rzo1 rzo1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @linzch3. With the shared working directory, the cleanup in pull_build's except block can now delete earlier work: re-running pull-build for an image that already exists makes skopeo_copy_image fail, and shutil.rmtree(skopeo_dir) then removes the previous run's directory with its .sqsh files. The same happens within one run for two images with the same basename. Could you only remove skopeo_dir when this run created it? Also, a short note on the new reuse behaviour in the --working-dir help would be helpful.

A failed pull-build re-run must not delete a pre-existing skopeo_dir and
its .sqsh files. Also mention the reuse behaviour in the --working-dir help.
@linzch3

linzch3 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

thx for catching this. u're right that a failed pull-build re-run (or two images with the same basename) could wipe an earlier skopeo_dir and its .sqsh files. i now only remove the directory when this run created it, and i added a short note on the reuse behaviour in the --working-dir help.

…rking-dir

# Conflicts:
#	bin/test_docker_to_squash.py
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.

docker-to-squash.py: get_working_dir creates a new directory on every call, so push-update cannot find pulled images

2 participants