Last active
July 11, 2019 16:11
-
-
Save ayosec/bb5fdc883867ef770754acb579215b5a to your computer and use it in GitHub Desktop.
Script to see image sizes in Docker Hub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "json" | |
case ARGV.size | |
when 1 | |
image = ARGV[0] | |
limit = 20 | |
when 2 | |
image = ARGV[0] | |
limit = ARGV[1] | |
else | |
STDERR.puts "Usage: docker-hub-images image [limit]" | |
exit 1 | |
end | |
if not image.include?("/") | |
image = "library/" + image | |
end | |
curl_cmd = %w(curl -s --user-agent Firefox -G) | |
curl_cmd << "https://hub.docker.com/v2/repositories/#{image}/tags/" | |
curl_cmd << "-d" << "page_size=#{limit}" | |
curl_cmd << "-d" << "page=1" | |
resp = IO.popen(curl_cmd) do |io| | |
JSON.parse(io.read) | |
end | |
count = resp["count"] | |
if not count | |
jj resp | |
exit 1 | |
end | |
puts "Found #{count} images" | |
results = resp["results"].map do |image| | |
[ image["name"], "#{image["full_size"] / 1024 / 1024} Mib" ] | |
end | |
name_length = results.map {|r| r[0].size }.max + 3 | |
results.each_with_index do |image, index| | |
print "%5d " % (index + 1) | |
print image[0].ljust(name_length) | |
puts image[1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment