Skip to content

Conversation

@euanh
Copy link
Collaborator

@euanh euanh commented Jul 9, 2025

Motivation

Currently, RegistryClient handles uploading and downloading container images to and from a registry. In fact, containertool creates two clients: one is used only to download images from the source repository, and the other is used only to upload images to the destination. Registries are read/write, but in the future we may need to handle sources of images which are read-only or write-only - for example when writing a container image out to an archive on disk.

This change adds two new protocols, splitting up the operations needed to upload and download images. This allows for future clients which cannot handle both sets of operations.

Modifications

  • Add new ImageSource and ImageDestination protocols, defining the functions needed to download and upload images, respectively.
  • Consolidate the RegistryClient extensions which implement the ImageSource and ImageDestination protocols.

Result

Refactoring. No functional change, but responsibilities of different objects are clearer.

Test Plan

Existing tests continue to pass.

@euanh euanh added kind/enhancement New feature or request semver/patch No public API change. labels Jul 9, 2025
@euanh euanh force-pushed the source-destination-protocols branch 5 times, most recently from 4143511 to ce27304 Compare July 10, 2025 08:47
@euanh euanh changed the title Source destination protocols ContainerRegistry: Separate registry operations into ImageSource and ImageDestination protocols Jul 10, 2025
@euanh euanh force-pushed the source-destination-protocols branch 2 times, most recently from 45d10c6 to 800f328 Compare July 10, 2025 09:04
@euanh euanh force-pushed the source-destination-protocols branch 2 times, most recently from 92e6189 to 560f45a Compare July 10, 2025 10:21
@euanh euanh force-pushed the source-destination-protocols branch 3 times, most recently from 2eeacd9 to 99e852e Compare July 10, 2025 10:37
@euanh euanh force-pushed the source-destination-protocols branch from 99e852e to 1c129a7 Compare July 10, 2025 10:37
@euanh euanh marked this pull request as ready for review July 10, 2025 10:38
@euanh euanh merged commit cf92449 into apple:main Jul 10, 2025
23 checks passed
@euanh euanh deleted the source-destination-protocols branch July 10, 2025 10:41
euanh added a commit that referenced this pull request Jul 11, 2025
Motivation
----------

When the `--from scratch` option is used, `containertool` does not
download the [scratch](https://hub.docker.com/_/scratch) from Docker Hub
- instead it synthesizes a suitable empty image. Currently this is
handled by making the source client optional, but that causes `nil`
checks to spread everywhere. Now that we have the `ImageSource` protocol
(#148) we can instead use a [null
object](https://en.wikipedia.org/wiki/Null_object_pattern) which can
only return an empty image. This allows the `nil` checks to be removed
and lets the same code path handle images built on real base images and
the scratch base image.

Modifications
-------------

* Add `ScratchImage`, a null object implementing the `ImageSource`
protocol
* Remove special cases previously needed to make the image source
optional.
* Remove the option to pass `JSONEncoder` and `JSONDecoder` instances to
`RegistryClient`. Specific configuration options must be used to match
the requirements of the image specification, so there is not much value
in allowing the user to pass in an encoder with an unknown
configuration.

Result
------

* Fewer special cases
* No functional change

Test Plan
---------

Existing tests continue to pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement New feature or request semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant