Class: DockerRegistry::Registry
- Inherits:
-
Object
- Object
- DockerRegistry::Registry
- Defined in:
- lib/registry/registry.rb
Instance Method Summary collapse
- #copy(repo, tag, newregistry, newrepo, newtag) ⇒ Object
- #doget(url) ⇒ Object
- #dohead(url) ⇒ Object
-
#initialize(uri, options = {}) ⇒ Registry
constructor
A new instance of Registry.
- #manifest(repo, tag) ⇒ Object
- #ping ⇒ Object
- #pull(repo, tag, dir) ⇒ Object
- #push(manifest, dir) ⇒ Object
- #search(query = '') ⇒ Object
- #tag(repo, tag, newrepo, newtag) ⇒ Object
- #tags(repo, withHashes = false) ⇒ Object
Constructor Details
#initialize(uri, options = {}) ⇒ Registry
Returns a new instance of Registry.
10 11 12 13 14 15 16 17 |
# File 'lib/registry/registry.rb', line 10 def initialize(uri, = {}) @uri = URI.parse(uri) @base_uri = "#{@uri.scheme}://#{@uri.host}:#{@uri.port}" @user = @uri.user @password = @uri.password # make a ping connection ping end |
Instance Method Details
#copy(repo, tag, newregistry, newrepo, newtag) ⇒ Object
94 95 |
# File 'lib/registry/registry.rb', line 94 def copy(repo,tag,newregistry,newrepo,newtag) end |
#doget(url) ⇒ Object
19 20 21 |
# File 'lib/registry/registry.rb', line 19 def doget(url) return doreq "get", url end |
#dohead(url) ⇒ Object
23 24 25 |
# File 'lib/registry/registry.rb', line 23 def dohead(url) return doreq "head", url end |
#manifest(repo, tag) ⇒ Object
69 70 71 72 |
# File 'lib/registry/registry.rb', line 69 def manifest(repo,tag) # first get the manifest JSON.parse doget "/v2/#{repo}/manifests/#{tag}" end |
#ping ⇒ Object
27 28 29 |
# File 'lib/registry/registry.rb', line 27 def ping response = doget '/v2/' end |
#pull(repo, tag, dir) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/registry/registry.rb', line 74 def pull(repo,tag,dir) # make sure the directory exists FileUtils::mkdir_p dir # get the manifest m = manifest repo,tag # pull each of the layers layers = m["fsLayers"].each { |layer| # make sure the layer does not exist first if ! File.file? "#{dir}/#{layer.blobSum}" then doget "/v2/#{repo}/blobs/#{layer.blobSum}" "#{dir}/#{layer.blobSum}" end } end |
#push(manifest, dir) ⇒ Object
88 89 |
# File 'lib/registry/registry.rb', line 88 def push(manifest,dir) end |
#search(query = '') ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/registry/registry.rb', line 31 def search(query = '') response = doget "/v2/_catalog" # parse the response repos = JSON.parse(response)["repositories"] if query.strip.length > 0 re = Regexp.new query repos = repos.find_all {|e| re =~ e } end return repos end |
#tag(repo, tag, newrepo, newtag) ⇒ Object
91 92 |
# File 'lib/registry/registry.rb', line 91 def tag(repo,tag,newrepo,newtag) end |
#tags(repo, withHashes = false) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/registry/registry.rb', line 42 def (repo,withHashes = false) response = doget "/v2/#{repo}/tags/list" # parse the response resp = JSON.parse response # do we include the hashes? if withHashes then useGet = false resp["hashes"] = {} resp["tags"].each {|tag| if useGet then head = doget "/v2/#{repo}/manifests/#{tag}" else begin head = dohead "/v2/#{repo}/manifests/#{tag}" rescue DockerRegistry::InvalidMethod # in case we are in a registry pre-2.3.0, which did not support manifest HEAD useGet = true head = doget "/v2/#{repo}/manifests/#{tag}" end end resp["hashes"][tag] = head.headers[:docker_content_digest] } end return resp end |