docker_registry2 icon indicating copy to clipboard operation
docker_registry2 copied to clipboard

Feature request: Image size and mod timestamp

Open calh opened this issue 8 years ago • 3 comments

Can you add in a method to sum up the sizes from each of the blobs from an image tag? (Using the API HEAD call to /v2/#{image}/blobs/#{blobSum})

Also, it would be nice to have a convenience method to run through the v1Compatibility elements, find the most recent, and return a Time object that represents the tag's upload time.

Thank you!

calh avatar Nov 10 '16 21:11 calh

Can you add in a method to sum up the sizes from each of the blobs from an image tag? (Using the API HEAD call to /v2/#{image}/blobs/#{blobSum})

Been a bit since I worked on the manifests, so can you explain how this is used? No issues with it, but always want to understand the use case.

Also, it would be nice to have a convenience method to run through the v1Compatibility elements, find the most recent, and return a Time object that represents the tag's upload time.

Hmm, again, what is the use case?

deitch avatar Nov 10 '16 22:11 deitch

My use case is that I'm writing a backup script to stuff my older images into S3 storage. I want to pull accurate timestamps in order to implement algorithms like "keep the past 7 days". I also want to check sizes so that I can verify that a backup currently exists in S3, and has a size that's close to the size of the tag in my local repo.

On a side note, I already implemented this in my wrapper class, it'd just be nice to have in the gem:

def pull_manifest(tag)
  ret = @registry.manifest(@image, tag)
  size=0
  ret["fsLayers"].each do |layer|
    sum=layer["blobSum"]
    size += blob_size(sum)
  end
  times = []
  ret["history"].each do |i|
    # Why does this come back as a String from the gem?  (should I file a separate bug?)
    v1 = JSON.parse( i['v1Compatibility'] )
    times << Time.parse( v1['created'] )
  end
  time = times.sort!.last
end

def blob_size(checksum)
  c=Curl::Easy.new
  c.url = "https://my-registry//v2/#{image}/blobs/#{checksum}"
  c.head = true
  c.perform
  c.downloaded_content_length
end

calh avatar Nov 11 '16 15:11 calh

Finally coming back to this after a while.

On the first part, no need to ask for the sizes via HEAD, they are in the manifest. Putting it in right now. On the second part, can you explain that? I had thought they had stopped including the v1 compat elements?

deitch avatar Mar 26 '17 13:03 deitch