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

Add functionality to pull image manifests to DockerClient #4140

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

amogh09
Copy link
Contributor

@amogh09 amogh09 commented Apr 14, 2024

Summary

This PR adds PullImageManifest method to DockerClient interface and adds an implementation of the method for *dockerGoClient. The method is supposed to get image manifest for the provided image reference and return the manifest as a value of registry.DistributionInspect type.

A new integration test is added for *dockerGoClient's implementation of PullImageManifest that checks that the implementation works for public and private registries. For the test, scripts/setup-test-registry script is updated to start a private registry on the host in addition to the public registry it already starts.

Implementation details

  • A new method PullImageManifest is added to DockerClient interface.
  • The method is implemented for *dockerGoClient type. The implementation resolves registry credentials in the same way as PullImage and then calls Docker client's DistributionInspect API to fetch the image manifest from the registry.
  • A new integration test TestImageManifestPullInteg is added that checks that PullImageManifest method of *dockerGoClient is able to pull image manifests from public and private registries. scripts/setup-test-registry script is updated to start a private registry in addition to the public registry that it already starts. The private registry is used by the test. The private registry uses basic auth credentials to authenticate and authorize requests. The script generates an htpasswd file which is provided to the registry. The file contains a single basic auth username/password pair where the username is "username" and password is "password". Password in the file is hashed using bcrypt algorithm as required by the registry container. So, requests to the registry need to include basic auth credentials that match this username and password pair.
  • sdkclient.Client interface that is a wrapper around Docker client's API is updated to include DistributionInspect method.

Testing

Added new unit and integration tests.

New tests cover the changes: yes

Description for the changelog

Does this PR include breaking model changes? If so, Have you added transformation functions?

Enhancement: Add image manifest pull functionality to DockerClient

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@amogh09 amogh09 changed the base branch from master to dev April 14, 2024 18:06
@amogh09 amogh09 force-pushed the manifest-fetch-func branch 2 times, most recently from 64ce955 to e76bf47 Compare April 17, 2024 00:47
@amogh09 amogh09 marked this pull request as ready for review April 17, 2024 00:57
@amogh09 amogh09 requested a review from a team as a code owner April 17, 2024 00:57
@amogh09 amogh09 changed the title Manifest fetch func Add functionality to pull image manifests to DockerClient Apr 17, 2024
},
expectedDistributionInspect: testDistributionInspect,
},
func() testCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: Didn't know we could do this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes how cool is that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows tighter scoping of variables.

// Get auth creds
sdkAuthConfig, err := dg.getAuthdata(imageRef, authData)
if err != nil {
return registry.DistributionInspect{}, wrapPullErrorAsNamedError(imageRef, err)
Copy link
Contributor

@mye956 mye956 Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Just curious, any reasons why we can't use nil if there were errors?

Copy link
Contributor Author

@amogh09 amogh09 Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's because this method has a value return type and not a pointer so the compiler won't allow returning nil. I think it's standard practice to return zero value (that's what var d registry.DistributionInspect would initialize to as well). I just followed the method signature of Docker SDK which is

DistributionInspect(ctx context.Context, imageRef, encodedRegistryAuth string) (registry.DistributionInspect, error)

It is just like how functions that have a (string, error) return type would return "", nil for error cases and not a nil. The user must check the returned error before using the returned value.

@amogh09 amogh09 merged commit 0cb285e into aws:dev Apr 18, 2024
40 checks passed
@harishxr harishxr mentioned this pull request Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants