dockerapi 0.6.0 → 0.7.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +109 -67
- data/lib/docker/api/base.rb +8 -8
- data/lib/docker/api/connection.rb +4 -14
- data/lib/docker/api/container.rb +50 -50
- data/lib/docker/api/exec.rb +9 -9
- data/lib/docker/api/image.rb +37 -39
- data/lib/docker/api/network.rb +15 -15
- data/lib/docker/api/system.rb +14 -13
- data/lib/docker/api/version.rb +1 -1
- data/lib/docker/api/volume.rb +11 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 756ada080034328ec7c5e7950d5565e6e7d3612bc92af58d9c8f89558a75f5c5
|
4
|
+
data.tar.gz: cba4ac000ef8e9d4374bc36be4e87dd3c2227b2fa59cc062f24ad7a06de11c52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c6c059fa47afc4749dac18c62d61a984c2874b41046c2926d7eb884a7761ea088fef4209deaf71fe5864e5351e8e96a975f29520760ae6559209d323dd4f4b6
|
7
|
+
data.tar.gz: 25bad2ed4c92a2b5551d78e3a12833037623e7f26045a829b587d4136c383d7431ae7a3d17bf6b9ca139c4fcc060cbf07f15a61854a4a43f601455613174f943
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.7.0
|
2
|
+
|
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.
|
4
|
+
|
5
|
+
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
|
+
|
1
7
|
# 0.6.0
|
2
8
|
|
3
9
|
Add connection parameters specifications with connect_to in Docker::API::Connection.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,71 +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
|
-
|
32
|
+
image.create( fromImage: "nginx:latest" )
|
28
33
|
|
29
34
|
# Pull from a private repository
|
30
|
-
|
35
|
+
image.create( {fromImage: "private/repo:tag"}, {username: "janedoe", password: "password"} )
|
31
36
|
|
32
37
|
# Create image from local tar file
|
33
|
-
|
38
|
+
image.create( fromSrc: "/path/to/file.tar", repo: "repo:tag" )
|
34
39
|
|
35
40
|
# Create image from remote tar file
|
36
|
-
|
41
|
+
image.create( fromSrc: "https://url.to/file.tar", repo: "repo:tag" )
|
37
42
|
|
38
43
|
# List images
|
39
|
-
|
44
|
+
image.list
|
40
45
|
|
41
46
|
# Inspect image
|
42
|
-
|
47
|
+
image.inspect("image")
|
43
48
|
|
44
49
|
# History
|
45
|
-
|
50
|
+
image.history("image")
|
46
51
|
|
47
52
|
# Search image
|
48
|
-
|
49
|
-
|
50
|
-
|
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}})
|
51
56
|
|
52
57
|
# Tag image
|
53
|
-
|
54
|
-
|
58
|
+
image.tag("current:tag", repo: "new:tag") # or
|
59
|
+
image.tag("current:tag", repo: "new", tag: "tag")
|
55
60
|
|
56
61
|
# Push image
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
60
65
|
|
61
66
|
# Remove image
|
62
|
-
|
63
|
-
|
67
|
+
image.remove("image")
|
68
|
+
image.remove("image", force: true)
|
64
69
|
|
65
70
|
# Remove unsued images (prune)
|
66
|
-
|
71
|
+
image.prune(filters: {dangling: {"false": true}})
|
67
72
|
|
68
73
|
# Create image from a container (commit)
|
69
|
-
|
74
|
+
image.commit(container: container, repo: "my/image", tag: "latest", comment: "Comment from commit", author: "dockerapi", pause: false )
|
70
75
|
|
71
76
|
# Build image from a local tar file
|
72
|
-
|
77
|
+
image.build("/path/to/file.tar")
|
73
78
|
|
74
79
|
# Build image from a remote tar file
|
75
|
-
|
80
|
+
image.build(nil, remote: "https://url.to/file.tar")
|
76
81
|
|
77
82
|
# Build image from a remote Dockerfile
|
78
|
-
|
83
|
+
image.build(nil, remote: "https://url.to/Dockerfile")
|
79
84
|
|
80
85
|
# Delete builder cache
|
81
|
-
|
86
|
+
image.delete_cache
|
82
87
|
|
83
88
|
# Export repo
|
84
|
-
|
89
|
+
image.export("repo:tag", "~/exported_image.tar")
|
85
90
|
|
86
91
|
# Import repo
|
87
|
-
|
92
|
+
image.import("/path/to/file.tar")
|
88
93
|
```
|
89
94
|
|
90
95
|
### Containers
|
@@ -93,140 +98,177 @@ Let's test a Nginx container
|
|
93
98
|
|
94
99
|
```ruby
|
95
100
|
# Pull nginx image
|
96
|
-
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
|
97
105
|
|
98
106
|
# Create container
|
99
|
-
|
107
|
+
container.create( {name: "nginx"}, {Image: "nginx:latest", HostConfig: {PortBindings: {"80/tcp": [ {HostIp: "0.0.0.0", HostPort: "80"} ]}}})
|
100
108
|
|
101
109
|
# Start container
|
102
|
-
|
110
|
+
container.start("nginx")
|
103
111
|
|
104
112
|
# Open localhost or machine IP to check the container running
|
105
113
|
|
106
114
|
# Restart container
|
107
|
-
|
115
|
+
container.restart("nginx")
|
108
116
|
|
109
117
|
# Pause/unpause container
|
110
|
-
|
111
|
-
|
118
|
+
container.pause("nginx")
|
119
|
+
container.unpause("nginx")
|
112
120
|
|
113
121
|
# List containers
|
114
|
-
|
122
|
+
container.list
|
115
123
|
|
116
124
|
# List containers (including stopped ones)
|
117
|
-
|
125
|
+
container.list(all: true)
|
118
126
|
|
119
127
|
# Inspect container
|
120
|
-
|
128
|
+
container.inspect("nginx")
|
121
129
|
|
122
130
|
# View container's processes
|
123
|
-
|
131
|
+
container.top("nginx")
|
124
132
|
|
125
|
-
#
|
126
|
-
|
133
|
+
# Using json output
|
134
|
+
container.top("nginx").json
|
127
135
|
|
128
136
|
# View filesystem changes
|
129
|
-
|
137
|
+
container.changes("nginx")
|
130
138
|
|
131
139
|
# View filesystem logs
|
132
|
-
|
133
|
-
|
140
|
+
container.logs("nginx", stdout: true)
|
141
|
+
container.logs("nginx", stdout: true, follow: true)
|
134
142
|
|
135
143
|
# View filesystem stats
|
136
|
-
|
144
|
+
container.stats("nginx", stream: true)
|
137
145
|
|
138
146
|
# Export container
|
139
|
-
|
147
|
+
container.export("nginx", "~/exported_container")
|
140
148
|
|
141
149
|
# Get files from container
|
142
|
-
|
150
|
+
container.archive("nginx", "~/html.tar", path: "/usr/share/nginx/html/")
|
143
151
|
|
144
152
|
# Stop container
|
145
|
-
|
153
|
+
container.stop("nginx")
|
146
154
|
|
147
155
|
# Remove container
|
148
|
-
|
156
|
+
container.remove("nginx")
|
149
157
|
|
150
158
|
# Remove stopped containers (prune)
|
151
|
-
|
159
|
+
container.prune
|
152
160
|
```
|
153
161
|
|
154
162
|
### Volumes
|
155
163
|
|
156
164
|
```ruby
|
165
|
+
# Connect to local volume endpoints
|
166
|
+
volume = Docker::API::Volume.new
|
167
|
+
|
157
168
|
# Create volume
|
158
|
-
|
169
|
+
volume.create( Name:"my-volume" )
|
159
170
|
|
160
171
|
# List volumes
|
161
|
-
|
172
|
+
volume.list
|
162
173
|
|
163
174
|
# Inspect volume
|
164
|
-
|
175
|
+
volume.inspect("my-volume")
|
165
176
|
|
166
177
|
# Remove volume
|
167
|
-
|
178
|
+
volume.remove("my-volume")
|
168
179
|
|
169
180
|
# Remove unused volumes (prune)
|
170
|
-
|
181
|
+
volume.prune
|
171
182
|
```
|
172
183
|
|
173
184
|
### Network
|
174
185
|
|
175
186
|
```ruby
|
187
|
+
# Connect to local network endpoints
|
188
|
+
network = Docker::API::Network.new
|
189
|
+
|
176
190
|
# List networks
|
177
|
-
|
191
|
+
network.list
|
178
192
|
|
179
193
|
# Inspect network
|
180
|
-
|
194
|
+
network.inspect("bridge")
|
181
195
|
|
182
196
|
# Create network
|
183
|
-
|
197
|
+
network.create( Name:"my-network" )
|
184
198
|
|
185
199
|
# Remove network
|
186
|
-
|
200
|
+
network.remove("my-network")
|
187
201
|
|
188
202
|
# Remove unused network (prune)
|
189
|
-
|
203
|
+
network.prune
|
190
204
|
|
191
205
|
# Connect container to a network
|
192
|
-
|
206
|
+
network.connect( "my-network", Container: "my-container" )
|
193
207
|
|
194
208
|
# Disconnect container to a network
|
195
|
-
|
209
|
+
network.disconnect( "my-network", Container: "my-container" )
|
196
210
|
```
|
197
211
|
|
198
212
|
### System
|
199
213
|
|
200
214
|
```ruby
|
215
|
+
# Connect to local system endpoints
|
216
|
+
sys = Docker::API::System.new
|
217
|
+
|
201
218
|
# Ping docker api
|
202
|
-
|
219
|
+
sys.ping
|
203
220
|
|
204
221
|
# Docker components versions
|
205
|
-
|
222
|
+
sys.version
|
206
223
|
|
207
224
|
# System info
|
208
|
-
|
225
|
+
sys.info
|
209
226
|
|
210
227
|
# System events (stream)
|
211
|
-
|
228
|
+
sys.events(until: Time.now.to_i)
|
212
229
|
|
213
230
|
# Data usage information
|
214
|
-
|
231
|
+
sys.df
|
215
232
|
```
|
216
233
|
|
217
234
|
### Exec
|
218
235
|
|
219
236
|
```ruby
|
237
|
+
# Connect to local exec endpoints
|
238
|
+
exe = Docker::API::Exec.new
|
239
|
+
|
220
240
|
# Create exec instance, get generated exec ID
|
221
|
-
response =
|
241
|
+
response = exe.create(container, AttachStdout:true, Cmd: ["ls", "-l"])
|
222
242
|
id = response.json["Id"]
|
223
243
|
|
224
244
|
# Execute the command, stream from Stdout is stored in response data
|
225
|
-
response =
|
245
|
+
response = exe.start(id)
|
226
246
|
print response.data[:stream]
|
227
247
|
|
228
248
|
# Inspect exec instance
|
229
|
-
|
249
|
+
exe.inspect(id)
|
250
|
+
```
|
251
|
+
|
252
|
+
### Connection
|
253
|
+
|
254
|
+
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.
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
# Setting different connections
|
258
|
+
local = Docker::API::Connection.new('unix:///', socket: "/path/to/docker.sock")
|
259
|
+
remote = Docker::API::Connection.new("http://127.0.0.1:2375") # change the IP address accordingly
|
260
|
+
|
261
|
+
# Using default /var/run/docker.sock
|
262
|
+
image_default = Docker::API::Image.new
|
263
|
+
image_default.list
|
264
|
+
|
265
|
+
# Using custom socket path
|
266
|
+
image_custom = Docker::API::Image.new(local)
|
267
|
+
image_custom.list
|
268
|
+
|
269
|
+
# Using remote address
|
270
|
+
image_remote = Docker::API::Image.new(remote)
|
271
|
+
image_remote.list
|
230
272
|
```
|
231
273
|
|
232
274
|
### Requests
|
@@ -238,7 +280,7 @@ Requests should work as described in [Docker API documentation](https://docs.doc
|
|
238
280
|
All requests return a response class that inherits from Excon::Response. Available attribute readers and methods include: `status`, `data`, `body`, `headers`, `json`, `path`, `success?`.
|
239
281
|
|
240
282
|
```ruby
|
241
|
-
response = Docker::API::Image.create(fromImage: "busybox:latest")
|
283
|
+
response = Docker::API::Image.new.create(fromImage: "busybox:latest")
|
242
284
|
|
243
285
|
response
|
244
286
|
=> #<Docker::API::Response:0x000055bb390b35c0 ... >
|
data/lib/docker/api/base.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module Docker
|
2
2
|
module API
|
3
3
|
class Base
|
4
|
+
|
5
|
+
def initialize connection = nil
|
6
|
+
@connection = connection || Docker::API::Connection.new
|
7
|
+
end
|
4
8
|
|
5
9
|
private
|
6
10
|
|
7
|
-
def
|
11
|
+
def base_path
|
8
12
|
"/"
|
9
13
|
end
|
10
14
|
|
11
|
-
def
|
12
|
-
Docker::API::Connection.instance
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.validate error, permitted, params
|
15
|
+
def validate error, permitted, params
|
16
16
|
unpermitted = params.keys.map(&:to_s) - permitted.map(&:to_s)
|
17
17
|
raise error.new(permitted, unpermitted) if unpermitted.size > 0
|
18
18
|
end
|
@@ -20,13 +20,13 @@ module Docker
|
|
20
20
|
## Converts Ruby Hash into query parameters
|
21
21
|
## In general, the format is key=value
|
22
22
|
## If value is another Hash, it should keep a json syntax {key:value}
|
23
|
-
def
|
23
|
+
def hash_to_params h
|
24
24
|
p = []
|
25
25
|
h.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
|
26
26
|
p.join("&").gsub(" ","")
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def build_path path, params = {}
|
30
30
|
p = path.is_a?(Array) ? ([base_path] << path).join("/") : path
|
31
31
|
params.size > 0 ? [p, hash_to_params(params)].join("?") : p
|
32
32
|
end
|
@@ -1,28 +1,18 @@
|
|
1
|
-
require "singleton"
|
2
1
|
module Docker
|
3
2
|
module API
|
4
3
|
class Connection
|
5
|
-
include Singleton
|
6
|
-
|
7
4
|
[:get, :post, :head, :delete, :put].each do | method |
|
8
5
|
define_method(method) { | path | self.request(method: method, path: path) }
|
9
6
|
end
|
10
7
|
|
11
|
-
def post(path, body = nil)
|
12
|
-
self.request(method: :post, path: path, headers: { "Content-Type" => "application/json" }, body: body.to_json)
|
13
|
-
end
|
14
|
-
|
15
8
|
def request params
|
16
9
|
Docker::API::Response.new(@connection.request(params).data)
|
17
10
|
end
|
18
|
-
|
19
|
-
def connect_to params
|
20
|
-
@connection = Excon.new(params)
|
21
|
-
end
|
22
11
|
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
def initialize url = nil, params = nil
|
13
|
+
url ||= 'unix:///'
|
14
|
+
params ||= url == 'unix:///' ? {socket: '/var/run/docker.sock'} : {}
|
15
|
+
@connection = Excon.new(url, params)
|
26
16
|
end
|
27
17
|
|
28
18
|
end
|
data/lib/docker/api/container.rb
CHANGED
@@ -5,111 +5,111 @@ module Docker
|
|
5
5
|
|
6
6
|
class Container < Docker::API::Base
|
7
7
|
|
8
|
-
def
|
8
|
+
def base_path
|
9
9
|
"/containers"
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def list params = {}
|
13
13
|
validate Docker::API::InvalidParameter, [:all, :limit, :size, :filters], params
|
14
|
-
connection.get(build_path(["json"], params))
|
14
|
+
@connection.get(build_path(["json"], params))
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def inspect name, params = {}
|
18
18
|
validate Docker::API::InvalidParameter, [:size], params
|
19
|
-
connection.get(build_path([name, "json"], params))
|
19
|
+
@connection.get(build_path([name, "json"], params))
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def top name, params = {}
|
23
23
|
validate Docker::API::InvalidParameter, [:ps_args], params
|
24
|
-
connection.get(build_path([name, "top"], params))
|
24
|
+
@connection.get(build_path([name, "top"], params))
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
connection.get(build_path([name, "changes"]))
|
27
|
+
def changes name
|
28
|
+
@connection.get(build_path([name, "changes"]))
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def start name, params = {}
|
32
32
|
validate Docker::API::InvalidParameter, [:detachKeys], params
|
33
|
-
connection.post(build_path([name, "start"], params))
|
33
|
+
@connection.post(build_path([name, "start"], params))
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def stop name, params = {}
|
37
37
|
validate Docker::API::InvalidParameter, [:t], params
|
38
|
-
connection.post(build_path([name, "stop"], params))
|
38
|
+
@connection.post(build_path([name, "stop"], params))
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def restart name, params = {}
|
42
42
|
validate Docker::API::InvalidParameter, [:t], params
|
43
|
-
connection.post(build_path([name, "restart"], params))
|
43
|
+
@connection.post(build_path([name, "restart"], params))
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def kill name, params = {}
|
47
47
|
validate Docker::API::InvalidParameter, [:signal], params
|
48
|
-
connection.post(build_path([name, "kill"], params))
|
48
|
+
@connection.post(build_path([name, "kill"], params))
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
51
|
+
def wait name, params = {}
|
52
52
|
validate Docker::API::InvalidParameter, [:condition], params
|
53
|
-
connection.post(build_path([name, "wait"], params))
|
53
|
+
@connection.post(build_path([name, "wait"], params))
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
56
|
+
def update name, body = {}
|
57
57
|
validate Docker::API::InvalidRequestBody, Docker::API::UpdateBody, body
|
58
|
-
connection.post
|
58
|
+
@connection.request(method: :post, path: build_path([name, "update"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
61
|
+
def rename name, params = {}
|
62
62
|
validate Docker::API::InvalidParameter, [:name], params
|
63
|
-
connection.post(build_path([name, "rename"], params))
|
63
|
+
@connection.post(build_path([name, "rename"], params))
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
66
|
+
def resize name, params = {}
|
67
67
|
validate Docker::API::InvalidParameter, [:w, :h], params
|
68
|
-
connection.post(build_path([name, "resize"], params))
|
68
|
+
@connection.post(build_path([name, "resize"], params))
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
71
|
+
def prune params = {}
|
72
72
|
validate Docker::API::InvalidParameter, [:filters], params
|
73
|
-
connection.post(build_path(["prune"], params))
|
73
|
+
@connection.post(build_path(["prune"], params))
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
connection.post(build_path([name, "pause"]))
|
76
|
+
def pause name
|
77
|
+
@connection.post(build_path([name, "pause"]))
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
connection.post(build_path([name, "unpause"]))
|
80
|
+
def unpause name
|
81
|
+
@connection.post(build_path([name, "unpause"]))
|
82
82
|
end
|
83
83
|
|
84
|
-
def
|
84
|
+
def remove name, params = {}
|
85
85
|
validate Docker::API::InvalidParameter, [:v, :force, :link], params
|
86
|
-
connection.delete(build_path([name]))
|
86
|
+
@connection.delete(build_path([name]))
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
89
|
+
def logs name, params = {}
|
90
90
|
validate Docker::API::InvalidParameter, [:follow, :stdout, :stderr, :since, :until, :timestamps, :tail], params
|
91
91
|
|
92
92
|
path = build_path([name, "logs"], params)
|
93
93
|
|
94
94
|
if params[:follow] == true || params[:follow] == 1
|
95
|
-
connection.request(method: :get, path: path , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
95
|
+
@connection.request(method: :get, path: path , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
96
96
|
else
|
97
|
-
connection.get(path)
|
97
|
+
@connection.get(path)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
def
|
101
|
+
def attach name, params = {}
|
102
102
|
validate Docker::API::InvalidParameter, [:detachKeys, :logs, :stream, :stdin, :stdout, :stderr], params
|
103
|
-
connection.request(method: :post, path: build_path([name, "attach"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
103
|
+
@connection.request(method: :post, path: build_path([name, "attach"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
104
104
|
end
|
105
105
|
|
106
|
-
def
|
106
|
+
def create params = {}, body = {}
|
107
107
|
validate Docker::API::InvalidParameter, [:name], params
|
108
108
|
validate Docker::API::InvalidRequestBody, Docker::API::CreateBody, body
|
109
|
-
connection.post
|
109
|
+
@connection.request(method: :post, path: build_path(["create"], params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
110
110
|
end
|
111
111
|
|
112
|
-
def
|
112
|
+
def stats name, params = {}
|
113
113
|
validate Docker::API::InvalidParameter, [:stream], params
|
114
114
|
path = build_path([name, "stats"], params)
|
115
115
|
|
@@ -117,37 +117,37 @@ module Docker
|
|
117
117
|
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
118
118
|
puts chunk
|
119
119
|
end
|
120
|
-
connection.request(method: :get, path: path , response_block: streamer)
|
120
|
+
@connection.request(method: :get, path: path , response_block: streamer)
|
121
121
|
else
|
122
|
-
connection.get(path)
|
122
|
+
@connection.get(path)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
def
|
127
|
-
response =
|
126
|
+
def export name, path = "exported_container"
|
127
|
+
response = self.inspect(name)
|
128
128
|
if response.status == 200
|
129
129
|
file = File.open(File.expand_path(path), "wb")
|
130
130
|
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
131
131
|
file.write(chunk)
|
132
132
|
end
|
133
|
-
response = connection.request(method: :get, path: build_path([name, "export"]) , response_block: streamer)
|
133
|
+
response = @connection.request(method: :get, path: build_path([name, "export"]) , response_block: streamer)
|
134
134
|
file.close
|
135
135
|
end
|
136
136
|
response
|
137
137
|
end
|
138
138
|
|
139
|
-
def
|
139
|
+
def archive name, file, params = {}
|
140
140
|
validate Docker::API::InvalidParameter, [:path, :noOverwriteDirNonDir, :copyUIDGID], params
|
141
141
|
|
142
142
|
begin # File exists on disk, send it to container
|
143
143
|
file = File.open( File.expand_path( file ) , "r")
|
144
|
-
response = connection.request(method: :put, path: build_path([name, "archive"], params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
144
|
+
response = @connection.request(method: :put, path: build_path([name, "archive"], params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
145
145
|
file.close
|
146
146
|
rescue Errno::ENOENT # File doesnt exist, get it from container
|
147
|
-
response = connection.head(build_path([name, "archive"], params))
|
147
|
+
response = @connection.head(build_path([name, "archive"], params))
|
148
148
|
if response.status == 200 # file exists in container
|
149
149
|
file = File.open( File.expand_path( file ) , "wb")
|
150
|
-
response = connection.request(method: :get, path: build_path([name, "archive"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
|
150
|
+
response = @connection.request(method: :get, path: build_path([name, "archive"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
|
151
151
|
file.close
|
152
152
|
end
|
153
153
|
end
|
data/lib/docker/api/exec.rb
CHANGED
@@ -2,20 +2,20 @@ module Docker
|
|
2
2
|
module API
|
3
3
|
class Exec < Docker::API::Base
|
4
4
|
|
5
|
-
def
|
5
|
+
def base_path
|
6
6
|
"/exec"
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def create name, body = {}
|
10
10
|
validate Docker::API::InvalidRequestBody, [:AttachStdin, :AttachStdout, :AttachStderr, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir], body
|
11
|
-
connection.request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json )
|
11
|
+
@connection.request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json )
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def start name, body = {}
|
15
15
|
validate Docker::API::InvalidRequestBody, [:Detach, :Tty], body
|
16
16
|
|
17
17
|
stream = ""
|
18
|
-
response = connection.request(method: :post,
|
18
|
+
response = @connection.request(method: :post,
|
19
19
|
path: "/exec/#{name}/start",
|
20
20
|
headers: {"Content-Type": "application/json"},
|
21
21
|
body: body.to_json,
|
@@ -25,13 +25,13 @@ module Docker
|
|
25
25
|
response
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def resize name, params = {}
|
29
29
|
validate Docker::API::InvalidParameter, [:w, :h], params
|
30
|
-
connection.post(build_path([name, "resize"], params))
|
30
|
+
@connection.post(build_path([name, "resize"], params))
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
connection.get(build_path([name, "json"]))
|
33
|
+
def inspect name
|
34
|
+
@connection.get(build_path([name, "json"]))
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
data/lib/docker/api/image.rb
CHANGED
@@ -7,113 +7,111 @@ 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
|
10
|
+
def base_path
|
11
11
|
"/images"
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
connection.get(build_path([name, "json"]))
|
14
|
+
def inspect name
|
15
|
+
@connection.get(build_path([name, "json"]))
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
connection.get(build_path([name, "history"]))
|
18
|
+
def history name
|
19
|
+
@connection.get(build_path([name, "history"]))
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def list params = {}
|
23
23
|
validate Docker::API::InvalidParameter, [:all, :filters, :digests], params
|
24
|
-
connection.get(build_path(["json"], params))
|
24
|
+
@connection.get(build_path(["json"], params))
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def search params = {}
|
28
28
|
validate Docker::API::InvalidParameter, [:term, :limit, :filters], params
|
29
|
-
connection.get(build_path(["search"], params))
|
29
|
+
@connection.get(build_path(["search"], params))
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def tag name, params = {}
|
33
33
|
validate Docker::API::InvalidParameter, [:repo, :tag], params
|
34
|
-
connection.post(build_path([name, "tag"], params))
|
34
|
+
@connection.post(build_path([name, "tag"], params))
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def prune params = {}
|
38
38
|
validate Docker::API::InvalidParameter, [:filters], params
|
39
|
-
connection.post(build_path(["prune"], params))
|
39
|
+
@connection.post(build_path(["prune"], params))
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def remove name, params = {}
|
43
43
|
validate Docker::API::InvalidParameter, [:force, :noprune], params
|
44
|
-
connection.delete(build_path([name], params))
|
44
|
+
@connection.delete(build_path([name], params))
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
47
|
+
def export name, path = "exported_image"
|
48
48
|
file = File.open("/tmp/exported-image", "wb")
|
49
49
|
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
50
50
|
file.write(chunk)
|
51
51
|
end
|
52
|
-
response = connection.request(method: :get, path: build_path([name, "get"]) , response_block: streamer)
|
52
|
+
response = @connection.request(method: :get, path: build_path([name, "get"]) , response_block: streamer)
|
53
53
|
file.close
|
54
54
|
response.status == 200 ? FileUtils.mv("/tmp/exported-image", File.expand_path(path)) : FileUtils.rm("/tmp/exported-image")
|
55
55
|
response
|
56
56
|
end
|
57
57
|
|
58
|
-
def
|
58
|
+
def import path, params = {}
|
59
59
|
validate Docker::API::InvalidParameter, [:quiet], params
|
60
60
|
file = File.open(File.expand_path(path), "r")
|
61
|
-
response = connection.request(method: :post, path: build_path(["load"], params) , headers: {"Content-Type" => "application/x-tar"}, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
61
|
+
response = @connection.request(method: :post, path: build_path(["load"], params) , headers: {"Content-Type" => "application/x-tar"}, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
62
62
|
file.close
|
63
63
|
response
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
66
|
+
def push name, params = {}, authentication = {}
|
67
67
|
validate Docker::API::InvalidParameter, [:tag], params
|
68
68
|
|
69
69
|
if authentication.keys.size > 0
|
70
|
-
|
71
|
-
return auth unless [200, 204].include? auth.status
|
72
|
-
connection.request(method: :post, path: build_path([name, "push"], params), headers: { "X-Registry-Auth" => Base64.encode64(authentication.to_json.to_s).chomp } )
|
70
|
+
@connection.request(method: :post, path: build_path([name, "push"], params), headers: { "X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s).chomp } )
|
73
71
|
else
|
74
|
-
|
72
|
+
raise Docker::API::Error.new("Provide authentication parameters to push an image")
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
78
|
-
def
|
76
|
+
def commit params = {}, body = {}
|
79
77
|
validate Docker::API::InvalidParameter, [:container, :repo, :tag, :comment, :author, :pause, :changes], params
|
80
78
|
validate Docker::API::InvalidRequestBody, Docker::API::CommitBody, body
|
81
|
-
container = Docker::API::Container.inspect(params[:container])
|
79
|
+
container = Docker::API::Container.new.inspect(params[:container])
|
82
80
|
return container if [404, 301].include? container.status
|
83
81
|
body = JSON.parse(container.body)["Config"].merge(body)
|
84
|
-
connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
82
|
+
@connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
85
83
|
end
|
86
84
|
|
87
|
-
def
|
85
|
+
def create params = {}, authentication = {}
|
88
86
|
validate Docker::API::InvalidParameter, [:fromImage, :fromSrc, :repo, :tag, :message, :platform], params
|
89
87
|
|
90
88
|
if authentication.keys.size > 0
|
91
|
-
auth = Docker::API::System.auth(authentication)
|
89
|
+
auth = Docker::API::System.new.auth(authentication)
|
92
90
|
return auth unless [200, 204].include? auth.status
|
93
|
-
connection.request(method: :post, path: build_path(["create"], params), headers: { "X-Registry-Auth" => Base64.encode64(authentication.to_json.to_s).chomp } )
|
91
|
+
@connection.request(method: :post, path: build_path(["create"], params), headers: { "X-Registry-Auth" => Base64.encode64(authentication.to_json.to_s).chomp } )
|
94
92
|
elsif params.has_key? :fromSrc
|
95
93
|
if params[:fromSrc].match(/^(http|https)/)
|
96
|
-
connection.request(method: :post, path: build_path(["create"], params))
|
94
|
+
@connection.request(method: :post, path: build_path(["create"], params))
|
97
95
|
else
|
98
96
|
file = File.open(File.expand_path(params[:fromSrc]), "r")
|
99
97
|
params[:fromSrc] = "-"
|
100
|
-
response = connection.request(method: :post, path: build_path(["create"], params) , headers: {"Content-Type" => "application/x-tar"}, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
98
|
+
response = @connection.request(method: :post, path: build_path(["create"], params) , headers: {"Content-Type" => "application/x-tar"}, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
101
99
|
file.close
|
102
100
|
response
|
103
101
|
end
|
104
102
|
else
|
105
|
-
connection.post(build_path(["create"], params))
|
103
|
+
@connection.post(build_path(["create"], params))
|
106
104
|
end
|
107
105
|
end
|
108
106
|
|
109
|
-
def
|
107
|
+
def build path, params = {}, authentication = {}
|
110
108
|
raise Docker::API::Error.new("Expected path or params[:remote]") unless path || params[:remote]
|
111
109
|
validate Docker::API::InvalidParameter, Docker::API::BuildParams, params
|
112
110
|
|
113
111
|
header = {"Content-type": "application/x-tar"}
|
114
112
|
if authentication.keys.size > 0
|
115
113
|
authentication.each_key do |server|
|
116
|
-
auth = Docker::API::System.auth({username: authentication[server][:username] ,password:authentication[server][:password], serveraddress: server})
|
114
|
+
auth = Docker::API::System.new.auth({username: authentication[server][:username] ,password:authentication[server][:password], serveraddress: server})
|
117
115
|
return auth unless [200, 204].include? auth.status
|
118
116
|
end
|
119
117
|
header.merge!({"X-Registry-Config": Base64.urlsafe_encode64(authentication.to_json.to_s).chomp})
|
@@ -121,17 +119,17 @@ module Docker
|
|
121
119
|
|
122
120
|
begin
|
123
121
|
file = File.open( File.expand_path( path ) , "r")
|
124
|
-
response = connection.request(method: :post, path: build_path("/build", params), headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s})
|
122
|
+
response = @connection.request(method: :post, path: build_path("/build", params), headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s})
|
125
123
|
file.close
|
126
124
|
rescue
|
127
|
-
response = connection.request(method: :post, path: build_path("/build", params), headers: header)
|
125
|
+
response = @connection.request(method: :post, path: build_path("/build", params), headers: header)
|
128
126
|
end
|
129
127
|
response
|
130
128
|
end
|
131
129
|
|
132
|
-
def
|
130
|
+
def delete_cache params = {}
|
133
131
|
validate Docker::API::InvalidParameter, [:all, "keep-storage", :filters], params
|
134
|
-
connection.post(build_path("/build/prune", params))
|
132
|
+
@connection.post(build_path("/build/prune", params))
|
135
133
|
end
|
136
134
|
|
137
135
|
end
|
data/lib/docker/api/network.rb
CHANGED
@@ -2,42 +2,42 @@ module Docker
|
|
2
2
|
module API
|
3
3
|
class Network < Docker::API::Base
|
4
4
|
|
5
|
-
def
|
5
|
+
def base_path
|
6
6
|
"/networks"
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def list params = {}
|
10
10
|
validate Docker::API::InvalidParameter, [:filters], params
|
11
|
-
connection.get(build_path("/networks", params))
|
11
|
+
@connection.get(build_path("/networks", params))
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def inspect name, params = {}
|
15
15
|
validate Docker::API::InvalidParameter, [:verbose, :scope], params
|
16
|
-
connection.get(build_path([name], params))
|
16
|
+
@connection.get(build_path([name], params))
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def create body = {}
|
20
20
|
validate Docker::API::InvalidRequestBody, [:Name, :CheckDuplicate, :Driver, :Internal, :Attachable, :Ingress, :IPAM, :EnableIPv6, :Options, :Labels], body
|
21
|
-
connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
21
|
+
@connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
connection.delete(build_path([name]))
|
24
|
+
def remove name
|
25
|
+
@connection.delete(build_path([name]))
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def prune params = {}
|
29
29
|
validate Docker::API::InvalidParameter, [:filters], params
|
30
|
-
connection.post(build_path(["prune"], params))
|
30
|
+
@connection.post(build_path(["prune"], params))
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def connect name, body = {}
|
34
34
|
validate Docker::API::InvalidRequestBody, [:Container, :EndpointConfig], body
|
35
|
-
connection.request(method: :post, path: build_path([name, "connect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
35
|
+
@connection.request(method: :post, path: build_path([name, "connect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def disconnect name, body = {}
|
39
39
|
validate Docker::API::InvalidRequestBody, [:Container, :Force], body
|
40
|
-
connection.request(method: :post, path: build_path([name, "disconnect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
40
|
+
@connection.request(method: :post, path: build_path([name, "disconnect"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
data/lib/docker/api/system.rb
CHANGED
@@ -2,32 +2,33 @@ require "json"
|
|
2
2
|
module Docker
|
3
3
|
module API
|
4
4
|
class System < Docker::API::Base
|
5
|
-
|
6
|
-
def
|
5
|
+
|
6
|
+
def auth body = {}
|
7
7
|
validate Docker::API::InvalidRequestBody, [:username, :password, :email, :serveraddress, :identitytoken], body
|
8
|
-
connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
|
8
|
+
@connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def events params = {}
|
12
12
|
validate Docker::API::InvalidParameter, [:since, :until, :filters], params
|
13
|
-
connection.request(method: :get, path: build_path("/events", params), response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect } )
|
13
|
+
@connection.request(method: :get, path: build_path("/events", params), response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect } )
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
connection.get("/_ping")
|
16
|
+
def ping
|
17
|
+
@connection.get("/_ping")
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
connection.get("/info")
|
20
|
+
def info
|
21
|
+
@connection.get("/info")
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
connection.get("/version")
|
24
|
+
def version
|
25
|
+
@connection.get("/version")
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
connection.get("/system/df")
|
28
|
+
def df
|
29
|
+
@connection.get("/system/df")
|
30
30
|
end
|
31
|
+
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
data/lib/docker/api/version.rb
CHANGED
data/lib/docker/api/volume.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
module Docker
|
2
2
|
module API
|
3
3
|
class Volume < Docker::API::Base
|
4
|
-
def
|
4
|
+
def base_path
|
5
5
|
"/volumes"
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
8
|
+
def list params = {}
|
9
9
|
validate Docker::API::InvalidParameter, [:filters], params
|
10
|
-
connection.get(build_path("/volumes", params))
|
10
|
+
@connection.get(build_path("/volumes", params))
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def create body = {}
|
14
14
|
validate Docker::API::InvalidRequestBody, [:Name, :Driver, :DriverOpts, :Labels], body
|
15
|
-
connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
15
|
+
@connection.request(method: :post, path: build_path(["create"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
connection.get(build_path([name]))
|
18
|
+
def inspect name
|
19
|
+
@connection.get(build_path([name]))
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def remove name, params = {}
|
23
23
|
validate Docker::API::InvalidParameter, [:force], params
|
24
|
-
connection.delete(build_path([name]))
|
24
|
+
@connection.delete(build_path([name]))
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def prune params = {}
|
28
28
|
validate Docker::API::InvalidParameter, [:filters], params
|
29
|
-
connection.post(build_path(["prune"], params))
|
29
|
+
@connection.post(build_path(["prune"], params))
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
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.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2020-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|