dockerapi 0.3.0 → 0.8.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: 75cce9b4918cafd3470d083b64922e43885c6e6e438ef8fd4eb4058944986781
4
- data.tar.gz: 76bff03e4603b101af6b968271778d9c0dbec86c512373fd45f1e538efdae3a4
3
+ metadata.gz: 4e010cc4d2a5c4aa102ffe7cd9d58e7e4823bf4ba9079f9a622cb021dad8cd0e
4
+ data.tar.gz: 47163ffb19a35b4a473da7f88f40d5eac418a15638ccc8d91b6b1672a1af09f6
5
5
  SHA512:
6
- metadata.gz: c5966f40e08494459b9d727d21f2b9600cc1945d31b1229a9b7d4305d98edf332092a238b5b649d9cfedf6cf56e9e3664ebeb3c7674145fea826c9758b5eb61f
7
- data.tar.gz: a6800709a10f44eac1e2cdb4001b11b7b6f5630b7af75cccd47db57ba33b48af45509593b2eaa340b06c4f35423581c47d4e646eee4503ef6b6d70bee1e847e0
6
+ metadata.gz: b48b06f99c46c936d4458a1908c08fe13f862ce7c63394077f52d8b621b2eb9e0be959682227f9b7ba59946f18b9098f2983a4bf1a781d16218ad66b08c730a3
7
+ data.tar.gz: ee2cb40d653054ea9bb559b9d39f43dd28556dcc25374033904f5c292403e371176ce1233636209bd5678df06f90436f6214aaafadd255d0b438cc870c318591
@@ -1,6 +1,69 @@
1
+ # 0.8.0
2
+
3
+ Add Docker::API::Swarm methods:
4
+ * init
5
+ * update
6
+ * inspect
7
+ * unlock_key
8
+ * unlock
9
+ * join
10
+ * leave
11
+
12
+ Add Docker::API::Node methods:
13
+ * list
14
+ * inspect
15
+ * update
16
+ * delete
17
+
18
+ Query parameters and request body json can now skip the validation step with `:skip_validation => true` option.
19
+
20
+ # 0.7.0
21
+
22
+ 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.
23
+
24
+ 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.
25
+
26
+ # 0.6.0
27
+
28
+ Add connection parameters specifications with connect_to in Docker::API::Connection.
29
+
30
+ Add Docker::API::Exec methods:
31
+ * create
32
+ * start
33
+ * resize
34
+ * inspect
35
+
36
+ # 0.5.0
37
+
38
+ Add Docker::API::System methods:
39
+ * auth
40
+ * ping
41
+ * info
42
+ * version
43
+ * events
44
+ * df
45
+
46
+ Add new response class Docker::API::Response with the following methods:
47
+ * json
48
+ * path
49
+ * success?
50
+
51
+ Error classes output better error messages.
52
+
53
+ # 0.4.0
54
+
55
+ Add Docker::API::Network methods:
56
+ * list
57
+ * inspect
58
+ * create
59
+ * remove
60
+ * prune
61
+ * connect
62
+ * disconnect
63
+
1
64
  # 0.3.0
2
65
 
3
- Add Docker::API::Image methods:
66
+ Add Docker::API::Volume methods:
4
67
  * list
5
68
  * inspect
6
69
  * create
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dockerapi (0.3.0)
4
+ dockerapi (0.8.0)
5
5
  excon (~> 0.74.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -20,72 +20,76 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ New implementation details as of v0.7.0.
24
+
23
25
  ### Images
24
26
 
25
27
  ```ruby
28
+ # Connect to local image endpoints
29
+ image = Docker::API::Image.new
30
+
26
31
  # Pull from a public repository
27
- Docker::API::Image.create( fromImage: "nginx:latest" )
32
+ image.create( fromImage: "nginx:latest" )
28
33
 
29
34
  # Pull from a private repository
30
- Docker::API::Image.create( {fromImage: "private/repo:tag"}, {username: "janedoe", password: "password"} )
35
+ image.create( {fromImage: "private/repo:tag"}, {username: "janedoe", password: "password"} )
31
36
 
32
37
  # Create image from local tar file
33
- Docker::API::Image.create( fromSrc: "/path/to/file.tar", repo: "repo:tag" )
38
+ image.create( fromSrc: "/path/to/file.tar", repo: "repo:tag" )
34
39
 
35
40
  # Create image from remote tar file
36
- Docker::API::Image.create( fromSrc: "https://url.to/file.tar", repo: "repo:tag" )
41
+ image.create( fromSrc: "https://url.to/file.tar", repo: "repo:tag" )
37
42
 
38
43
  # List images
39
- Docker::API::Image.list
40
- Docker::API::Image.list( all:true )
44
+ image.list
41
45
 
42
46
  # Inspect image
43
- Docker::API::Image.inspect("image")
47
+ image.inspect("image")
44
48
 
45
49
  # History
46
- Docker::API::Image.history("image")
50
+ image.history("image")
47
51
 
48
52
  # Search image
49
- Docker::API::Image.search(term: "busybox", limit: 2)
50
- Docker::API::Image.search(term: "busybox", filters: {"is-automated": {"true": true}})
51
- Docker::API::Image.search(term: "busybox", filters: {"is-official": {"true": true}})
53
+ image.search(term: "busybox", limit: 2)
54
+ image.search(term: "busybox", filters: {"is-automated": {"true": true}})
55
+ image.search(term: "busybox", filters: {"is-official": {"true": true}})
52
56
 
53
57
  # Tag image
54
- Docker::API::Image.tag("current:tag", repo: "new:tag") # or
55
- Docker::API::Image.tag("current:tag", repo: "new", tag: "tag")
58
+ image.tag("current:tag", repo: "new:tag") # or
59
+ image.tag("current:tag", repo: "new", tag: "tag")
56
60
 
57
61
  # Push image
58
- Docker::API::Image.push("repo:tag") # to dockerhub
59
- Docker::API::Image.push("localhost:5000/repo:tag") # to local registry
60
- Docker::API::Image.push("private/repo", {tag: "tag"}, {username: "janedoe", password: "password"} # to private repository
62
+ image.push("repo:tag") # to dockerhub
63
+ image.push("localhost:5000/repo:tag") # to local registry
64
+ image.push("private/repo", {tag: "tag"}, {username: "janedoe", password: "password"} # to private repository
61
65
 
62
- # Remove container
63
- Docker::API::Image.remove("image")
64
- Docker::API::Image.remove("image", force: true)
66
+ # Remove image
67
+ image.remove("image")
68
+ image.remove("image", force: true)
65
69
 
66
70
  # Remove unsued images (prune)
67
- Docker::API::Image.prune(filters: {dangling: {"false": true}})
71
+ image.prune(filters: {dangling: {"false": true}})
68
72
 
69
73
  # Create image from a container (commit)
70
- Docker::API::Image.commit(container: container, repo: "my/image", tag: "latest", comment: "Comment from commit", author: "dockerapi", pause: false )
74
+ image.commit(container: container, repo: "my/image", tag: "latest", comment: "Comment from commit", author: "dockerapi", pause: false )
71
75
 
72
76
  # Build image from a local tar file
73
- Docker::API::Image.build("/path/to/file.tar")
77
+ image.build("/path/to/file.tar")
74
78
 
75
79
  # Build image from a remote tar file
76
- Docker::API::Image.build(nil, remote: "https://url.to/file.tar")
80
+ image.build(nil, remote: "https://url.to/file.tar")
77
81
 
78
82
  # Build image from a remote Dockerfile
79
- Docker::API::Image.build(nil, remote: "https://url.to/Dockerfile")
83
+ image.build(nil, remote: "https://url.to/Dockerfile")
80
84
 
81
85
  # Delete builder cache
82
- Docker::API::Image.delete_cache
86
+ image.delete_cache
83
87
 
84
88
  # Export repo
85
- Docker::API::Image.export("repo:tag", "~/exported_image.tar")
89
+ image.export("repo:tag", "~/exported_image.tar")
86
90
 
87
91
  # Import repo
88
- Docker::API::Image.import("/path/to/file.tar")
92
+ image.import("/path/to/file.tar")
89
93
  ```
90
94
 
91
95
  ### Containers
@@ -94,82 +98,227 @@ Let's test a Nginx container
94
98
 
95
99
  ```ruby
96
100
  # Pull nginx image
97
- Docker::API::Image.create( fromImage: "nginx:latest" )
101
+ Docker::API::Image.new.create( fromImage: "nginx:latest" )
102
+
103
+ # Connect to local container endpoints
104
+ container = Docker::API::Container.new
98
105
 
99
106
  # Create container
100
- Docker::API::Container.create( {name: "nginx"}, {Image: "nginx:latest", HostConfig: {PortBindings: {"80/tcp": [ {HostIp: "0.0.0.0", HostPort: "80"} ]}}})
107
+ container.create( {name: "nginx"}, {Image: "nginx:latest", HostConfig: {PortBindings: {"80/tcp": [ {HostIp: "0.0.0.0", HostPort: "80"} ]}}})
101
108
 
102
109
  # Start container
103
- Docker::API::Container.start("nginx")
110
+ container.start("nginx")
104
111
 
105
112
  # Open localhost or machine IP to check the container running
106
113
 
107
114
  # Restart container
108
- Docker::API::Container.restart("nginx")
115
+ container.restart("nginx")
109
116
 
110
117
  # Pause/unpause container
111
- Docker::API::Container.pause("nginx")
112
- Docker::API::Container.unpause("nginx")
118
+ container.pause("nginx")
119
+ container.unpause("nginx")
113
120
 
114
121
  # List containers
115
- Docker::API::Container::list
122
+ container.list
116
123
 
117
124
  # List containers (including stopped ones)
118
- Docker::API::Container::list(all: true)
125
+ container.list(all: true)
119
126
 
120
127
  # Inspect container
121
- Docker::API::Container.inspect("nginx")
128
+ container.inspect("nginx")
122
129
 
123
130
  # View container's processes
124
- Docker::API::Container.top("nginx")
131
+ container.top("nginx")
125
132
 
126
- # Let's enhance the output
127
- JSON.parse(Docker::API::Container.top("nginx").body)
133
+ # Using json output
134
+ container.top("nginx").json
128
135
 
129
136
  # View filesystem changes
130
- Docker::API::Container.changes("nginx")
137
+ container.changes("nginx")
131
138
 
132
139
  # View filesystem logs
133
- Docker::API::Container.logs("nginx", stdout: true)
134
- Docker::API::Container.logs("nginx", stdout: true, follow: true)
140
+ container.logs("nginx", stdout: true)
141
+ container.logs("nginx", stdout: true, follow: true)
135
142
 
136
143
  # View filesystem stats
137
- Docker::API::Container.stats("nginx", stream: true)
144
+ container.stats("nginx", stream: true)
138
145
 
139
146
  # Export container
140
- Docker::API::Container.export("nginx", "~/exported_container")
147
+ container.export("nginx", "~/exported_container")
141
148
 
142
149
  # Get files from container
143
- Docker::API::Container.archive("nginx", "~/html.tar", path: "/usr/share/nginx/html/")
150
+ container.archive("nginx", "~/html.tar", path: "/usr/share/nginx/html/")
144
151
 
145
152
  # Stop container
146
- Docker::API::Container.stop("nginx")
153
+ container.stop("nginx")
147
154
 
148
155
  # Remove container
149
- Docker::API::Container.remove("nginx")
156
+ container.remove("nginx")
150
157
 
151
158
  # Remove stopped containers (prune)
152
- Docker::API::Container.prune
159
+ container.prune
153
160
  ```
154
161
 
155
162
  ### Volumes
156
163
 
157
164
  ```ruby
165
+ # Connect to local volume endpoints
166
+ volume = Docker::API::Volume.new
167
+
158
168
  # Create volume
159
- Docker::API::Volume.create Name:"my-volume"
169
+ volume.create( Name:"my-volume" )
160
170
 
161
171
  # List volumes
162
- Docker::API::Volume.list
172
+ volume.list
163
173
 
164
174
  # Inspect volume
165
- Docker::API::Volume.inspect "my-volume"
175
+ volume.inspect("my-volume")
166
176
 
167
177
  # Remove volume
168
- Docker::API::Volume.remove "my-volume"
178
+ volume.remove("my-volume")
169
179
 
170
180
  # Remove unused volumes (prune)
171
- Docker::API::Volume.prune
181
+ volume.prune
182
+ ```
183
+
184
+ ### Network
185
+
186
+ ```ruby
187
+ # Connect to local network endpoints
188
+ network = Docker::API::Network.new
189
+
190
+ # List networks
191
+ network.list
172
192
 
193
+ # Inspect network
194
+ network.inspect("bridge")
195
+
196
+ # Create network
197
+ network.create( Name:"my-network" )
198
+
199
+ # Remove network
200
+ network.remove("my-network")
201
+
202
+ # Remove unused network (prune)
203
+ network.prune
204
+
205
+ # Connect container to a network
206
+ network.connect( "my-network", Container: "my-container" )
207
+
208
+ # Disconnect container to a network
209
+ network.disconnect( "my-network", Container: "my-container" )
210
+ ```
211
+
212
+ ### System
213
+
214
+ ```ruby
215
+ # Connect to local system endpoints
216
+ sys = Docker::API::System.new
217
+
218
+ # Ping docker api
219
+ sys.ping
220
+
221
+ # Docker components versions
222
+ sys.version
223
+
224
+ # System info
225
+ sys.info
226
+
227
+ # System events (stream)
228
+ sys.events(until: Time.now.to_i)
229
+
230
+ # Data usage information
231
+ sys.df
232
+ ```
233
+
234
+ ### Exec
235
+
236
+ ```ruby
237
+ # Connect to local exec endpoints
238
+ exe = Docker::API::Exec.new
239
+
240
+ # Create exec instance, get generated exec ID
241
+ response = exe.create(container, AttachStdout:true, Cmd: ["ls", "-l"])
242
+ id = response.json["Id"]
243
+
244
+ # Execute the command, stream from Stdout is stored in response data
245
+ response = exe.start(id)
246
+ print response.data[:stream]
247
+
248
+ # Inspect exec instance
249
+ exe.inspect(id)
250
+ ```
251
+
252
+ ### Swarm
253
+ ```ruby
254
+ # Connect to local swarm endpoints
255
+ swarm = Docker::API::Swarm.new
256
+
257
+ # Init swarm
258
+ swarm.init({AdvertiseAddr: "local-ip-address:2377", ListenAddr: "0.0.0.0:4567"})
259
+
260
+ # Inspect swarm
261
+ swarm.inspect
262
+
263
+ # Update swarm
264
+ swarm.update(version, {rotateWorkerToken: true})
265
+ swarm.update(version, {rotateManagerToken: true})
266
+ swarm.update(version, {rotateManagerUnlockKey: true})
267
+ swarm.update(version, {EncryptionConfig: { AutoLockManagers: true }})
268
+
269
+ # Get unlock key
270
+ swarm.unlock_key
271
+
272
+ # Unlock swarm
273
+ swarm.unlock(UnlockKey: "key-value")
274
+
275
+ # Join an existing swarm
276
+ swarm.join(RemoteAddrs: ["remote-manager-address:2377"], JoinToken: "Join-Token-Here")
277
+
278
+ # Leave a swarm
279
+ swarm.leave(force: true)
280
+ ```
281
+
282
+ ### Node
283
+ ```ruby
284
+ # Connect to local node endpoints
285
+ node = Docker::API::Node.new
286
+
287
+ # List nodes
288
+ node.list
289
+
290
+ # Inspect node
291
+ node.inspect("node-id")
292
+
293
+ # Update node (version, Role and Availability must be present)
294
+ node.update("node-id", {version: "version"}, {Role: "worker", Availability: "pause" })
295
+ node.update("node-id", {version: "version"}, {Role: "worker", Availability: "active" })
296
+ node.update("node-id", {version: "version"}, {Role: "manager", Availability: "active" })
297
+
298
+ # Delete node
299
+ node.delete("node-id")
300
+ ```
301
+
302
+ ### Connection
303
+
304
+ By default Docker::API::Connection will connect to local Docker socket at `/var/run/docker.sock`. See examples below to use a different path or connect to a remote address.
305
+
306
+ ```ruby
307
+ # Setting different connections
308
+ local = Docker::API::Connection.new('unix:///', socket: "/path/to/docker.sock")
309
+ remote = Docker::API::Connection.new("http://127.0.0.1:2375") # change the IP address accordingly
310
+
311
+ # Using default /var/run/docker.sock
312
+ image_default = Docker::API::Image.new
313
+ image_default.list
314
+
315
+ # Using custom socket path
316
+ image_custom = Docker::API::Image.new(local)
317
+ image_custom.list
318
+
319
+ # Using remote address
320
+ image_remote = Docker::API::Image.new(remote)
321
+ image_remote.list
173
322
  ```
174
323
 
175
324
  ### Requests
@@ -178,7 +327,41 @@ Requests should work as described in [Docker API documentation](https://docs.doc
178
327
 
179
328
  ### Response
180
329
 
181
- All requests return a Excon::Response object.
330
+ All requests return a response class that inherits from Excon::Response. Available attribute readers and methods include: `status`, `data`, `body`, `headers`, `json`, `path`, `success?`.
331
+
332
+ ```ruby
333
+ response = Docker::API::Image.new.create(fromImage: "busybox:latest")
334
+
335
+ response
336
+ => #<Docker::API::Response:0x000055bb390b35c0 ... >
337
+
338
+ response.status
339
+ => 200
340
+
341
+ response.data
342
+ => {:body=>"...", :cookies=>[], :host=>nil, :headers=>{ ... }, :path=>"/images/create?fromImage=busybox:latest", :port=>nil, :status=>200, :status_line=>"HTTP/1.1 200 OK\r\n", :reason_phrase=>"OK"}
343
+
344
+ response.headers
345
+ => {"Api-Version"=>"1.40", "Content-Type"=>"application/json", "Docker-Experimental"=>"false", "Ostype"=>"linux", "Server"=>"Docker/19.03.11 (linux)", "Date"=>"Mon, 29 Jun 2020 16:10:06 GMT"}
346
+
347
+ response.body
348
+ => "{\"status\":\"Pulling from library/busybox\" ... "
349
+
350
+ response.json
351
+ => [{:status=>"Pulling from library/busybox", :id=>"latest"}, {:status=>"Pulling fs layer", :progressDetail=>{}, :id=>"76df9210b28c"}, ... , {:status=>"Status: Downloaded newer image for busybox:latest"}]
352
+
353
+ response.path
354
+ => "/images/create?fromImage=busybox:latest"
355
+
356
+ response.success?
357
+ => true
358
+ ```
359
+
360
+ ### Error handling
361
+
362
+ `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.
363
+
364
+ To completely skip the validation process, add `:skip_validation => true` in the hash to be validated.
182
365
 
183
366
  ## Development
184
367
 
@@ -188,28 +371,19 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
188
371
 
189
372
  ### Road to 1.0.0
190
373
 
191
- NS: Not Started
192
-
193
- WIP: Work In Progress
194
-
195
-
196
374
  | Class | Tests | Implementation | Refactoring |
197
375
  |---|---|---|---|
198
- | Container | Ok | Ok | NS |
199
- | Image | Ok | Ok | NS |
200
- | Volume | Ok | Ok | NS |
201
- | Network | NS | NS | NS |
202
- | System | NS | NS | NS |
203
- | Exec | NS | NS | NS |
204
- | Swarm | NS | NS | NS |
205
- | Node | NS | NS | NS |
206
- | Service | NS | NS | NS |
207
- | Task | NS | NS | NS |
208
- | Secret | NS | NS | NS |
209
-
210
- Misc:
211
- * Improve response object
212
- * Improve error objects
376
+ | Container | Ok | Ok | 7/24 |
377
+ | Image | Ok | Ok | 7/31 |
378
+ | Volume | Ok | Ok | 8/7 |
379
+ | Network | Ok | Ok | 8/7 |
380
+ | System | Ok | Ok | 8/7 |
381
+ | Exec | Ok | Ok | 8/7 |
382
+ | Swarm | Ok | Ok | 8/14 |
383
+ | Node | Ok | Ok | 8/14 |
384
+ | Service | 7/17 | 7/17 | 8/14 |
385
+ | Task | 7/17 | 7/17 | 8/14 |
386
+ | Secret | 7/17 | 7/17 | 8/14 |
213
387
 
214
388
  ## Contributing
215
389