refactor(BA-6632): move image scanning out of the models layer into the image repository#12439
Conversation
a53387f to
f5d2c4f
Compare
Move the container-registry scan/untag logic out of models/image/row.py into the image repository layer so the models layer no longer imports the container_registry package: - scan_single_image / rescan_images (and the registry loading/filtering helpers) live on ImageDBSource. - the registry untag external call lives on ImageRepository, which fetches the image + registry row first. - cli/image_impl uses ImageDBSource for rescan and raises click errors in the purge untag path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d1faad3 to
9fc43b8
Compare
There was a problem hiding this comment.
Pull request overview
This PR is a layering refactor (BA-6632) that removes the container-registry scan/rescan/untag logic from the models layer (models/image/row.py) so that the models layer no longer imports the container_registry package. The scan/rescan orchestration and configured-registry helpers move onto ImageDBSource, the Harbor untag external call moves onto ImageRepository (fetching image + registry first, then calling Harbor outside a held DB session), and the CLI is updated to use the new locations. It's described as a pure relocation with no new scanning behavior.
Changes:
- Move
rescan_images,scan_single_image, registry loading/filtering helpers, and a newfetch_image_and_registryontoImageDBSource; remove their model-layer counterparts. - Move
untag_image_from_registryorchestration ontoImageRepository(fetch data first, then perform the Harbor v2 call without holding the DB session open). - Update
cli/image_impl.pyto useImageDBSource().rescan_images(...)and inline the Harbor v2 untag inpurge_image.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/ai/backend/manager/repositories/image/repository.py | Stores _db; untag_image_from_registry now fetches image/ref/registry then calls Harbor v2 untag directly. |
| src/ai/backend/manager/repositories/image/db_source/db_source.py | Adds fetch_image_and_registry, scan_single_image, rescan_images, and configured-registry load/scan/filter helpers; imports get_container_registry_cls. |
| src/ai/backend/manager/models/image/row.py | Removes scan/rescan/untag helpers and the container_registry imports from the models layer. |
| src/ai/backend/manager/models/image/init.py | Drops rescan_images/scan_single_image re-exports. |
| src/ai/backend/manager/cli/image_impl.py | Uses ImageDBSource for rescan and inlines Harbor v2 untag in purge. |
| changes/12439.enhance.md | Changelog fragment describing the relocation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if registry_row.type != ContainerRegistryType.HARBOR2: | ||
| raise NotImplementedError("This feature is only supported for Harbor 2 registries") |
|
Strictly speaking, the rescan logic would be better placed on the client side. However, I don't think it necessarily needs to be addressed in this PR. |
Summary
models/image/row.pyso the models layer no longer imports thecontainer_registrypackage.scan_single_image/rescan_images(and the registry loading/filtering helpers) now live onImageDBSource.untagexternal call lives onImageRepository, which fetches the image + registry row first, then calls the Harbor registry directly.cli/image_implusesImageDBSourcefor rescan and inlines the Harbor untag.Notes
BaseContainerRegistry) is tracked separately in BA-6634.Test plan
pants check(mypy)pants test— image rescan / untag paths (repository, DB source, CLI) behave unchangedResolves BA-6632