dockerapi 0.16.0 → 0.17.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: 8207aa413525c868d4e1c0f57cacf38c19348dee819da2aeb63f390d5ac41f28
4
- data.tar.gz: 53406674405580c0dcb91c4c32a914ef0de92ce9a9c1132eb7bf046902e5adc8
3
+ metadata.gz: 1965ae78342ecc9d450e4cc8262352405784881e31231d700dd606a15d9b58eb
4
+ data.tar.gz: bea7418501d8a3c08ea73f6c6970b08afe7358c7a15e790b7d51011bb69cd721
5
5
  SHA512:
6
- metadata.gz: be5d82c94e72b29d4341330b3c12f4a2007c6e46813cca6eb6cc8ba3f3a0adae2cd8ef00d0020ed1d59bf5bfc12bf6b22f6b3dd96eb5287ee03f02e14f1bb0ce
7
- data.tar.gz: f4155422936cd0a4e754d4f32a118662c1d6ace28d788aae51e4d09f09b817519ed7ec0bca9e1955bcb2edc66c5ea111181493e43d398de20e4662d665ac8d2b
6
+ metadata.gz: 91a6a4e8f85632f9294a07ae2e4bee24d4ff79543b1f50d240638b98d5e9bcc792193be15fa6003d97c73ec8f4b5126f0fe7294367160fce16f8eebd689b5198
7
+ data.tar.gz: 8a9a1b6ee4bbe7f10c0ae1396eb51e2cb246a37f490758a0278dfe7b06612870a4c12886caf01b9a575b255decec7faf5f0f4ef9d49e2df76a3cb80e4ca06776
@@ -1,3 +1,7 @@
1
+ # 0.17.0
2
+
3
+ New block execution introduced in [PR#1](https://github.com/nu12/dockerapi/pull/1).
4
+
1
5
  # 0.16.0
2
6
 
3
7
  `Docker::API::Task#logs` method can now receive a block to replace standard output to stdout behavior.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dockerapi (0.16.0)
4
+ dockerapi (0.17.0)
5
5
  excon (~> 0.76.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -21,6 +21,7 @@ Interact with Docker API directly from Ruby code. Comprehensive implementation (
21
21
  * [Requests](#requests)
22
22
  * [Response](#response)
23
23
  * [Error handling](#error-handling)
24
+ * [Blocks](#blocks)
24
25
  * [Development](#development)
25
26
  * [Contributing](#contributing)
26
27
  * [License](#license)
@@ -533,30 +534,38 @@ response.success?
533
534
 
534
535
  To completely skip the validation process, add `:skip_validation => true` in the hash to be validated.
535
536
 
537
+ ### Blocks
538
+
539
+ Some methods can receive a block to alter the default execution:
540
+ * Docker::API::Container#logs
541
+ * Docker::API::Container#attach
542
+ * Docker::API::Container#stats
543
+ * Docker::API::Container#export
544
+ * Docker::API::Container#get_archive
545
+ * Docker::API::Image#create
546
+ * Docker::API::Image#build
547
+ * Docker::API::Image#export
548
+ * Docker::API::System#event
549
+ * Docker::API::Exec#start
550
+ * Docker::API::Task#logs
551
+
552
+ Example:
553
+ ```ruby
554
+ => image = Docker::API::Image.new
555
+
556
+ => image.create(fromImage: "nginx:alpine") do | chunk, bytes_remaining, bytes_total |
557
+ p chunk.to_s
558
+ end
559
+ ```
560
+
561
+ The default blocks can be found in `Docker::API::Base`.
562
+
536
563
  ## Development
537
564
 
538
565
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
539
566
 
540
567
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
541
568
 
542
- ### Road to 1.0.0
543
-
544
- | Class | Tests | Implementation | Refactoring |
545
- |---|---|---|---|
546
- | Image | Ok | Ok | Ok |
547
- | Container | Ok | Ok | Ok |
548
- | Volume | Ok | Ok | Ok |
549
- | Network | Ok | Ok | Ok |
550
- | System | Ok | Ok | Ok |
551
- | Exec | Ok | Ok | Ok |
552
- | Swarm | Ok | Ok | Ok |
553
- | Node | Ok | Ok | Ok |
554
- | Service | Ok | Ok | Ok |
555
- | Task | Ok | Ok | Ok |
556
- | Secret | Ok | Ok | Ok |
557
- | Config | Ok | Ok | 8/14 |
558
- | Plugin | Ok | Ok | 8/14 |
559
-
560
569
  ## Contributing
561
570
 
562
571
  Bug reports and pull requests are welcome on GitHub at https://github.com/nu12/dockerapi.
@@ -46,7 +46,7 @@ class Docker::API::Base
46
46
  # @param &block: Replace the default output to stdout behavior.
47
47
  def default_reader path, url, header = {"Content-Type" => "application/x-tar"}, &block
48
48
  file = File.open(File.expand_path(path), "r")
49
- response = @connection.request(method: :post, path: url , headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s}, response_block: block_given? ? block.call : default_streamer )
49
+ response = @connection.request(method: :post, path: url , headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s}, response_block: block_given? ? block : default_streamer )
50
50
  file.close
51
51
  response
52
52
  end
@@ -204,7 +204,7 @@ class Docker::API::Container < Docker::API::Base
204
204
  path = build_path("/containers/#{name}/logs", params)
205
205
 
206
206
  if [true, 1 ].include? params[:follow]
207
- @connection.request(method: :get, path: path , response_block: block_given? ? block.call : default_streamer)
207
+ @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
208
208
  else
209
209
  @connection.get(path)
210
210
  end
@@ -220,7 +220,7 @@ class Docker::API::Container < Docker::API::Base
220
220
  # @param params [Hash]: Parameters that are appended to the URL.
221
221
  # @param &block: Replace the default output to stdout behavior.
222
222
  def attach name, params = {}, &block
223
- @connection.request(method: :post, path: build_path("/containers/#{name}/attach", params) , response_block: block_given? ? block.call : default_streamer)
223
+ @connection.request(method: :post, path: build_path("/containers/#{name}/attach", params) , response_block: block_given? ? block : default_streamer)
224
224
  end
225
225
 
226
226
  ##
@@ -247,7 +247,7 @@ class Docker::API::Container < Docker::API::Base
247
247
  def stats name, params = {}, &block
248
248
  path = build_path("/containers/#{name}/stats", params)
249
249
  if [true, 1 ].include? params[:stream]
250
- @connection.request(method: :get, path: path , response_block: block_given? ? block.call : default_streamer)
250
+ @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
251
251
  else
252
252
  @connection.get(path)
253
253
  end
@@ -265,7 +265,7 @@ class Docker::API::Container < Docker::API::Base
265
265
  def export name, path, &block
266
266
  response = self.details(name)
267
267
  return response unless response.status == 200
268
- @connection.request(method: :get, path: "/containers/#{name}/export" , response_block: block_given? ? block.call : default_writer(path))
268
+ @connection.request(method: :get, path: "/containers/#{name}/export" , response_block: block_given? ? block : default_writer(path))
269
269
  end
270
270
 
271
271
  ##
@@ -285,7 +285,7 @@ class Docker::API::Container < Docker::API::Base
285
285
  return response unless response.status == 200
286
286
 
287
287
  file = File.open( File.expand_path( path ) , "wb")
288
- response = @connection.request(method: :get, path: build_path("/containers/#{name}/archive", params) , response_block: block_given? ? block.call : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
288
+ response = @connection.request(method: :get, path: build_path("/containers/#{name}/archive", params) , response_block: block_given? ? block : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
289
289
  file.close
290
290
  response
291
291
  end
@@ -26,7 +26,7 @@ class Docker::API::Exec < Docker::API::Base
26
26
  # @param &block: Replace the default output to stdout behavior.
27
27
  def start name, body = {}, &block
28
28
  @connection.request(method: :post, path: "/exec/#{name}/start", headers: {"Content-Type": "application/json"}, body: body.to_json,
29
- response_block: block_given? ? block.call : default_streamer )
29
+ response_block: block_given? ? block : default_streamer )
30
30
  end
31
31
 
32
32
  ##
@@ -105,7 +105,7 @@ class Docker::API::Image < Docker::API::Base
105
105
  # @param path [String]: Path to the exported file.
106
106
  # @param &block: Replace the default file writing behavior.
107
107
  def export name, path, &block
108
- @connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block.call : default_writer(path))
108
+ @connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block : default_writer(path))
109
109
  end
110
110
 
111
111
  ##
@@ -158,7 +158,7 @@ class Docker::API::Image < Docker::API::Base
158
158
  # @param authentication [Hash]: Authentication parameters.
159
159
  # @param &block: Replace the default output to stdout behavior.
160
160
  def create params = {}, authentication = {}, &block
161
- request = {method: :post, path: build_path("/images/create", params), response_block: block_given? ? block.call : default_streamer }
161
+ request = {method: :post, path: build_path("/images/create", params), response_block: block_given? ? block : default_streamer }
162
162
  if params.has_key? :fromSrc and !params[:fromSrc].match(/^(http|https)/) # then it's using a tar file
163
163
  path = params[:fromSrc]
164
164
  params[:fromSrc] = "-"
@@ -186,7 +186,7 @@ class Docker::API::Image < Docker::API::Base
186
186
  headers.merge!({"X-Registry-Config": auth_encoder(authentication) }) if authentication.keys.size > 0
187
187
 
188
188
  if path == nil and params.has_key? :remote
189
- response = @connection.request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block.call : default_streamer)
189
+ response = @connection.request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block : default_streamer)
190
190
  else
191
191
  default_reader(path, build_path("/build", params), headers)
192
192
  end
@@ -23,7 +23,7 @@ class Docker::API::System < Docker::API::Base
23
23
  # @param params [Hash]: Parameters that are appended to the URL.
24
24
  # @param &block: Replace the default output to stdout behavior.
25
25
  def events params = {}, &block
26
- @connection.request(method: :get, path: build_path("/events", params), response_block: block_given? ? block.call : default_streamer )
26
+ @connection.request(method: :get, path: build_path("/events", params), response_block: block_given? ? block : default_streamer )
27
27
  end
28
28
 
29
29
  ##
@@ -36,7 +36,7 @@ class Docker::API::Task < Docker::API::Base
36
36
  path = build_path("/tasks/#{name}/logs", params)
37
37
 
38
38
  if [true, 1 ].include? params[:follow]
39
- @connection.request(method: :get, path: path , response_block: block_given? ? block.call : default_streamer)
39
+ @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
40
40
  else
41
41
  @connection.get(path)
42
42
  end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.16.0"
3
+ GEM_VERSION = "0.17.0"
4
4
 
5
5
  API_VERSION = "1.40"
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alysson A. Costa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-11 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.1.2
90
+ rubygems_version: 3.1.4
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Interact with Docker API from Ruby code.