docker_registry2 1.8.0 → 1.9.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
  SHA256:
3
- metadata.gz: 19ca637dbdf39b4614e28d2650e79da21fe23ad0996abcde2a4d93b4df6c8eb1
4
- data.tar.gz: 9ab57fce26b7b7f1d61e00c6c4fa3b141dcdecaeb1d3a1918f3476542d29a8c0
3
+ metadata.gz: b4b040151a73ef44e9ac9b07bb2998283fb86e1ed33d41cc523b6229e1372121
4
+ data.tar.gz: 0b27fcb25ccbe51eb4ee88655ba076d93daa8ed26de37ff0ef32185edceb9b54
5
5
  SHA512:
6
- metadata.gz: 772e70eb519763985de74098cee52c7cd7a252516dacf2e9da0f6ecfdec2e8cdcc822a80548577de15b7d73ba0bdc8edff1b9fed6a24c97c71178928840d5966
7
- data.tar.gz: 1d92a8c1c4994440cd3884592627b537f9ddcaa0836329f1bad4262561896b9b9f67b9dcb33a5ede29bf172e0281b6a694d4575a503820ac62cb557160e1c3f1
6
+ metadata.gz: 0f04c98177280e070b1d2fdc0b9577027a8802db7aa91eac54d62b5adf0043b242d6e3d896a83f8805717c5c551e16585d0c64183247149c62196e7d3092d1b6
7
+ data.tar.gz: a4101e6d617104332dbf23a0a2edd4b61dbad4b7f7844317fddbad81461a07671c405195380db95173823217e37b0c7aa839b2fa74b621cf26387a3366e06357
data/README.md CHANGED
@@ -243,6 +243,54 @@ manifest = reg.manifest("namespace/repo","2.5.6")
243
243
  manifest.headers
244
244
  ```
245
245
 
246
+ #### blob
247
+
248
+ ````ruby
249
+ > blob_digest = "sha256:87fbbe5ed7a499baa6603cd81502cfe0f26d0e9fe8b2feca8bc4ab04cd87c01e"
250
+ > blob = reg.blob("namespace/repo", blob_digest, '/path/to/blob')
251
+ ````
252
+
253
+ Returns the blob for the given digest in given repository. Blobs can vary in size, so a file path may be passed to stream the data. This is the recommended approach for downloading layer blobs due to their large size. For the format and syntax of the blob, see the [registry API](https://docs.docker.com/registry/spec/api/#blob)
254
+
255
+ The following exceptions are thrown:
256
+
257
+ * `RegistryAuthenticationException`: username and password are invalid
258
+ * `RegistryAuthorizationException`: registry does not support tags using the given
259
+ * `NotFound`: Either the repo or blob cannot be found
260
+
261
+
262
+ Alternatively, if omitted the raw blob will be returned:
263
+ ````ruby
264
+ > blob = reg.blob("namespace/repo", "sha256:437f2acdb882407ad515c936c6f1cd9adbbb1340c8b271797723464c6ac71f9b")
265
+ > blob.headers
266
+ => {:date=>"Sun, 01 Dec 2019 15:48:57 GMT", :content_type=>"application/octet-stream", :content_length=>"7016", :connection=>"keep-alive", :set_cookie=>["__cfduid=d7b1e0e004daa8e1ffd2c8c80c70959e51575215337; expires=Tue, 31-Dec-19 15:48:57 GMT; path=/; domain=.production.cloudflare.docker.com; HttpOnly; Secure"], :cf_ray=>"53e6355468b3e593-MAN", :cf_cache_status=>"HIT", :cache_control=>"public, max-age=14400", :accept_ranges=>"bytes", :age=>"990327", :etag=>"\"574739ff4eca4fe0b24bcac899909659\"", :expires=>"Sun, 01 Dec 2019 19:48:57 GMT", :last_modified=>"Wed, 20 Nov 2019 01:18:29 GMT", :vary=>"Accept-Encoding", :expect_ct=>"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", :x_amz_id_2=>"nL/phq2BUYjsGIwrSHh8QMqsnGNbjDlDjFjunI7qOqpnfR/3WAbVnKcobw4d23+nAx3lAED6Vbw=", :x_amz_request_id=>"E6B231599CAE0074", :x_amz_version_id=>"hTvrmlz_ARV25b0tY5NVrEJNlv7._2J3", :server=>"cloudflare"}
267
+ > blob.body
268
+ => "<raw body>"
269
+ ````
270
+
271
+ The mediaType on the manifest paired with the digest determines the blob format, so in the case of an image blob (`application/vnd.docker.distribution.manifest.v2+json`) the body can be deserialized from JSON
272
+
273
+ ```ruby
274
+ > manifest = reg.manifest "library/nginx", "1.17.6-alpine"
275
+ => {"schemaVersion"=>2, "mediaType"=>"application/vnd.docker.distribution.manifest.v2+json", "config"=>{"mediaType"=>"application/vnd.docker.container.image.v1+json", "size"=>7016, "digest"=>"sha256:a624d888d69ffdc185ed3b9c9c0645e8eaaac843ce59e89f1fbe45b0581e4ef6"}, "layers"=>[{"mediaType"=>"application/vnd.docker.image.rootfs.diff.tar.gzip", "size"=>2787134, "digest"=>"sha256:89d9c30c1d48bac627e5c6cb0d1ed1eec28e7dbdfbcc04712e4c79c0f83faf17"}, {"mediaType"=>"application/vnd.docker.image.rootfs.diff.tar.gzip", "size"=>5984561, "digest"=>"sha256:24f1c4f0b2f40c236ec9c306bd841778f30db9e6e7f067512732147ae7c11b07"}]}
276
+ > image_digest = manifest['config']['digest']
277
+ => "sha256:a624d888d69ffdc185ed3b9c9c0645e8eaaac843ce59e89f1fbe45b0581e4ef6"
278
+ > raw_blob = reg.blob "library/nginx", image_digest
279
+ => #<DockerRegistry2::Blob:0x007fd9bf8f2e10 ...>
280
+ > image_blob = JSON.parse(raw_blob.body)
281
+ => {...}
282
+ > image_blob['architecture']
283
+ => "amd64"
284
+ > image_blob['os']
285
+ => "linux"
286
+ > image_blob['docker_version']
287
+ => "18.06.1-ce"
288
+ > image_blob['created']
289
+ => "2019-11-20T01:16:50.939316846Z"
290
+ > image_blob['config']['Labels']
291
+ => {"maintainer"=>"NGINX Docker Maintainers <docker-maint@nginx.com>"}
292
+ ```
293
+
246
294
  #### digest
247
295
  ````ruby
248
296
  digest = reg.digest("namespace/repo", "2.5.6")
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/registry/version'
2
2
  require File.dirname(__FILE__) + '/registry/registry'
3
3
  require File.dirname(__FILE__) + '/registry/exceptions'
4
4
  require File.dirname(__FILE__) + '/registry/manifest'
5
+ require File.dirname(__FILE__) + '/registry/blob'
5
6
 
6
7
 
7
8
  module DockerRegistry2
@@ -0,0 +1,10 @@
1
+ module DockerRegistry2
2
+ class Blob
3
+ attr_reader :body, :headers
4
+
5
+ def initialize(headers, body)
6
+ @headers = headers
7
+ @body = body
8
+ end
9
+ end
10
+ end
@@ -107,6 +107,20 @@ class DockerRegistry2::Registry
107
107
  manifest
108
108
  end
109
109
 
110
+ def blob(repo, digest, outpath=nil)
111
+ blob_url = "/v2/#{repo}/blobs/#{digest}"
112
+ if outpath.nil?
113
+ response = doget(blob_url)
114
+ DockerRegistry2::Blob.new(response.headers, response.body)
115
+ else
116
+ File.open(outpath, 'w') do |fd|
117
+ doreq('get', blob_url, fd)
118
+ end
119
+
120
+ outpath
121
+ end
122
+ end
123
+
110
124
  def digest(repo, tag)
111
125
  tag_path = "/v2/#{repo}/manifests/#{tag}"
112
126
  dohead(tag_path).headers[:docker_content_digest]
@@ -148,11 +162,7 @@ class DockerRegistry2::Registry
148
162
  next if File.file? layer_file
149
163
  # download layer
150
164
  # puts "getting layer (v2) #{layer['digest']}"
151
- File.open(layer_file, 'w') do |fd|
152
- doreq('get',
153
- "/v2/#{repo}/blobs/#{layer['digest']}",
154
- fd)
155
- end
165
+ blob(repo, layer['digest'], layer_file)
156
166
  layer_file
157
167
  end
158
168
  end
@@ -169,11 +179,7 @@ class DockerRegistry2::Registry
169
179
  next if File.file? layer_file
170
180
  # download layer
171
181
  # puts "getting layer (v1) #{layer['blobSum']}"
172
- File.open(layer_file, 'w') do |fd|
173
- doreq('get',
174
- "/v2/#{repo}/blobs/#{layer['blobSum']}",
175
- fd)
176
- end
182
+ blob(repo, layer['blobSum'], layer_file)
177
183
  # return layer file
178
184
  layer_file
179
185
  end
@@ -1,3 +1,3 @@
1
1
  module DockerRegistry2
2
- VERSION = '1.8.0'
2
+ VERSION = '1.9.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: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avi Deitcher https://github.com/deitch
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-08-11 00:00:00.000000000 Z
14
+ date: 2019-12-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -78,6 +78,7 @@ files:
78
78
  - README.md
79
79
  - docker_registry2.gemspec
80
80
  - lib/docker_registry2.rb
81
+ - lib/registry/blob.rb
81
82
  - lib/registry/exceptions.rb
82
83
  - lib/registry/manifest.rb
83
84
  - lib/registry/registry.rb
@@ -101,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
104
  requirements: []
104
- rubyforge_project:
105
- rubygems_version: 2.7.3
105
+ rubygems_version: 3.0.3
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Docker v2 registry HTTP API client