docker_registry2 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c827b61fd48f2bd6359d119f56abcc48be8ccf57
4
- data.tar.gz: b73fec0b836cbb3930a44e830c8ef44664d63cd2
3
+ metadata.gz: 992caae84eabca0ad18bcc512d5597374dc6118d
4
+ data.tar.gz: b2c5bf87009426992b0e7fe033c0f68bfcedbca8
5
5
  SHA512:
6
- metadata.gz: eb535e5baa99262fd1a5819a9df3bdf7c9d98a8b13782c1dfecaeff1a05071e9b4c16e9df0d6f6a25749434f5a7280617f7dab458e6b08f94e60bc1c3909cf68
7
- data.tar.gz: ba4f8dfaa9ef8b3210d317f5cb9d843fc21b60e2a15101f609adb0118ced20b2c8b73ebdf29d0f5d2ee2501aadb6dc8c8f947d27eef016108de357a4cbb23d38
6
+ metadata.gz: aa966c198aed38cc24d0f249ba0d0add2dff8f6ea890488f3bb1e9276668c89c0679d22f7049d66a8968933481df96297e4773458e5e89f1f00c98ed782d7618
7
+ data.tar.gz: de196e0db00daf1c698ac31bc28835f79bc8beffad0acae27318b44a578e6441f08330177986639dc300a339be61759e651a046ba5e0cfbb5d06dc06c3e69809
data/README.md CHANGED
@@ -38,6 +38,17 @@ And execute:
38
38
  Once it is installed, you first *open* a connection to a registry, and then *request* from the registry.
39
39
 
40
40
  ### Connecting
41
+ Use the `connect` method to connect to a registry:
42
+
43
+ ````ruby
44
+ reg = DockerRegistry2.connect("https://my.registy.corp.com")
45
+ ````
46
+
47
+ If you do not provide the URL for a registry, it uses the default `https://registry.hub.docker.com`.
48
+
49
+
50
+
51
+ You can connect anonymously or with credentials:
41
52
 
42
53
  #### Anonymous
43
54
  To connect to a registry:
@@ -78,7 +89,7 @@ Once you have a valid `reg` object return by `DockerRegistry2.connect()`, you ca
78
89
  results = reg.search("mylibs")
79
90
  ````
80
91
 
81
- Returns all repositories whose name contains `"mylibs"`.
92
+ Returns all repositories whose name contains `"mylibs"`.
82
93
 
83
94
  **Note:** The v2 registry does not support search directly server-side. Thus, this is simulated by using the `catalog/` endpoint. It is highly recommended to avoid using this function until the v2 registry supports direct search, as it will be slow. It pulls a list of all repositories to the client and then does a pattern match on them.
84
95
 
@@ -126,7 +137,7 @@ The response structure looks something like this:
126
137
  }
127
138
  ````
128
139
 
129
- It is important to note that the hashes **may** or **may not** match the hashes that you receive when running `docker images` on your machine. These are the hashes returned by the `Docker-Content-Digest` for the manifest. See [v2 API Spec](https://docs.docker.com/registry/spec/api/#get-manifest).
140
+ It is important to note that the hashes **may** or **may not** match the hashes that you receive when running `docker images` on your machine. These are the hashes returned by the `Docker-Content-Digest` for the manifest. See [v2 API Spec](https://docs.docker.com/registry/spec/api/#get-manifest).
130
141
 
131
142
  These **may** or **may not** be useful for comparing to the local image on disk when running `docker images`. These **are** useful for comparing 2 different tags or images in one or more registries.
132
143
 
@@ -244,6 +255,26 @@ The following exceptions are thrown:
244
255
  * `RegistryAuthenticationException`: username and password are invalid
245
256
  * `RegistryAuthorizationException`: registry does not support your deleting the given repository, probably because you do not have sufficient access rights.
246
257
 
258
+ #### Layer sizes
259
+ If you want to get the sizes of one or more layers in an image, you have several convenience functions available.
260
+
261
+ ##### Total Size
262
+ If you want to add up easily all of the layers in a manifest (which, of course, should equal the total size of the image), you can pass the manifest to the `manifest_sum` method.
263
+
264
+ ```ruby
265
+ manifest = reg.manifest "library/ubuntu", "16.04"
266
+ totalSize = reg.manifest_sum manifest
267
+ ```
268
+
269
+ ##### Single Blob
270
+ If you have the repo name and the sha256 hash for the blob, you can get the size of the layer by doing:
271
+
272
+ ```ruby
273
+ reg.blob_size "namespace/repo", "sha256:abc5634737434"
274
+ ```
275
+
276
+ Of course, most of the time you won't need this, since the sizes are already included in the same place you got the blob hashes in the first place: the manifest.
277
+
247
278
 
248
279
  ### Exceptions
249
280
 
@@ -258,10 +289,6 @@ MIT License.
258
289
 
259
290
  ## Contribution
260
291
 
261
- Developed by Avi Deitcher http://github.com/deitch
292
+ Developed by Avi Deitcher http://github.com/deitch
262
293
  Contributors Jonathan Hurter https://github.com/johnsudaar
263
294
  Contributions courtesy of TraderTools, Inc. http://tradertools.com
264
-
265
-
266
-
267
-
@@ -4,19 +4,19 @@ require File.dirname(__FILE__) + '/registry/exceptions'
4
4
 
5
5
 
6
6
  module DockerRegistry2
7
- def self.connect(uri)
7
+ def self.connect(uri="https://registry.hub.docker.com")
8
8
  @reg = DockerRegistry2::Registry.new(uri)
9
- end
10
-
9
+ end
10
+
11
11
  def self.search(query = '')
12
12
  @reg.search(query)
13
13
  end
14
14
 
15
15
  def self.tags(repository)
16
16
  @reg.tags(repository)
17
- end
18
-
17
+ end
18
+
19
19
  def self.manifest(repository,tag)
20
20
  @reg.manifest(repository,tag)
21
21
  end
22
- end
22
+ end
@@ -44,7 +44,7 @@ class DockerRegistry2::Registry
44
44
  # parse the response
45
45
  resp = JSON.parse response
46
46
  # do we include the hashes?
47
- if withHashes then
47
+ if withHashes then
48
48
  useGet = false
49
49
  resp["hashes"] = {}
50
50
  resp["tags"].each {|tag|
@@ -62,38 +62,53 @@ class DockerRegistry2::Registry
62
62
  resp["hashes"][tag] = head.headers[:docker_content_digest]
63
63
  }
64
64
  end
65
-
65
+
66
66
  return resp
67
67
  end
68
-
68
+
69
69
  def manifest(repo,tag)
70
70
  # first get the manifest
71
71
  JSON.parse doget "/v2/#{repo}/manifests/#{tag}"
72
72
  end
73
-
73
+
74
74
  def pull(repo,tag,dir)
75
75
  # make sure the directory exists
76
76
  FileUtils::mkdir_p dir
77
77
  # get the manifest
78
78
  m = manifest repo,tag
79
79
  # pull each of the layers
80
- layers = m["fsLayers"].each { |layer|
80
+ layers = m["layers"].each { |layer|
81
81
  # make sure the layer does not exist first
82
82
  if ! File.file? "#{dir}/#{layer.blobSum}" then
83
83
  doget "/v2/#{repo}/blobs/#{layer.blobSum}" "#{dir}/#{layer.blobSum}"
84
84
  end
85
85
  }
86
86
  end
87
-
87
+
88
88
  def push(manifest,dir)
89
89
  end
90
-
90
+
91
91
  def tag(repo,tag,newrepo,newtag)
92
92
  end
93
-
93
+
94
94
  def copy(repo,tag,newregistry,newrepo,newtag)
95
95
  end
96
-
96
+
97
+ # gets the size of a particular blob, given the repo and the content-addressable hash
98
+ # usually unneeded, since manifest includes it
99
+ def blob_size(repo,blobSum)
100
+ response = dohead "/v2/#{repo}/blobs/#{blobSum}"
101
+ Integer(response.headers[:content_length],10)
102
+ end
103
+
104
+ def manifest_sum(manifest)
105
+ size = 0
106
+ manifest["layers"].each { |layer|
107
+ size += layer["size"]
108
+ }
109
+ size
110
+ end
111
+
97
112
  private
98
113
  def doreq(type,url,stream=nil)
99
114
  begin
@@ -1,3 +1,3 @@
1
1
  module DockerRegistry2
2
- VERSION = '0.4.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_registry2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avi Deitcher https://github.com/deitch
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-27 00:00:00.000000000 Z
13
+ date: 2017-03-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler