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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions copy-images.sh
Original file line number Diff line number Diff line change
@@ -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


# 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

4 changes: 2 additions & 2 deletions lib/docker_registry2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?

@reg.search(query, records)
end

def self.tags(repository)
Expand Down
16 changes: 10 additions & 6 deletions lib/registry/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ def paginate_doget(url)
end
end

def search(query = '')
def search(query = '', record_count = 100)
all_repos = []
paginate_doget('/v2/_catalog') do |response|
repos = JSON.parse(response)['repositories']
repos.select! { |repo| repo.match?(/#{query}/) } unless query.empty?
all_repos += repos
regex = Regexp.new(Regexp.escape(query), Regexp::IGNORECASE) unless query.empty?

paginate_doget("/v2/_catalog?n=#{record_count}") do |response|
repos = JSON.parse(response).fetch('repositories', [])
repos.each do |repo|
all_repos << repo if query.empty? || regex.match?(repo)
end
end

all_repos
end

Expand Down Expand Up @@ -246,7 +250,7 @@ def parse_link_header(header)
links = {}

# Parse each part into a named link
parts.each do |part, _index|
parts.each_key do |part|
section = part.split(';')
url = section[0][/<(.*)>/, 1]
name = section[1][/rel="?([^"]*)"?/, 1].to_sym
Expand Down
2 changes: 1 addition & 1 deletion spec/vcr/search/hello_world.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading