fix: detect images pulled by digest (no RepoTags) (#101)#106
Open
AmSach wants to merge 1 commit into
Open
Conversation
When a container's image was pulled by digest (e.g. via
'image@sha256:...' in a compose file), Docker does not assign
any RepoTags, so container.image.tags is an empty list and the
container was silently skipped during backup.
This was particularly painful for Immich, whose compose file pins
the postgres image by digest, so the immich-app/postgres pattern
in BACKUP_PROVIDERS never matched.
Fix by:
- extracting image-reference parsing into _name_from_image_reference
(handles name:tag, name@sha256:..., and registry/name:tag@sha256:...
forms, plus a missing tag when only the digest is referenced)
- falling back to container.attrs['Config']['Image'] when RepoTags
is empty
- adding tests covering all the new cases
| ), | ||
| ], | ||
| ) | ||
| def test_name_from_image_reference_with_digest(reference: str, name: str) -> None: |
Owner
There was a problem hiding this comment.
Suggestion: This test can be folded into test_get_container_names - I don't think the internal helper needs its own tests
| """ | ||
| # Strip the digest suffix if present (e.g. @sha256:...). | ||
| # We only care about the name part for matching against patterns. | ||
| image_ref = reference.split("@", 1)[0] |
Owner
There was a problem hiding this comment.
Suggestion: Split from the right
Suggested change
| image_ref = reference.split("@", 1)[0] | |
| image_ref = reference.rsplit("@", 1)[0] |
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.
Fixes #101
When a container's image was pulled by digest (e.g. via
image@sha256:...in a compose file), Docker does not assign anyRepoTags, socontainer.image.tagsis an empty list and the container was silently skipped during backup.This was particularly painful for Immich, whose compose file pins the postgres image by digest, e.g.:
Before:
get_container_nameswould return an empty set,immich-app/postgresnever matched a backup pattern, and the database was silently skipped.After:
get_container_namesfalls back tocontainer.attrs['Config']['Image'](which preserves the original digest reference) and the new_name_from_image_referencehelper correctly strips the@sha256:...digest suffix before matching.Changes
db-auto-backup.py:_name_from_image_reference(reference)helper that handlesname:tag,name@digest, andregistry/name:tag@digestforms.get_container_namesnow also readsConfig.Imageas a fallback whenRepoTagsis empty, and uses the new helper.image.split(":", 1)crash when no tag separator is present is gone — the helper tolerates tags being absent (digest-only references).tests/tests.py:test_name_from_image_reference_with_digest— 4 parametrized cases covering Immich-style, official-library, and pure-digest references.test_name_from_image_reference_without_digest— 4 cases for the existingname:tagform (including tag-less images).test_get_container_names_falls_back_to_config_image— end-to-end check that the digest-pinned Immich image is now detected.test_get_container_names_empty_when_no_reference— confirms we degrade gracefully when bothRepoTagsandConfig.Imageare missing.Test run
(Integration tests
test_backup_runs/test_backup_runs_compressedwere skipped because they require a live Docker test container fromtests/conftest.py; they are unchanged.)black,ruff, andmypyall pass clean.— Sent via @AmSach bot