Last active
August 29, 2015 14:19
-
-
Save fancyremarker/26551108195a9e7ceb3a to your computer and use it in GitHub Desktop.
[:octopus:] Test for Docker remote repository compatibility with old clients
This file contains hidden or 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 | |
# ruby registry-compat-test.rb namespace/repo | |
require 'faraday' | |
require 'json' | |
REPO = ARGV[0].split(':')[0] | |
TAG = ARGV[0].split(':')[1] || 'latest' | |
# Fetch image list and X-Docker-Token | |
images_url = "https://index.docker.io/v1/repositories/#{REPO}/images" | |
images_request = Faraday.new(url: images_url) | |
images_response = images_request.get do |req| | |
req.headers['X-Docker-Token'] = 'true' | |
end | |
images = JSON.parse(images_response.body).map { |entry| entry['id'] } | |
token = images_response.headers['X-Docker-Token'] | |
tag_layers_url = "https://index.docker.io/v1/repositories/#{REPO}/tags/#{TAG}" | |
tag_layers_request = Faraday.new(url: tag_layers_url) | |
tag_layers_response = tag_layers_request.get | |
layers = JSON.parse(tag_layers_response.body).map { |entry| entry['id'] } | |
layer_images = layers.map { |layer| images.find { |id| id =~ /^#{layer}/ } } | |
repo_compatible = true | |
layer_images.each do |id| | |
layer_url = "https://registry-1.docker.io/v1/images/#{id}/layer" | |
layer_request = Faraday.new(url: layer_url) | |
layer_response = layer_request.get do |req| | |
req.headers['Authorization'] = "Token #{token}" | |
end | |
path = layer_response.headers['Location'].split('/')[3] | |
puts "#{id[0..11]}: #{path}" | |
repo_compatible = false unless path == 'images' | |
end | |
puts "Compatibility: #{repo_compatible ? 'GOOD' : 'BAD'}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment