Skip to content

refactor(BA-6632): move image scanning out of the models layer into the image repository#12439

Merged
fregataa merged 1 commit into
mainfrom
refactor/BA-6632-image-scanner-out-of-models
Jul 1, 2026
Merged

refactor(BA-6632): move image scanning out of the models layer into the image repository#12439
fregataa merged 1 commit into
mainfrom
refactor/BA-6632-image-scanner-out-of-models

Conversation

@fregataa

@fregataa fregataa commented Jun 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Move the container-registry scan/untag logic out of models/image/row.py so the models layer no longer imports the container_registry package.
  • scan_single_image / rescan_images (and the registry loading/filtering helpers) now live on ImageDBSource.
  • The registry untag external call lives on ImageRepository, which fetches the image + registry row first, then calls the Harbor registry directly.
  • cli/image_impl uses ImageDBSource for rescan and inlines the Harbor untag.

Notes

  • Pure relocation of existing logic — no new scanning behavior. The broader container-registry refactor (extracting external-access Client classes and deprecating BaseContainerRegistry) is tracked separately in BA-6634.

Test plan

  • CI: pants check (mypy)
  • CI: pants test — image rescan / untag paths (repository, DB source, CLI) behave unchanged

Resolves BA-6632

@github-actions github-actions Bot added the size:L 100~500 LoC label Jun 26, 2026
@github-actions github-actions Bot added comp:manager Related to Manager component comp:cli Related to CLI component labels Jun 26, 2026
fregataa added a commit that referenced this pull request Jun 26, 2026
@fregataa fregataa marked this pull request as ready for review June 26, 2026 20:52
@fregataa fregataa requested a review from a team as a code owner June 26, 2026 20:52
@fregataa fregataa changed the title refactor(BA-6632): move image scanning into a repository-layer ImageScanner refactor(BA-6632): move image scanning into a repository-layer Jun 29, 2026
fregataa added a commit that referenced this pull request Jun 29, 2026
@fregataa fregataa force-pushed the refactor/BA-6632-image-scanner-out-of-models branch from a53387f to f5d2c4f Compare June 29, 2026 03:06
@fregataa fregataa changed the title refactor(BA-6632): move image scanning into a repository-layer refactor(BA-6632): move image scanning out of the models layer into the image repository Jun 29, 2026
@fregataa fregataa marked this pull request as draft June 29, 2026 03:10
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>
@fregataa fregataa force-pushed the refactor/BA-6632-image-scanner-out-of-models branch from d1faad3 to 9fc43b8 Compare June 29, 2026 03:31
@fregataa fregataa marked this pull request as ready for review July 1, 2026 02:15
Copilot AI review requested due to automatic review settings July 1, 2026 02:15

Copilot AI 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.

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 new fetch_image_and_registry onto ImageDBSource; remove their model-layer counterparts.
  • Move untag_image_from_registry orchestration onto ImageRepository (fetch data first, then perform the Harbor v2 call without holding the DB session open).
  • Update cli/image_impl.py to use ImageDBSource().rescan_images(...) and inline the Harbor v2 untag in purge_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.

Comment on lines +275 to +276
if registry_row.type != ContainerRegistryType.HARBOR2:
raise NotImplementedError("This feature is only supported for Harbor 2 registries")
@jopemachine

Copy link
Copy Markdown
Member

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.

@fregataa fregataa merged commit 3976762 into main Jul 1, 2026
39 checks passed
@fregataa fregataa deleted the refactor/BA-6632-image-scanner-out-of-models branch July 1, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:cli Related to CLI component comp:manager Related to Manager component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants