-
Notifications
You must be signed in to change notification settings - Fork 611
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
Conversation
5043ff2
to
71a2210
Compare
64ce955
to
e76bf47
Compare
e76bf47
to
b9437d4
Compare
b9437d4
to
bdb3741
Compare
}, | ||
expectedDistributionInspect: testDistributionInspect, | ||
}, | ||
func() testCase { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Summary
This PR adds
PullImageManifest
method toDockerClient
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 ofregistry.DistributionInspect
type.A new integration test is added for
*dockerGoClient
's implementation ofPullImageManifest
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
PullImageManifest
is added toDockerClient
interface.*dockerGoClient
type. The implementation resolves registry credentials in the same way asPullImage
and then calls Docker client's DistributionInspect API to fetch the image manifest from the registry.TestImageManifestPullInteg
is added that checks thatPullImageManifest
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 includeDistributionInspect
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.