From 668a3a38156f1edf1a8eb6d13f29a5f150eaa1a8 Mon Sep 17 00:00:00 2001 From: Victor Pereira Date: Wed, 13 Dec 2023 20:11:54 +0100 Subject: [PATCH 1/3] Improve search method --- lib/docker_registry2.rb | 4 ++-- lib/registry/registry.rb | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/docker_registry2.rb b/lib/docker_registry2.rb index b29f068..e3a9ea0 100644 --- a/lib/docker_registry2.rb +++ b/lib/docker_registry2.rb @@ -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) + @reg.search(query, records) end def self.tags(repository) diff --git a/lib/registry/registry.rb b/lib/registry/registry.rb index 5f804e0..d68faf5 100644 --- a/lib/registry/registry.rb +++ b/lib/registry/registry.rb @@ -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 @@ -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 From 47460972488927126bdd008a619f1e7bda99c94f Mon Sep 17 00:00:00 2001 From: Victor Pereira Date: Wed, 13 Dec 2023 20:41:03 +0100 Subject: [PATCH 2/3] Fix search VCR --- spec/vcr/search/hello_world.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/vcr/search/hello_world.yml b/spec/vcr/search/hello_world.yml index 968de6c..4719c54 100644 --- a/spec/vcr/search/hello_world.yml +++ b/spec/vcr/search/hello_world.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://localhost:5000/v2/_catalog + uri: http://localhost:5000/v2/_catalog?n=100 body: encoding: US-ASCII string: '' From 260adcc4d6f2bfdbd569bbb2cd40205e2cd28d0a Mon Sep 17 00:00:00 2001 From: Victor Pereira Date: Wed, 20 Dec 2023 14:19:26 +0100 Subject: [PATCH 3/3] Script to create copies of images --- copy-images.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 copy-images.sh diff --git a/copy-images.sh b/copy-images.sh new file mode 100755 index 0000000..ae7e8c6 --- /dev/null +++ b/copy-images.sh @@ -0,0 +1,21 @@ +#!/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 +