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

WIP: Improve search method #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

vpereira
Copy link
Contributor

@vpereira vpereira commented Dec 13, 2023

Hello @deitch

I was working in a different project, where we tune the query to the "_catalog" endpoint to get more or less records per page. So I then imagined that we could have the same in the docker_registry2 gem.

So the default is 100 records per page, so thats what i set on the search method. I "precompiled" the regex used in the search method, matching the query, outside of the each loop, since it doesnt change.

Lets see if it works 👍

P.S: Ops it looks like I have to regenerate the VCR files. Nice CI pipeline you have here 😊

@deitch
Copy link
Owner

deitch commented Dec 14, 2023

Heh, didn't you add the spec in? 😁

@deitch
Copy link
Owner

deitch commented Dec 14, 2023

The prior behavior fetched them all? It looks like this adds not just an option to limit, but a default limit that did not exist before? Is that a breaking change?

@vpereira
Copy link
Contributor Author

The prior behavior fetched them all? It looks like this adds not just an option to limit, but a default limit that did not exist before? Is that a breaking change?

the default is 100 entries per page. We could for sure make the "n" optional and if nothing gets passed it gets the /_catalog as before. I will add a spec too to make sure that the n influences the number of returned entries per page

Reference: https://distribution.github.io/distribution/spec/api/

@vpereira vpereira changed the title Improve search method WIP: Improve search method Dec 14, 2023
@deitch
Copy link
Owner

deitch commented Dec 15, 2023

So you are saying that the default is 100. This PR just makes it explicit, but that is what happens anyways?
OK, then fine with me.

I approved it, just waiting for the spec you said you wanted to add.

@vpereira
Copy link
Contributor Author

vpereira commented Dec 15, 2023

@deitch

So you are saying that the default is 100. This PR just makes it explicit, but that is what happens anyways?

Exactly, the default page size for the docker official registry is 100. I will add a spec for that. Maybe we should keep the query to the "_catalog" in case people are using a different registry backend and are expecting other value there.

I approved it, just waiting for the spec you said you wanted to add.

spec will come 👍

@vpereira
Copy link
Contributor Author

Hi @deitch

While running the local registry with docker-compose up i realized, that our local images are in the v1 format, which isnt supported anymore by the new registries?

Anyway with the commands:

docker-compose up
docker pull localhost:5000/hello-world-v1
skopeo copy --dest-tls-verify=false docker-daemon:hello-world-v1:latest docker://localhost:5000/hello-world-v1:latest

I was able to convert the manifest from v1 to v2

@vpereira
Copy link
Contributor Author

I created some images locally to test the "/v2/_catalog" with the following script (that I will add to the PR)

#!/bin/bash

# Source image
source_image="localhost:5000/hello-world-v1:latest"

# Registry URL
registry_url="localhost:5000"

# Iterating from 2 to 101
for counter in {2..101}
do
    # Destination image name
    dest_image="$registry_url/hello-world-v$counter:latest"

    # Skopeo copy command
    skopeo copy --dest-tls-verify=false "docker-daemon:$source_image" "docker://$dest_image"

    # Optional: Echo to track progress
    echo "Copied to $dest_image"
done

Then to make sure that we have more than 100 images in the catalog:

$ curl -s http://localhost:5000/v2/_catalog?n=300 | jq '.repositories | length'
203

Lets check the default of calling /v2/_catalog:

$ curl -s http://localhost:5000/v2/_catalog | jq '.repositories | length'
100

So like that I'm sure the default are 100 results. I will now add the spec to make sure that we can control this value, i.e having 3 images named hello-world-{1,2,3} on my registry, i can spec that passing arbitrary values to the search method can influence the number of returned results

@@ -11,8 +11,8 @@ def self.connect(uri = 'https://registry.hub.docker.com', opts = {})
@reg = DockerRegistry2::Registry.new(uri, opts)
end

def self.search(query = '')
@reg.search(query)
def self.search(query = '', records = 100)
Copy link
Owner

Choose a reason for hiding this comment

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

Is it a bit strange that here the params are query and records, but in reg.search() they are query and record_count? Should we not be consistent?

Copy link
Contributor Author

@vpereira vpereira Jan 3, 2024

Choose a reason for hiding this comment

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

ok, i will align them 👍 .. any preferences? records or records_count ?

@@ -0,0 +1,21 @@
#!/bin/bash
Copy link
Owner

Choose a reason for hiding this comment

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

This is a nice utility, but I don't think it belongs in the root, does it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, i will move it to a better place

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.

2 participants