Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DockerService, ManifestService, ImageDigestCache, and RegistryServiceClient classes are all too tightly coupled #1265

Open
lbussell opened this issue May 1, 2024 · 2 comments

Comments

@lbussell
Copy link
Contributor

lbussell commented May 1, 2024

At a high level, DockerService depends on the ManifestService. However, DockerService only relies on the ManifestService for methods that have the exact same signature and behavior as ManifestService commands (or its extension methods).

public Task<IEnumerable<string>> GetImageManifestLayersAsync(string image, IRegistryCredentialsHost credsHost, bool isDryRun) =>
_manifestService.GetImageLayersAsync(image, credsHost, isDryRun);

The DockerServiceCache is also tightly coupled with the ImageDigestCache class because of the same reason. ImageDigestCache simply makes and caches calls to the ManifestService class (through DockerService).

public Task<string?> GetImageDigestAsync(string image, IRegistryCredentialsHost credsHost, bool isDryRun) =>
_imageDigestCache.GetImageDigestAsync(image, credsHost, isDryRun);

public Task<string?> GetImageDigestAsync(string tag, IRegistryCredentialsHost credsHost, bool isDryRun) =>
LockHelper.DoubleCheckedLockLookupAsync(_digestCacheLock, _digestCache, tag,
() => _dockerService.GetImageDigestAsync(tag, credsHost, isDryRun),
// Don't allow null digests to be cached. A locally built image won't have a digest until
// it is pushed so if its digest is retrieved before pushing, we don't want that
// null to be cached.
val => !string.IsNullOrEmpty(val));

We should remove DockerService's dependency on the ManifestService class, since there are commands that use the DockerService that don't rely on any functionality from the ManifestService. ImageDigestCache should become ManifestServiceCache (or potentially RegistryServiceClientCache, since that is the only class making the single network call). We should experiment with combining ManifestService and RegistryServiceClient.

Also, ManifestServiceExtensions can be combined into the ManifestService class since they are in the same namespace.

I have put together a branch where I experimented with removing the DockerService dependency on the ManifestService, but it is currently incomplete and not fully functional - https://github.com/lbussell/docker-tools/commits/dev/loganbussell/1262playground/

Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@lbussell
Copy link
Contributor Author

lbussell commented May 2, 2024

[Triage] We may want to consider keeping the ManifestServiceExtensions class, since its existence allows us to keep the IManifestService interface as small as possible which reduces the complexity of testing the ManifestService. The methods in the ManifestServiceExtensions don't rely on any of the ManifestService's internal state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Post Release
Development

No branches or pull requests

1 participant