dockerapi 0.7.0 → 0.11.0

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
2
  SHA256:
3
- metadata.gz: 756ada080034328ec7c5e7950d5565e6e7d3612bc92af58d9c8f89558a75f5c5
4
- data.tar.gz: cba4ac000ef8e9d4374bc36be4e87dd3c2227b2fa59cc062f24ad7a06de11c52
3
+ metadata.gz: '09aa5bf2a46df8ad42f1c4833fe7577610af14dde350730787b703e1080fa4c7'
4
+ data.tar.gz: 0be7a47781bbc7f75824f65b8fea5d7bcbd11deb98451f2b030856391a68d5c1
5
5
  SHA512:
6
- metadata.gz: 0c6c059fa47afc4749dac18c62d61a984c2874b41046c2926d7eb884a7761ea088fef4209deaf71fe5864e5351e8e96a975f29520760ae6559209d323dd4f4b6
7
- data.tar.gz: 25bad2ed4c92a2b5551d78e3a12833037623e7f26045a829b587d4136c383d7431ae7a3d17bf6b9ca139c4fcc060cbf07f15a61854a4a43f601455613174f943
6
+ metadata.gz: f0573e091c6cbbc6c2fa3411ca6336a328e4677a656f22bd7d4a036064f8c813523c6a686c2e3ec03df2ec194f65c1b69c6d5be5782c1a1fca80460f3c383db9
7
+ data.tar.gz: 5fa96ad226aad3faa2e3a2836948687adf29079b0495e88ceb42424bbe14d2664cab4a8f59a2a795e2f73c9fe59318504a9c454b4964d1b16a04165023c7e8f8
@@ -1,6 +1,78 @@
1
+ # 0.11.0
2
+
3
+ Add `Docker::API::Task` methods:
4
+ * list
5
+ * details
6
+ * logs
7
+
8
+ Add `Docker::API::Secret` methods:
9
+ * create
10
+ * update
11
+ * list
12
+ * details
13
+ * delete
14
+
15
+ Add `Docker::API::Config` methods:
16
+ * create
17
+ * update
18
+ * list
19
+ * details
20
+ * delete
21
+
22
+ Add `Docker::API::Image` methods:
23
+ * distribution
24
+
25
+ # 0.10.0
26
+
27
+ Add `Docker::API::Service` methods:
28
+ * create
29
+ * update
30
+ * list
31
+ * details
32
+ * logs
33
+ * delete
34
+
35
+ # 0.9.0
36
+
37
+ Significant change: `#inspect` is now deprecated and replaced by `#details` in the following classes:
38
+ * `Docker::API::Container`
39
+ * `Docker::API::Image`
40
+ * `Docker::API::Network`
41
+ * `Docker::API::Volume`
42
+ * `Docker::API::Exec`
43
+ * `Docker::API::Swarm`
44
+ * `Docker::API::Node`
45
+
46
+ The method will be removed in the refactoring phase.
47
+
48
+ # 0.8.1
49
+
50
+ Restore the default `#inspect` output for `Docker::API` classes.
51
+
52
+ Most of the overriding methods take an argument, therefore calling using the expect arguments will return a `Docker::API::Response` object, while calling without arguments will return `Kernel#inspect`. To avoid this confusing schema, next release will rename `#inspect` within `Docker::API` to something else.
53
+
54
+ # 0.8.0
55
+
56
+ Add `Docker::API::Swarm` methods:
57
+ * init
58
+ * update
59
+ * ~~inspect~~ details
60
+ * unlock_key
61
+ * unlock
62
+ * join
63
+ * leave
64
+
65
+ Add `Docker::API::Node` methods:
66
+ * list
67
+ * ~~inspect~~ details
68
+ * update
69
+ * delete
70
+
71
+ Query parameters and request body json can now skip the validation step with `:skip_validation => true` option.
72
+
1
73
  # 0.7.0
2
74
 
3
- Major changes: Docker::API::Connection is now a regular class intead of a Singleton, allowing multiple connections to be stablished within the same program (replacing the connect_to implementation). To leverage this feature, API-related classes must be initialized and may or may not receive a Docker::API::Connection as parameter, or it'll connect to /var/run/docker.sock by default. For this reason, class methods were replaced with instance methods. Documentation will reflect this changes of implementation.
75
+ Significant changes: `Docker::API::Connection` is now a regular class intead of a Singleton, allowing multiple connections to be stablished within the same program (replacing the connect_to implementation). To leverage this feature, API-related classes must be initialized and may or may not receive a `Docker::API::Connection` as parameter, or it'll connect to `/var/run/docker.sock` by default. For this reason, class methods were replaced with instance methods. Documentation will reflect this changes of implementation.
4
76
 
5
77
  Bug fix: Image push returns a 20X status even when the push is unsucessful. To prevent false positives, it now requires the authentication parameters to be provided, generating a 403 status for invalid credentials or an error if they are absent.
6
78
 
@@ -8,15 +80,15 @@ Bug fix: Image push returns a 20X status even when the push is unsucessful. To p
8
80
 
9
81
  Add connection parameters specifications with connect_to in Docker::API::Connection.
10
82
 
11
- Add Docker::API::Exec methods:
83
+ Add `Docker::API::Exec` methods:
12
84
  * create
13
85
  * start
14
86
  * resize
15
- * inspect
87
+ * ~~inspect~~ details
16
88
 
17
89
  # 0.5.0
18
90
 
19
- Add Docker::API::System methods:
91
+ Add `Docker::API::System` methods:
20
92
  * auth
21
93
  * ping
22
94
  * info
@@ -24,7 +96,7 @@ Add Docker::API::System methods:
24
96
  * events
25
97
  * df
26
98
 
27
- Add new response class Docker::API::Response with the following methods:
99
+ Add new response class `Docker::API::Response` with the following methods:
28
100
  * json
29
101
  * path
30
102
  * success?
@@ -33,9 +105,9 @@ Error classes output better error messages.
33
105
 
34
106
  # 0.4.0
35
107
 
36
- Add Docker::API::Network methods:
108
+ Add `Docker::API::Network` methods:
37
109
  * list
38
- * inspect
110
+ * ~~inspect~~ details
39
111
  * create
40
112
  * remove
41
113
  * prune
@@ -44,9 +116,9 @@ Add Docker::API::Network methods:
44
116
 
45
117
  # 0.3.0
46
118
 
47
- Add Docker::API::Volume methods:
119
+ Add `Docker::API::Volume` methods:
48
120
  * list
49
- * inspect
121
+ * ~~inspect~~ details
50
122
  * create
51
123
  * remove
52
124
  * prune
@@ -54,8 +126,8 @@ Add Docker::API::Volume methods:
54
126
 
55
127
  # 0.2.0
56
128
 
57
- Add Docker::API::Image methods:
58
- * inspect
129
+ Add `Docker::API::Image` methods:
130
+ * ~~inspect~~ details
59
131
  * history
60
132
  * list
61
133
  * search
@@ -70,13 +142,13 @@ Add Docker::API::Image methods:
70
142
  * build
71
143
  * delete_cache
72
144
 
73
- Add Docker::API::System.auth (untested) for basic authentication
145
+ Add `Docker::API::System.auth` (untested) for basic authentication
74
146
 
75
147
  # 0.1.0
76
148
 
77
- Add Docker::API::Container methods:
149
+ Add `Docker::API::Container` methods:
78
150
  * list
79
- * inspect
151
+ * ~~inspect~~ details
80
152
  * top
81
153
  * changes
82
154
  * start
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dockerapi (0.7.0)
4
+ dockerapi (0.11.0)
5
5
  excon (~> 0.74.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -20,8 +20,6 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- New implementation details as of v0.7.0.
24
-
25
23
  ### Images
26
24
 
27
25
  ```ruby
@@ -44,7 +42,10 @@ image.create( fromSrc: "https://url.to/file.tar", repo: "repo:tag" )
44
42
  image.list
45
43
 
46
44
  # Inspect image
47
- image.inspect("image")
45
+ image.details("image")
46
+
47
+ # Return image digest and platform information by contacting the registry.
48
+ image.distribution("image")
48
49
 
49
50
  # History
50
51
  image.history("image")
@@ -125,7 +126,7 @@ container.list
125
126
  container.list(all: true)
126
127
 
127
128
  # Inspect container
128
- container.inspect("nginx")
129
+ container.details("nginx")
129
130
 
130
131
  # View container's processes
131
132
  container.top("nginx")
@@ -136,7 +137,7 @@ container.top("nginx").json
136
137
  # View filesystem changes
137
138
  container.changes("nginx")
138
139
 
139
- # View filesystem logs
140
+ # View container logs
140
141
  container.logs("nginx", stdout: true)
141
142
  container.logs("nginx", stdout: true, follow: true)
142
143
 
@@ -172,7 +173,7 @@ volume.create( Name:"my-volume" )
172
173
  volume.list
173
174
 
174
175
  # Inspect volume
175
- volume.inspect("my-volume")
176
+ volume.details("my-volume")
176
177
 
177
178
  # Remove volume
178
179
  volume.remove("my-volume")
@@ -191,7 +192,7 @@ network = Docker::API::Network.new
191
192
  network.list
192
193
 
193
194
  # Inspect network
194
- network.inspect("bridge")
195
+ network.details("bridge")
195
196
 
196
197
  # Create network
197
198
  network.create( Name:"my-network" )
@@ -246,7 +247,148 @@ response = exe.start(id)
246
247
  print response.data[:stream]
247
248
 
248
249
  # Inspect exec instance
249
- exe.inspect(id)
250
+ exe.details(id)
251
+ ```
252
+
253
+ ### Swarm
254
+ ```ruby
255
+ # Connect to local swarm endpoints
256
+ swarm = Docker::API::Swarm.new
257
+
258
+ # Init swarm
259
+ swarm.init({AdvertiseAddr: "local-ip-address:2377", ListenAddr: "0.0.0.0:4567"})
260
+
261
+ # Inspect swarm
262
+ swarm.details
263
+
264
+ # Update swarm
265
+ swarm.update(version, {rotateWorkerToken: true})
266
+ swarm.update(version, {rotateManagerToken: true})
267
+ swarm.update(version, {rotateManagerUnlockKey: true})
268
+ swarm.update(version, {EncryptionConfig: { AutoLockManagers: true }})
269
+
270
+ # Get unlock key
271
+ swarm.unlock_key
272
+
273
+ # Unlock swarm
274
+ swarm.unlock(UnlockKey: "key-value")
275
+
276
+ # Join an existing swarm
277
+ swarm.join(RemoteAddrs: ["remote-manager-address:2377"], JoinToken: "Join-Token-Here")
278
+
279
+ # Leave a swarm
280
+ swarm.leave(force: true)
281
+ ```
282
+
283
+ ### Node
284
+ ```ruby
285
+ # Connect to local node endpoints
286
+ node = Docker::API::Node.new
287
+
288
+ # List nodes
289
+ node.list
290
+
291
+ # Inspect node
292
+ node.details("node-id")
293
+
294
+ # Update node (version, Role and Availability must be present)
295
+ node.update("node-id", {version: "version"}, {Role: "worker", Availability: "pause" })
296
+ node.update("node-id", {version: "version"}, {Role: "worker", Availability: "active" })
297
+ node.update("node-id", {version: "version"}, {Role: "manager", Availability: "active" })
298
+
299
+ # Delete node
300
+ node.delete("node-id")
301
+ ```
302
+
303
+ ### Service
304
+ ```ruby
305
+ # Connect to local service endpoints
306
+ service = Docker::API::Service.new
307
+
308
+ # List services
309
+ service.list
310
+
311
+ # Create a service
312
+ service.create({Name: "nginx-service",
313
+ TaskTemplate: {ContainerSpec: { Image: "nginx:alpine" }},
314
+ Mode: { Replicated: { Replicas: 2 } },
315
+ EndpointSpec: { Ports: [ {Protocol: "tcp", PublishedPort: 80, TargetPort: 80} ] }
316
+ })
317
+
318
+ # Update a service (needs version and current Spec)
319
+ version = service.details( service ).json["Version"]["Index"]
320
+ spec = service.details(service).json["Spec"]
321
+ service.update("nginx-service", {version: version}, spec.merge!({ Mode: { Replicated: { Replicas: 1 } } }))
322
+
323
+ # View service logs
324
+ service.logs("nginx-service", stdout: true)
325
+
326
+ # Inspect service
327
+ service.details("nginx-service")
328
+
329
+ # Delete service
330
+ service.delete("nginx-service")
331
+ ```
332
+
333
+ ### Task
334
+ ```ruby
335
+ # Connect to local task endpoints
336
+ task = Docker::API::Task.new
337
+
338
+ # List tasks
339
+ task.list
340
+
341
+ # View task logs
342
+ task.logs("task-id", stdout: true)
343
+
344
+ # Inspect service
345
+ task.details("task-id")
346
+ ```
347
+
348
+ ### Secret
349
+ ```ruby
350
+ # Connect to local secret endpoints
351
+ secret = Docker::API::Secret.new
352
+
353
+ # List secrets
354
+ secret.list
355
+
356
+ # Create a secret
357
+ secret.create({Name: "secret-name", Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg=="})
358
+
359
+ # Inspect secrets
360
+ secret.details("secret-name")
361
+
362
+ # Update a secret (needs version and current Spec)
363
+ version = secret.details( "secret-name" ).json["Version"]["Index"]
364
+ spec = secret.details("secret-name").json["Spec"]
365
+ secret.update("secret-name", {version: version}, spec.merge!({ Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg==" }))
366
+
367
+ # Delete secret
368
+ secret.delete("secret-name")
369
+ ```
370
+
371
+ ### Config
372
+ ```ruby
373
+ # Connect to local config endpoints
374
+ config = Docker::API::Config.new
375
+
376
+ # List configs
377
+ config.list
378
+
379
+ # Create a config
380
+ config.create({Name: "config-name", Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg=="})
381
+
382
+ # Inspect configs
383
+ config.details("config-name")
384
+
385
+ # Update a configs (needs version and current Spec)
386
+ version = config.details( "config-name" ).json["Version"]["Index"]
387
+ spec = config.details("config-name").json["Spec"]
388
+ config.update("config-name", {version: version}, spec.merge!({ Data: "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg==" }))
389
+
390
+ # Delete config
391
+ config.delete("config-name")
250
392
  ```
251
393
 
252
394
  ### Connection
@@ -311,6 +453,8 @@ response.success?
311
453
 
312
454
  `Docker::API::InvalidParameter` and `Docker::API::InvalidRequestBody` may be raised when an invalid option is passed as argument (ie: an option not described in Docker API documentation for request query parameters nor request body (json) parameters). Even if no errors were raised, consider validating the status code and/or message of the response to check if the Docker daemon has fulfilled the operation properly.
313
455
 
456
+ To completely skip the validation process, add `:skip_validation => true` in the hash to be validated.
457
+
314
458
  ## Development
315
459
 
316
460
  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.
@@ -319,28 +463,22 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
319
463
 
320
464
  ### Road to 1.0.0
321
465
 
322
- NS: Not Started
323
-
324
- WIP: Work In Progress
325
-
326
-
327
466
  | Class | Tests | Implementation | Refactoring |
328
467
  |---|---|---|---|
329
- | Container | Ok | Ok | NS |
330
- | Image | Ok | Ok | NS |
331
- | Volume | Ok | Ok | NS |
332
- | Network | Ok | Ok | NS |
333
- | System | Ok | Ok | NS |
334
- | Exec | Ok | Ok | NS |
335
- | Swarm | NS | NS | NS |
336
- | Node | NS | NS | NS |
337
- | Service | NS | NS | NS |
338
- | Task | NS | NS | NS |
339
- | Secret | NS | NS | NS |
340
-
341
- Misc:
342
- * ~~Improve response object~~
343
- * ~~Improve error objects~~
468
+ | Image | Ok | Ok | 8/7 |
469
+ | Container | Ok | Ok | 8/14 |
470
+ | Volume | Ok | Ok | 8/21 |
471
+ | Network | Ok | Ok | 8/21 |
472
+ | System | Ok | Ok | 8/21 |
473
+ | Exec | Ok | Ok | 8/21 |
474
+ | Swarm | Ok | Ok | 8/28 |
475
+ | Node | Ok | Ok | 8/28 |
476
+ | Service | Ok | Ok | 8/28 |
477
+ | Task | Ok | Ok | 9/4 |
478
+ | Secret | Ok | Ok | 9/4 |
479
+ | Config | Ok | Ok | 9/4 |
480
+ | Distribution | Ok | Ok | 9/4 |
481
+ | Plugin | 7/24 | 7/24 | 9/4 |
344
482
 
345
483
  ## Contributing
346
484
 
@@ -3,16 +3,18 @@ module Docker
3
3
  class Base
4
4
 
5
5
  def initialize connection = nil
6
+ raise Docker::API::Error.new("Expect connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection)
6
7
  @connection = connection || Docker::API::Connection.new
7
8
  end
8
9
 
9
10
  private
10
11
 
11
- def base_path
12
+ def base_path # TODO: this method to be removed?
12
13
  "/"
13
14
  end
14
15
 
15
16
  def validate error, permitted, params
17
+ return if params[:skip_validation]
16
18
  unpermitted = params.keys.map(&:to_s) - permitted.map(&:to_s)
17
19
  raise error.new(permitted, unpermitted) if unpermitted.size > 0
18
20
  end
@@ -22,12 +24,12 @@ module Docker
22
24
  ## If value is another Hash, it should keep a json syntax {key:value}
23
25
  def hash_to_params h
24
26
  p = []
25
- h.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
27
+ h.delete_if{ | k, v | k.to_s == "skip_validation" }.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
26
28
  p.join("&").gsub(" ","")
27
29
  end
28
30
 
29
31
  def build_path path, params = {}
30
- p = path.is_a?(Array) ? ([base_path] << path).join("/") : path
32
+ p = path.is_a?(Array) ? ([base_path] << path).join("/") : path # TODO: this line to be removed?
31
33
  params.size > 0 ? [p, hash_to_params(params)].join("?") : p
32
34
  end
33
35
 
@@ -0,0 +1,70 @@
1
+ # This class represents the Docker API endpoints regarding configs.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Config
4
+ #
5
+ # Configs are application configurations that can be used by services. Swarm mode must be enabled for these endpoints to work.
6
+ class Docker::API::Config < Docker::API::Base
7
+
8
+ # List configs
9
+ #
10
+ # Docker API: GET /configs
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ConfigList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ validate Docker::API::InvalidParameter, [:filters], params
17
+ @connection.get(build_path("/configs",params))
18
+ end
19
+
20
+ # Create a config
21
+ #
22
+ # Docker API: POST /configs/create
23
+ #
24
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ConfigCreate
25
+ #
26
+ # @param body [Hash]: Request body to be sent as json.
27
+ def create body = {}
28
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Templating], body
29
+ @connection.request(method: :post, path: "/configs/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
30
+ end
31
+
32
+ # Inspect a config
33
+ #
34
+ # Docker API: GET /configs/{id}
35
+ #
36
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ConfigInspect
37
+ #
38
+ # @param name [String]: The ID or name of the config.
39
+ def details name
40
+ @connection.get("/configs/#{name}")
41
+ end
42
+
43
+ # Update a config
44
+ #
45
+ # Docker API: POST /configs/{id}/update
46
+ #
47
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ConfigUpdate
48
+ #
49
+ # @param name [String]: The ID or name of the config.
50
+ #
51
+ # @param params [Hash]: Parameters that are appended to the URL.
52
+ #
53
+ # @param body [Hash]: Request body to be sent as json.
54
+ def update name, params = {}, body = {}
55
+ validate Docker::API::InvalidParameter, [:version], params
56
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Driver, :Templating], body
57
+ @connection.request(method: :post, path: build_path("/configs/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
58
+ end
59
+
60
+ # Delete a config
61
+ #
62
+ # Docker API: DELETE /configs/{id}
63
+ #
64
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ConfigDelete
65
+ #
66
+ # @param name [String]: The ID or name of the config.
67
+ def delete name
68
+ @connection.delete("/configs/#{name}")
69
+ end
70
+ end
@@ -5,16 +5,12 @@ module Docker
5
5
 
6
6
  class Container < Docker::API::Base
7
7
 
8
- def base_path
9
- "/containers"
10
- end
11
-
12
8
  def list params = {}
13
9
  validate Docker::API::InvalidParameter, [:all, :limit, :size, :filters], params
14
10
  @connection.get(build_path(["json"], params))
15
11
  end
16
12
 
17
- def inspect name, params = {}
13
+ def details name, params = {}
18
14
  validate Docker::API::InvalidParameter, [:size], params
19
15
  @connection.get(build_path([name, "json"], params))
20
16
  end
@@ -124,7 +120,7 @@ module Docker
124
120
  end
125
121
 
126
122
  def export name, path = "exported_container"
127
- response = self.inspect(name)
123
+ response = self.details(name)
128
124
  if response.status == 200
129
125
  file = File.open(File.expand_path(path), "wb")
130
126
  streamer = lambda do |chunk, remaining_bytes, total_bytes|
@@ -154,6 +150,21 @@ module Docker
154
150
  response
155
151
  end
156
152
 
153
+ #################################################
154
+ # Items in this area to be removed before 1.0.0 #
155
+ #################################################
156
+ def base_path
157
+ "/containers"
158
+ end
159
+
160
+ def inspect *args
161
+ return super.inspect if args.size == 0
162
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
163
+ name, params = args[0], args[1] || {}
164
+ details(name, params)
165
+ end
166
+ #################################################
167
+
157
168
  end
158
169
  end
159
170
  end
@@ -2,10 +2,6 @@ module Docker
2
2
  module API
3
3
  class Exec < Docker::API::Base
4
4
 
5
- def base_path
6
- "/exec"
7
- end
8
-
9
5
  def create name, body = {}
10
6
  validate Docker::API::InvalidRequestBody, [:AttachStdin, :AttachStdout, :AttachStderr, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir], body
11
7
  @connection.request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json )
@@ -27,12 +23,23 @@ module Docker
27
23
 
28
24
  def resize name, params = {}
29
25
  validate Docker::API::InvalidParameter, [:w, :h], params
30
- @connection.post(build_path([name, "resize"], params))
26
+ @connection.post(build_path("/exec/#{name}/resize", params))
31
27
  end
32
28
 
33
- def inspect name
34
- @connection.get(build_path([name, "json"]))
29
+ def details name
30
+ @connection.get("/exec/#{name}/json")
31
+ end
32
+
33
+ #################################################
34
+ # Items in this area to be removed before 1.0.0 #
35
+ #################################################
36
+ def inspect *args
37
+ return super.inspect if args.size == 0
38
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
39
+ name = args[0]
40
+ details(name)
35
41
  end
42
+ #################################################
36
43
 
37
44
  end
38
45
  end
@@ -7,12 +7,12 @@ module Docker
7
7
  BuildParams = [:dockerfile, :t, :extrahosts, :remote, :q, :nocache, :cachefrom, :pull, :rm, :forcerm, :memory, :memswap, :cpushares, :cpusetcpus, :cpuperiod, :cpuquota, :buildargs, :shmsize, :squash, :labels, :networkmode, :platform, :target, :outputs]
8
8
  class Image < Docker::API::Base
9
9
 
10
- def base_path
11
- "/images"
10
+ def details name
11
+ @connection.get(build_path([name, "json"]))
12
12
  end
13
13
 
14
- def inspect name
15
- @connection.get(build_path([name, "json"]))
14
+ def distribution name
15
+ @connection.get("/distribution/#{name}/json")
16
16
  end
17
17
 
18
18
  def history name
@@ -76,7 +76,7 @@ module Docker
76
76
  def commit params = {}, body = {}
77
77
  validate Docker::API::InvalidParameter, [:container, :repo, :tag, :comment, :author, :pause, :changes], params
78
78
  validate Docker::API::InvalidRequestBody, Docker::API::CommitBody, body
79
- container = Docker::API::Container.new.inspect(params[:container])
79
+ container = Docker::API::Container.new.details(params[:container])
80
80
  return container if [404, 301].include? container.status
81
81
  body = JSON.parse(container.body)["Config"].merge(body)
82
82
  @connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
@@ -132,7 +132,21 @@ module Docker
132
132
  @connection.post(build_path("/build/prune", params))
133
133
  end
134
134
 
135
- end
135
+ #################################################
136
+ # Items in this area to be removed before 1.0.0 #
137
+ #################################################
138
+ def base_path
139
+ "/images"
140
+ end
136
141
 
142
+ def inspect *args
143
+ return super.inspect if args.size == 0
144
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
145
+ name = args[0]
146
+ details(name)
147
+ end
148
+ #################################################
149
+
150
+ end
137
151
  end
138
152
  end
@@ -2,16 +2,12 @@ module Docker
2
2
  module API
3
3
  class Network < Docker::API::Base
4
4
 
5
- def base_path
6
- "/networks"
7
- end
8
-
9
5
  def list params = {}
10
6
  validate Docker::API::InvalidParameter, [:filters], params
11
7
  @connection.get(build_path("/networks", params))
12
8
  end
13
9
 
14
- def inspect name, params = {}
10
+ def details name, params = {}
15
11
  validate Docker::API::InvalidParameter, [:verbose, :scope], params
16
12
  @connection.get(build_path([name], params))
17
13
  end
@@ -40,6 +36,21 @@ module Docker
40
36
  @connection.request(method: :post, path: build_path([name, "disconnect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
41
37
  end
42
38
 
39
+ #################################################
40
+ # Items in this area to be removed before 1.0.0 #
41
+ #################################################
42
+ def base_path
43
+ "/networks"
44
+ end
45
+
46
+ def inspect *args
47
+ return super.inspect if args.size == 0
48
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
49
+ name, params = args[0], args[1] || {}
50
+ details(name, params)
51
+ end
52
+ #################################################
53
+
43
54
  end
44
55
  end
45
56
  end
@@ -0,0 +1,38 @@
1
+ module Docker
2
+ module API
3
+ class Node < Docker::API::Base
4
+
5
+ def list params = {}
6
+ validate Docker::API::InvalidParameter, [:filters], params
7
+ @connection.get(build_path("/nodes", params))
8
+ end
9
+
10
+ def update name, params = {}, body = {}
11
+ validate Docker::API::InvalidParameter, [:version], params
12
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Role, :Availability], body
13
+ @connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
+ end
15
+
16
+ def delete name, params = {}
17
+ validate Docker::API::InvalidParameter, [:force], params
18
+ @connection.delete(build_path("/nodes/#{name}", params))
19
+ end
20
+
21
+ def details name
22
+ @connection.get("/nodes/#{name}")
23
+ end
24
+
25
+ #################################################
26
+ # Items in this area to be removed before 1.0.0 #
27
+ #################################################
28
+ def inspect *args
29
+ return super.inspect if args.size == 0
30
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
31
+ name = args[0]
32
+ details(name)
33
+ end
34
+ #################################################
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,70 @@
1
+ # This class represents the Docker API endpoints regarding secrets.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
4
+ #
5
+ # Secrets are sensitive data that can be used by services. Swarm mode must be enabled for these endpoints to work.
6
+ class Docker::API::Secret < Docker::API::Base
7
+
8
+ # List secrets
9
+ #
10
+ # Docker API: GET /secrets
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ validate Docker::API::InvalidParameter, [:filters], params
17
+ @connection.get(build_path("/secrets",params))
18
+ end
19
+
20
+ # Create a secret
21
+ #
22
+ # Docker API: POST /secrets/create
23
+ #
24
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretCreate
25
+ #
26
+ # @param body [Hash]: Request body to be sent as json.
27
+ def create body = {}
28
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Driver, :Templating], body
29
+ @connection.request(method: :post, path: "/secrets/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
30
+ end
31
+
32
+ # Inspect a secret
33
+ #
34
+ # Docker API: GET /secrets/{id}
35
+ #
36
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretInspect
37
+ #
38
+ # @param name [String]: The ID or name of the secret.
39
+ def details name
40
+ @connection.get("/secrets/#{name}")
41
+ end
42
+
43
+ # Update a secret
44
+ #
45
+ # Docker API: POST /secrets/{id}/update
46
+ #
47
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretUpdate
48
+ #
49
+ # @param name [String]: The ID or name of the secret.
50
+ #
51
+ # @param params [Hash]: Parameters that are appended to the URL.
52
+ #
53
+ # @param body [Hash]: Request body to be sent as json.
54
+ def update name, params = {}, body = {}
55
+ validate Docker::API::InvalidParameter, [:version], params
56
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Data, :Driver, :Templating], body
57
+ @connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
58
+ end
59
+
60
+ # Delete a secret
61
+ #
62
+ # Docker API: DELETE /secrets/{id}
63
+ #
64
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/SecretDelete
65
+ #
66
+ # @param name [String]: The ID or name of the secret.
67
+ def delete name
68
+ @connection.delete("/secrets/#{name}")
69
+ end
70
+ end
@@ -0,0 +1,98 @@
1
+ # This class represents the Docker API endpoints regarding services.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Service
4
+ #
5
+ # Services are the definitions of tasks to run on a swarm. Swarm mode must be enabled for these endpoints to work.
6
+ class Docker::API::Service < Docker::API::Base
7
+
8
+ # List services
9
+ #
10
+ # Docker API: GET /services
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ validate Docker::API::InvalidParameter, [:filters], params
17
+ @connection.get(build_path("/services", params))
18
+ end
19
+
20
+ # Create a service
21
+ #
22
+ # Docker API: POST /services/create
23
+ #
24
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceCreate
25
+ #
26
+ # @param body [Hash]: Request body to be sent as json.
27
+ #
28
+ # @param authentication [Hash]: Authentication parameters.
29
+ def create body = {}, authentication = {}
30
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], body
31
+ headers = {"Content-Type": "application/json"}
32
+ headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
33
+ @connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
34
+ end
35
+
36
+ # Update a service
37
+ #
38
+ # Docker API: POST /services/{id}/update
39
+ #
40
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceUpdate
41
+ #
42
+ # @param name [String]: The ID or name of the service.
43
+ #
44
+ # @param params [Hash]: Parameters that are appended to the URL.
45
+ #
46
+ # @param body [Hash]: Request body to be sent as json.
47
+ #
48
+ # @param authentication [Hash]: Authentication parameters.
49
+ def update name, params = {}, body = {}, authentication = {}
50
+ # view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
51
+ validate Docker::API::InvalidParameter, [:version, :registryAuthFrom, :rollback], params
52
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :TaskTemplate, :Mode, :UpdateConfig, :RollbackConfig, :Networks, :EndpointSpec], body
53
+ headers = {"Content-Type": "application/json"}
54
+ headers.merge!({"X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s)}) if authentication.keys.size > 0
55
+ @connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
56
+ end
57
+
58
+ # Inspect a service
59
+ #
60
+ # Docker API: GET /services/{id}
61
+ #
62
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceInspect
63
+ #
64
+ # @param name [String]: The ID or name of the service.
65
+ #
66
+ # @param params [Hash]: Parameters that are appended to the URL.
67
+ def details name, params = {}
68
+ validate Docker::API::InvalidParameter, [:insertDefaults], params
69
+ @connection.get(build_path("/services/#{name}", params))
70
+ end
71
+
72
+ # Get stdout and stderr logs from a service.
73
+ #
74
+ # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
75
+ #
76
+ # Docker API: GET /services/{id}/logs
77
+ #
78
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceLogs
79
+ #
80
+ # @param name [String]: The ID or name of the service.
81
+ #
82
+ # @param params [Hash]: Parameters that are appended to the URL.
83
+ def logs name, params = {}
84
+ validate Docker::API::InvalidParameter, [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail], params
85
+ @connection.get(build_path("/services/#{name}/logs", params))
86
+ end
87
+
88
+ # Delete a service
89
+ #
90
+ # Docker API: DELETE /services/{id}
91
+ #
92
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceDelete
93
+ #
94
+ # @param name [String]: The ID or name of the service.
95
+ def delete name
96
+ @connection.delete("/services/#{name}")
97
+ end
98
+ end
@@ -0,0 +1,51 @@
1
+ module Docker
2
+ module API
3
+ class Swarm < Docker::API::Base
4
+
5
+ def init body = {}
6
+ validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :DataPathPort, :DefaultAddrPool, :ForceNewCluster, :SubnetSize, :Spec], body
7
+ @connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type": "application/json"}, body: body.to_json)
8
+ end
9
+
10
+ def update params = {}, body = {}
11
+ validate Docker::API::InvalidParameter, [:version, :rotateWorkerToken, :rotateManagerToken, :rotateManagerUnlockKey], params
12
+ validate Docker::API::InvalidRequestBody, [:Name, :Labels, :Orchestration, :Raft, :Dispatcher, :CAConfig, :EncryptionConfig, :TaskDefaults], body
13
+ @connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
14
+ end
15
+
16
+ def details
17
+ @connection.get("/swarm")
18
+ end
19
+
20
+ def unlock_key
21
+ @connection.get(build_path("/swarm/unlockkey"))
22
+ end
23
+
24
+ def unlock body = {}
25
+ validate Docker::API::InvalidRequestBody, [:UnlockKey], body
26
+ @connection.request(method: :post, path: build_path("/swarm/unlock"), headers: {"Content-Type": "application/json"}, body: body.to_json)
27
+ end
28
+
29
+ def join body = {}
30
+ validate Docker::API::InvalidRequestBody, [:ListenAddr, :AdvertiseAddr, :DataPathAddr, :RemoteAddrs, :JoinToken], body
31
+ @connection.request(method: :post, path: build_path("/swarm/join"), headers: {"Content-Type": "application/json"}, body: body.to_json)
32
+ end
33
+
34
+ def leave params = {}
35
+ validate Docker::API::InvalidParameter, [:force], params
36
+ @connection.post(build_path("/swarm/leave", params))
37
+ end
38
+
39
+ #################################################
40
+ # Items in this area to be removed before 1.0.0 #
41
+ #################################################
42
+ def inspect
43
+ caller.each { | el | return super.inspect if el.match(/inspector/) }
44
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
45
+ details
46
+ end
47
+ #################################################
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,46 @@
1
+ # This class represents the Docker API endpoints regarding tasks.
2
+ #
3
+ # @see https://docs.docker.com/engine/api/v1.40/#tag/Task
4
+ #
5
+ # A task is a container running on a swarm. It is the atomic scheduling unit of swarm. Swarm mode must be enabled for these endpoints to work.
6
+ class Docker::API::Task < Docker::API::Base
7
+
8
+ # List tasks
9
+ #
10
+ # Docker API: GET /tasks
11
+ #
12
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskList
13
+ #
14
+ # @param params [Hash]: Parameters that are appended to the URL.
15
+ def list params = {}
16
+ validate Docker::API::InvalidParameter, [:filters], params
17
+ @connection.get(build_path("/tasks",params))
18
+ end
19
+
20
+ # Inspect a task
21
+ #
22
+ # Docker API: GET /tasks/{id}
23
+ #
24
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskInspect
25
+ #
26
+ # @param name [String]: The ID or name of the task.
27
+ def details name
28
+ @connection.get("/tasks/#{name}")
29
+ end
30
+
31
+ # Get stdout and stderr logs from a task.
32
+ #
33
+ # Note: This endpoint works only for services with the local, json-file or journald logging drivers.
34
+ #
35
+ # Docker API: GET /tasks/{id}/logs
36
+ #
37
+ # @see https://docs.docker.com/engine/api/v1.40/#operation/TaskLogs
38
+ #
39
+ # @param name (String) : The ID or name of the task.
40
+ #
41
+ # @param params (Hash) : Parameters that are appended to the URL.
42
+ def logs name, params = {}
43
+ validate Docker::API::InvalidParameter, [:details, :follow, :stdout, :stderr, :since, :timestamps, :tail], params
44
+ @connection.get(build_path("/tasks/#{name}/logs", params))
45
+ end
46
+ end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  module API
3
- GEM_VERSION = "0.7.0"
3
+ GEM_VERSION = "0.11.0"
4
4
 
5
5
  API_VERSION = "1.40"
6
6
 
@@ -1,24 +1,21 @@
1
1
  module Docker
2
2
  module API
3
3
  class Volume < Docker::API::Base
4
- def base_path
5
- "/volumes"
6
- end
7
4
 
8
5
  def list params = {}
9
6
  validate Docker::API::InvalidParameter, [:filters], params
10
7
  @connection.get(build_path("/volumes", params))
11
8
  end
12
9
 
10
+ def details name
11
+ @connection.get(build_path([name]))
12
+ end
13
+
13
14
  def create body = {}
14
15
  validate Docker::API::InvalidRequestBody, [:Name, :Driver, :DriverOpts, :Labels], body
15
16
  @connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
16
17
  end
17
18
 
18
- def inspect name
19
- @connection.get(build_path([name]))
20
- end
21
-
22
19
  def remove name, params = {}
23
20
  validate Docker::API::InvalidParameter, [:force], params
24
21
  @connection.delete(build_path([name]))
@@ -29,6 +26,21 @@ module Docker
29
26
  @connection.post(build_path(["prune"], params))
30
27
  end
31
28
 
29
+ #################################################
30
+ # Items in this area to be removed before 1.0.0 #
31
+ #################################################
32
+ def base_path
33
+ "/volumes"
34
+ end
35
+
36
+ def inspect *args
37
+ return super.inspect if args.size == 0
38
+ warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
39
+ name = args[0]
40
+ @connection.get(build_path([name]))
41
+ end
42
+ #################################################
43
+
32
44
  end
33
45
  end
34
46
  end
@@ -12,6 +12,12 @@ require "docker/api/volume"
12
12
  require "docker/api/network"
13
13
  require "docker/api/exec"
14
14
  require "docker/api/system"
15
+ require "docker/api/swarm"
16
+ require "docker/api/node"
17
+ require "docker/api/service"
18
+ require "docker/api/task"
19
+ require "docker/api/secret"
20
+ require "docker/api/config"
15
21
 
16
22
  module Docker
17
23
  module API
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.7.0
4
+ version: 0.11.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-07-05 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -44,14 +44,20 @@ files:
44
44
  - bin/setup
45
45
  - dockerapi.gemspec
46
46
  - lib/docker/api/base.rb
47
+ - lib/docker/api/config.rb
47
48
  - lib/docker/api/connection.rb
48
49
  - lib/docker/api/container.rb
49
50
  - lib/docker/api/error.rb
50
51
  - lib/docker/api/exec.rb
51
52
  - lib/docker/api/image.rb
52
53
  - lib/docker/api/network.rb
54
+ - lib/docker/api/node.rb
53
55
  - lib/docker/api/response.rb
56
+ - lib/docker/api/secret.rb
57
+ - lib/docker/api/service.rb
58
+ - lib/docker/api/swarm.rb
54
59
  - lib/docker/api/system.rb
60
+ - lib/docker/api/task.rb
55
61
  - lib/docker/api/version.rb
56
62
  - lib/docker/api/volume.rb
57
63
  - lib/dockerapi.rb