Skip to content

Conversation

@euanh
Copy link
Collaborator

@euanh euanh commented Jul 10, 2025

Motivation

When the --from scratch option is used, containertool does not download the 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 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.

@euanh euanh force-pushed the scratch-client branch 5 times, most recently from ec69fc1 to 5159f79 Compare July 10, 2025 11:13
@euanh euanh changed the title containertool: Add special-case image source for scratch images, instead of optional source containertool: Use a null object to represent scratch images Jul 11, 2025
@euanh euanh marked this pull request as ready for review July 11, 2025 08:21
@euanh euanh added the semver/none No version bump required. label Jul 11, 2025
@euanh euanh force-pushed the scratch-client branch 2 times, most recently from 79a6187 to eaabb04 Compare July 11, 2025 09:48
@euanh euanh merged commit a6966f5 into apple:main Jul 11, 2025
23 checks passed
@euanh euanh deleted the scratch-client branch July 11, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant