docker-api 1.33.5 → 2.0.0.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: feaf132a5bd3b3aa9bd58bd2f0741135cedc676f
4
- data.tar.gz: 4298604d6b131a80e6d2be772c7730b474a415d2
2
+ SHA256:
3
+ metadata.gz: 88fd03d58560759042d6b5513da603fa2db7e1553e47ddcd85cf6af9df34ecf5
4
+ data.tar.gz: cccb4daff0e134328e485a81862609371990697af2c36a4694cb9ba2053e8423
5
5
  SHA512:
6
- metadata.gz: b5959dd544f98292d00b4c81ecc18292f1f152a12840109b56bdbb948bba7c1ad9755120822c8edd1ae680f9699bdc7946c8fd09e59749982c419bff71433e81
7
- data.tar.gz: 82e462599091c8234f832ad5fa7d7739b7826161a05784862e756d2a512686f7466e199c2a2c6888c60ff0dde17aea55b5478475d41b646e482f8a90e231a02a
6
+ metadata.gz: ce528e7f874a062c36fc71c531fcc038501495a9cddd71b6187169ea2278e404cb6a9fdf9d07f39327613bde8c99403d093b471e7d56717b1cb93e21f1f26d10
7
+ data.tar.gz: 04f96ad64f0aab19bd1d96d8816b247f55530b110c8717e4ee24447036302ff3ddd79070768ede3858b1c08ebc3f91b998191d48980396c1ab94c47a0c25c4ba
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  docker-api
2
2
  ==========
3
- [![Gem Version](https://badge.fury.io/rb/docker-api.svg)](https://badge.fury.io/rb/docker-api) [![travis-ci](https://travis-ci.org/swipely/docker-api.svg?branch=master)](https://travis-ci.org/swipely/docker-api) [![Code Climate](https://codeclimate.com/github/swipely/docker-api.svg)](https://codeclimate.com/github/swipely/docker-api) [![Dependency Status](https://gemnasium.com/swipely/docker-api.svg)](https://gemnasium.com/swipely/docker-api)
3
+ [![Gem Version](https://badge.fury.io/rb/docker-api.svg)](https://badge.fury.io/rb/docker-api) [![travis-ci](https://travis-ci.org/swipely/docker-api.svg?branch=master)](https://travis-ci.org/swipely/docker-api) [![Code Climate](https://codeclimate.com/github/swipely/docker-api.svg)](https://codeclimate.com/github/swipely/docker-api)
4
4
 
5
- This gem provides an object-oriented interface to the [Docker Remote API](https://docs.docker.com/reference/api/docker_remote_api/). Every method listed there is implemented. At the time of this writing, docker-api is meant to interface with Docker version 1.3.*
5
+ This gem provides an object-oriented interface to the [Docker Engine API](https://docs.docker.com/develop/sdk/). Every method listed there is implemented. At the time of this writing, docker-api is meant to interface with Docker version 1.4.*
6
6
 
7
7
  If you're interested in using Docker to package your apps, we recommend the [dockly](https://github.com/swipely/dockly) gem. Dockly provides a simple DSL for describing Docker containers that install as Debian packages and are controlled by upstart scripts.
8
8
 
@@ -36,7 +36,7 @@ docker-api is designed to be very lightweight. Almost no state is cached (aside
36
36
 
37
37
  ## Starting up
38
38
 
39
- Follow the [installation instructions](https://docs.docker.com/installation/#installation), and then run:
39
+ Follow the [installation instructions](https://docs.docker.com/install/), and then run:
40
40
 
41
41
  ```shell
42
42
  $ sudo docker -d
@@ -52,7 +52,7 @@ If you're running Docker locally as a socket, there is no setup to do in Ruby. I
52
52
  Docker.url = 'tcp://example.com:5422'
53
53
  ```
54
54
 
55
- Two things to note here. The first is that this gem uses [excon](http://www.github.com/geemus/excon), so any of the options that are valid for `Excon.new` are also valid for `Docker.options`. Second, by default Docker runs on a socket. The gem will assume you want to connect to the socket unless you specify otherwise.
55
+ Two things to note here. The first is that this gem uses [excon](https://github.com/excon/excon), so any of the options that are valid for `Excon.new` are also valid for `Docker.options`. Second, by default Docker runs on a socket. The gem will assume you want to connect to the socket unless you specify otherwise.
56
56
 
57
57
  Also, you may set the above variables via `ENV` variables. For example:
58
58
 
@@ -413,7 +413,7 @@ container.read_file("/test")
413
413
 
414
414
  # Export a Container. Since an export is typically at least 300M, chunks of the
415
415
  # export are yielded instead of just returning the whole thing.
416
- File.open('export.tar', 'w') do |f|
416
+ File.open('export.tar', 'w') do |file|
417
417
  container.export { |chunk| file.write(chunk) }
418
418
  end
419
419
  # => nil
@@ -622,10 +622,6 @@ image 'repo:new_tag' => 'repo:tag' do
622
622
  end
623
623
  ```
624
624
 
625
- ## Known issues
626
-
627
- * If the docker daemon is always responding to your requests with a 400 Bad Request when using UNIX sockets, verify you're running Excon version 0.46.0 or greater. [Link](https://github.com/swipely/docker-api/issues/381)
628
-
629
625
  ## Not supported (yet)
630
626
 
631
627
  * Generating a tarball of images and metadata for a repository specified by a name: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.14/#get-a-tarball-containing-all-images-and-tags-in-a-repository
@@ -1,5 +1,5 @@
1
1
  require 'cgi'
2
- require 'json'
2
+ require 'multi_json'
3
3
  require 'excon'
4
4
  require 'tempfile'
5
5
  require 'base64'
@@ -121,27 +121,16 @@ module Docker
121
121
 
122
122
  # Login to the Docker registry.
123
123
  def authenticate!(options = {}, connection = self.connection)
124
- creds = options.to_json
125
- connection.post('/auth', {}, :body => creds)
124
+ creds = MultiJson.dump(options)
125
+ connection.post('/auth', {}, body: creds)
126
126
  @creds = creds
127
127
  true
128
128
  rescue Docker::Error::ServerError, Docker::Error::UnauthorizedError
129
129
  raise Docker::Error::AuthenticationError
130
130
  end
131
131
 
132
- # When the correct version of Docker is installed, returns true. Otherwise,
133
- # raises a VersionError.
134
- def validate_version!
135
- Docker.info
136
- true
137
- rescue Docker::Error::TimeoutError
138
- raise
139
- rescue Docker::Error::DockerError
140
- raise Docker::Error::VersionError, "Expected API Version: #{API_VERSION}"
141
- end
142
-
143
132
  module_function :default_socket_url, :env_url, :url, :url=, :env_options,
144
133
  :options, :options=, :creds, :creds=, :logger, :logger=,
145
134
  :connection, :reset!, :reset_connection!, :version, :info,
146
- :ping, :authenticate!, :validate_version!, :ssl_options
135
+ :ping, :authenticate!, :ssl_options
147
136
  end
@@ -80,7 +80,7 @@ private
80
80
  user_agent = "Swipely/Docker-API #{Docker::VERSION}"
81
81
  {
82
82
  :method => http_method,
83
- :path => "/v#{Docker::API_VERSION}#{path}",
83
+ :path => path,
84
84
  :query => query,
85
85
  :headers => { 'Content-Type' => content_type,
86
86
  'User-Agent' => user_agent,
@@ -135,10 +135,10 @@ class Docker::Container
135
135
  # Based on the link, the config passed as run, needs to be passed as the
136
136
  # body of the post so capture it, remove from the options, and pass it via
137
137
  # the post body
138
- config = options.delete('run')
139
- hash = Docker::Util.parse_json(connection.post('/commit',
140
- options,
141
- :body => config.to_json))
138
+ config = MultiJson.dump(options.delete('run'))
139
+ hash = Docker::Util.parse_json(
140
+ connection.post('/commit', options, body: config)
141
+ )
142
142
  Docker::Image.send(:new, self.connection, hash)
143
143
  end
144
144
 
@@ -185,21 +185,21 @@ class Docker::Container
185
185
  end
186
186
 
187
187
  def update(opts)
188
- connection.post(path_for(:update), {}, body: opts.to_json)
188
+ connection.post(path_for(:update), {}, body: MultiJson.dump(opts))
189
189
  end
190
190
 
191
191
  def streaming_logs(opts = {}, &block)
192
- stack_size = opts.delete('stack_size') || -1
192
+ stack_size = opts.delete('stack_size') || opts.delete(:stack_size) || -1
193
193
  tty = opts.delete('tty') || opts.delete(:tty) || false
194
194
  msgs = Docker::MessagesStack.new(stack_size)
195
- excon_params = {response_block: Docker::Util.attach_for(block, msgs, tty)}
195
+ excon_params = {response_block: Docker::Util.attach_for(block, msgs, tty), idempotent: false}
196
196
 
197
197
  connection.get(path_for(:logs), opts, excon_params)
198
198
  msgs.messages.join
199
199
  end
200
200
 
201
201
  def start!(opts = {})
202
- connection.post(path_for(:start), {}, :body => opts.to_json)
202
+ connection.post(path_for(:start), {}, body: MultiJson.dump(opts))
203
203
  self
204
204
  end
205
205
 
@@ -225,7 +225,7 @@ class Docker::Container
225
225
  timeout = opts.delete('timeout')
226
226
  query = {}
227
227
  request_options = {
228
- :body => opts.to_json
228
+ :body => MultiJson.dump(opts)
229
229
  }
230
230
  if timeout
231
231
  query['t'] = timeout
@@ -266,14 +266,6 @@ class Docker::Container
266
266
  end
267
267
  end
268
268
 
269
- def copy(path, &block)
270
- connection.post(path_for(:copy), {},
271
- :body => { "Resource" => path }.to_json,
272
- :response_block => block
273
- )
274
- self
275
- end
276
-
277
269
  def archive_out(path, &block)
278
270
  connection.get(
279
271
  path_for(:archive),
@@ -332,17 +324,16 @@ class Docker::Container
332
324
 
333
325
  # Create a new Container.
334
326
  def self.create(opts = {}, conn = Docker.connection)
335
- name = opts.delete('name') || opts.delete(:name)
336
- query = {}
337
- query['name'] = name if name
338
- resp = conn.post('/containers/create', query, :body => opts.to_json)
327
+ query = opts.select {|key| ['name', :name].include?(key) }
328
+ clean_opts = opts.reject {|key| ['name', :name].include?(key) }
329
+ resp = conn.post('/containers/create', query, :body => MultiJson.dump(clean_opts))
339
330
  hash = Docker::Util.parse_json(resp) || {}
340
331
  new(conn, hash)
341
332
  end
342
333
 
343
334
  # Return the container with specified ID
344
335
  def self.get(id, opts = {}, conn = Docker.connection)
345
- container_json = conn.get("/containers/#{URI.encode(id)}/json", opts)
336
+ container_json = conn.get("/containers/#{id}/json", opts)
346
337
  hash = Docker::Util.parse_json(container_json) || {}
347
338
  new(conn, hash)
348
339
  end
@@ -353,6 +344,12 @@ class Docker::Container
353
344
  hashes.map { |hash| new(conn, hash) }
354
345
  end
355
346
 
347
+ # Prune images
348
+ def self.prune(conn = Docker.connection)
349
+ conn.post("/containers/prune", {})
350
+ nil
351
+ end
352
+
356
353
  # Convenience method to return the path for a particular resource.
357
354
  def path_for(resource)
358
355
  "/containers/#{self.id}/#{resource}"
@@ -29,7 +29,9 @@ class Docker::Event
29
29
 
30
30
  def stream(opts = {}, conn = Docker.connection, &block)
31
31
  conn.get('/events', opts, :response_block => lambda { |b, r, t|
32
- block.call(new_event(b, r, t))
32
+ b.each_line do |line|
33
+ block.call(new_event(line, r, t))
34
+ end
33
35
  })
34
36
  end
35
37
 
@@ -20,7 +20,7 @@ class Docker::Exec
20
20
  def self.create(options = {}, conn = Docker.connection)
21
21
  container = options.delete('Container')
22
22
  resp = conn.post("/containers/#{container}/exec", {},
23
- :body => options.to_json)
23
+ body: MultiJson.dump(options))
24
24
  hash = Docker::Util.parse_json(resp) || {}
25
25
  new(conn, hash)
26
26
  end
@@ -51,11 +51,11 @@ class Docker::Exec
51
51
  read_timeout = options[:wait]
52
52
 
53
53
  # Create API Request Body
54
- body = {
55
- "Tty" => tty,
56
- "Detach" => detached
57
- }
58
- excon_params = { :body => body.to_json }
54
+ body = MultiJson.dump(
55
+ 'Tty' => tty,
56
+ 'Detach' => detached
57
+ )
58
+ excon_params = { body: body }
59
59
 
60
60
  msgs = Docker::Messages.new
61
61
  unless detached
@@ -108,7 +108,7 @@ class Docker::Image
108
108
 
109
109
  # Create a new Image.
110
110
  def create(opts = {}, creds = nil, conn = Docker.connection, &block)
111
- credentials = creds.nil? ? Docker.creds : creds.to_json
111
+ credentials = creds.nil? ? Docker.creds : MultiJson.dump(creds)
112
112
  headers = credentials && Docker::Util.build_auth_header(credentials) || {}
113
113
  body = ''
114
114
  conn.post(
@@ -126,7 +126,7 @@ class Docker::Image
126
126
 
127
127
  # Return a specific image.
128
128
  def get(id, opts = {}, conn = Docker.connection)
129
- image_json = conn.get("/images/#{URI.encode(id)}/json", opts)
129
+ image_json = conn.get("/images/#{id}/json", opts)
130
130
  hash = Docker::Util.parse_json(image_json) || {}
131
131
  new(conn, hash)
132
132
  end
@@ -137,6 +137,12 @@ class Docker::Image
137
137
  end
138
138
  alias_method :delete, :remove
139
139
 
140
+ # Prune images
141
+ def prune(conn = Docker.connection)
142
+ conn.post("/images/prune", {})
143
+ end
144
+
145
+
140
146
  # Save the raw binary representation or one or more Docker images
141
147
  #
142
148
  # @param names [String, Array#String] The image(s) you wish to save
@@ -168,7 +174,7 @@ class Docker::Image
168
174
  # By using compare_by_identity we can create a Hash that has
169
175
  # the same key multiple times.
170
176
  query = {}.tap(&:compare_by_identity)
171
- Array(names).each { |name| query['names'.dup] = URI.encode(name) }
177
+ Array(names).each { |name| query['names'.dup] = name }
172
178
  conn.get(
173
179
  '/images/get',
174
180
  query,
@@ -206,8 +212,14 @@ class Docker::Image
206
212
 
207
213
  # Given a query like `{ :term => 'sshd' }`, queries the Docker Registry for
208
214
  # a corresponding Image.
209
- def search(query = {}, connection = Docker.connection)
210
- body = connection.get('/images/search', query)
215
+ def search(query = {}, connection = Docker.connection, creds = nil)
216
+ credentials = creds.nil? ? Docker.creds : creds.to_json
217
+ headers = credentials && Docker::Util.build_auth_header(credentials) || {}
218
+ body = connection.get(
219
+ '/images/search',
220
+ query,
221
+ :headers => headers,
222
+ )
211
223
  hashes = Docker::Util.parse_json(body) || []
212
224
  hashes.map { |hash| new(connection, 'id' => hash['name']) }
213
225
  end
@@ -3,17 +3,17 @@ class Docker::Network
3
3
  include Docker::Base
4
4
 
5
5
  def connect(container, opts = {}, body_opts = {})
6
+ body = MultiJson.dump({ container: container }.merge(body_opts))
6
7
  Docker::Util.parse_json(
7
- connection.post(path_for('connect'), opts,
8
- body: { container: container }.merge(body_opts).to_json)
8
+ connection.post(path_for('connect'), opts, body: body)
9
9
  )
10
10
  reload
11
11
  end
12
12
 
13
13
  def disconnect(container, opts = {})
14
+ body = MultiJson.dump(container: container)
14
15
  Docker::Util.parse_json(
15
- connection.post(path_for('disconnect'), opts,
16
- body: { container: container }.to_json)
16
+ connection.post(path_for('disconnect'), opts, body: body)
17
17
  )
18
18
  reload
19
19
  end
@@ -34,25 +34,24 @@ class Docker::Network
34
34
  end
35
35
 
36
36
  def reload
37
- network_json = @connection.get("/networks/#{URI.encode(@id)}")
37
+ network_json = @connection.get("/networks/#{@id}")
38
38
  hash = Docker::Util.parse_json(network_json) || {}
39
39
  @info = hash
40
40
  end
41
41
 
42
42
  class << self
43
43
  def create(name, opts = {}, conn = Docker.connection)
44
- default_opts = {
44
+ default_opts = MultiJson.dump({
45
45
  'Name' => name,
46
46
  'CheckDuplicate' => true
47
- }
48
- resp = conn.post('/networks/create', {},
49
- body: default_opts.merge(opts).to_json)
47
+ }.merge(opts))
48
+ resp = conn.post('/networks/create', {}, body: default_opts)
50
49
  response_hash = Docker::Util.parse_json(resp) || {}
51
50
  get(response_hash['Id'], {}, conn) || {}
52
51
  end
53
52
 
54
53
  def get(id, opts = {}, conn = Docker.connection)
55
- network_json = conn.get("/networks/#{URI.encode(id)}", opts)
54
+ network_json = conn.get("/networks/#{id}", opts)
56
55
  hash = Docker::Util.parse_json(network_json) || {}
57
56
  new(conn, hash)
58
57
  end
@@ -63,10 +62,15 @@ class Docker::Network
63
62
  end
64
63
 
65
64
  def remove(id, opts = {}, conn = Docker.connection)
66
- conn.delete("/networks/#{URI.encode(id)}", opts)
65
+ conn.delete("/networks/#{id}", opts)
67
66
  nil
68
67
  end
69
68
  alias_method :delete, :remove
69
+
70
+ def prune(conn = Docker.connection)
71
+ conn.post("/networks/prune", {})
72
+ nil
73
+ end
70
74
  end
71
75
 
72
76
  # Convenience method to return the path for a particular resource.
@@ -102,8 +102,8 @@ module Docker::Util
102
102
  end
103
103
 
104
104
  def parse_json(body)
105
- JSON.parse(body) unless body.nil? || body.empty? || (body == 'null')
106
- rescue JSON::ParserError => ex
105
+ MultiJson.load(body) unless body.nil? || body.empty? || (body == 'null')
106
+ rescue MultiJson::ParseError => ex
107
107
  raise UnexpectedResponseError, ex.message
108
108
  end
109
109
 
@@ -232,7 +232,7 @@ module Docker::Util
232
232
  end
233
233
 
234
234
  def build_auth_header(credentials)
235
- credentials = credentials.to_json if credentials.is_a?(Hash)
235
+ credentials = MultiJson.dump(credentials) if credentials.is_a?(Hash)
236
236
  encoded_creds = Base64.urlsafe_encode64(credentials)
237
237
  {
238
238
  'X-Registry-Auth' => encoded_creds
@@ -241,15 +241,16 @@ module Docker::Util
241
241
 
242
242
  def build_config_header(credentials)
243
243
  if credentials.is_a?(String)
244
- credentials = JSON.parse(credentials, symbolize_names: true)
244
+ credentials = MultiJson.load(credentials, symbolize_keys: true)
245
245
  end
246
- header = {
246
+
247
+ header = MultiJson.dump(
247
248
  credentials[:serveraddress].to_s => {
248
- "username" => credentials[:username].to_s,
249
- "password" => credentials[:password].to_s,
250
- "email" => credentials[:email].to_s
249
+ 'username' => credentials[:username].to_s,
250
+ 'password' => credentials[:password].to_s,
251
+ 'email' => credentials[:email].to_s
251
252
  }
252
- }.to_json
253
+ )
253
254
 
254
255
  encoded_header = Base64.urlsafe_encode64(header)
255
256
 
@@ -1,7 +1,4 @@
1
1
  module Docker
2
2
  # The version of the docker-api gem.
3
- VERSION = '1.33.5'
4
-
5
- # The version of the compatible Docker remote API.
6
- API_VERSION = '1.16'
3
+ VERSION = '2.0.0.pre.1'
7
4
  end
@@ -31,9 +31,14 @@ class Docker::Volume
31
31
  # creates a volume with an arbitrary name
32
32
  def create(name, opts = {}, conn = Docker.connection)
33
33
  opts['Name'] = name
34
- resp = conn.post('/volumes/create', {}, :body => opts.to_json)
34
+ resp = conn.post('/volumes/create', {}, body: MultiJson.dump(opts))
35
35
  hash = Docker::Util.parse_json(resp) || {}
36
36
  new(conn, hash)
37
37
  end
38
+
39
+ def prune(conn = Docker.connection)
40
+ conn.post("/volumes/prune")
41
+ end
42
+
38
43
  end
39
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.33.5
4
+ version: 2.0.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swipely, Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-16 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -16,16 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.38.0
19
+ version: 0.47.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.38.0
26
+ version: 0.47.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: json
28
+ name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -179,7 +179,7 @@ homepage: https://github.com/swipely/docker-api
179
179
  licenses:
180
180
  - MIT
181
181
  metadata: {}
182
- post_install_message:
182
+ post_install_message:
183
183
  rdoc_options: []
184
184
  require_paths:
185
185
  - lib
@@ -190,14 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
190
  version: '0'
191
191
  required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  requirements:
193
- - - ">="
193
+ - - ">"
194
194
  - !ruby/object:Gem::Version
195
- version: '0'
195
+ version: 1.3.1
196
196
  requirements: []
197
- rubyforge_project:
198
- rubygems_version: 2.4.6
199
- signing_key:
197
+ rubygems_version: 3.1.2
198
+ signing_key:
200
199
  specification_version: 4
201
200
  summary: A simple REST client for the Docker Remote API
202
201
  test_files: []
203
- has_rdoc: