containertool: Use a null object to represent scratch images #149
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.
Motivation
When the
--from scratchoption is used,containertooldoes 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 causesnilchecks to spread everywhere. Now that we have theImageSourceprotocol (#148) we can instead use a null object which can only return an empty image. This allows thenilchecks to be removed and lets the same code path handle images built on real base images and the scratch base image.Modifications
ScratchImage, a null object implementing theImageSourceprotocolJSONEncoderandJSONDecoderinstances toRegistryClient. 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
Test Plan
Existing tests continue to pass.