dockerapi 0.14.0 → 0.19.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/.github/workflows/ruby.yml +67 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile.lock +3 -3
- data/README.md +39 -21
- data/bin/setup +9 -1
- data/dockerapi.gemspec +1 -1
- data/lib/docker/api/base.rb +64 -20
- data/lib/docker/api/connection.rb +25 -17
- data/lib/docker/api/container.rb +6 -6
- data/lib/docker/api/error.rb +19 -3
- data/lib/docker/api/exec.rb +49 -36
- data/lib/docker/api/image.rb +13 -10
- data/lib/docker/api/network.rb +84 -48
- data/lib/docker/api/node.rb +47 -28
- data/lib/docker/api/response.rb +27 -19
- data/lib/docker/api/secret.rb +1 -9
- data/lib/docker/api/service.rb +3 -18
- data/lib/docker/api/swarm.rb +70 -36
- data/lib/docker/api/system.rb +57 -24
- data/lib/docker/api/task.rb +10 -10
- data/lib/docker/api/version.rb +2 -2
- data/lib/docker/api/volume.rb +56 -37
- data/lib/dockerapi.rb +10 -0
- metadata +5 -5
- data/.travis.yml +0 -6
data/lib/docker/api/error.rb
CHANGED
@@ -1,17 +1,33 @@
|
|
1
1
|
module Docker
|
2
2
|
module API
|
3
|
+
|
4
|
+
##
|
5
|
+
# This class represents a validation error.
|
3
6
|
class ValidationError < StandardError
|
7
|
+
|
8
|
+
##
|
9
|
+
# @params permitted [Array]: permitted values.
|
10
|
+
# @params unpermitted [Array]: unpermitted values.
|
4
11
|
def initialize permitted, unpermitted
|
5
12
|
super("Unpermitted options found: #{unpermitted.to_s}. Permitted are #{permitted.to_s}")
|
6
13
|
end
|
7
14
|
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# This class represents a parameter validation error.
|
18
|
+
class InvalidParameter < Docker::API::ValidationError; end
|
19
|
+
|
20
|
+
##
|
21
|
+
# This class represents a request body validation error.
|
22
|
+
class InvalidRequestBody < Docker::API::ValidationError; end
|
23
|
+
|
24
|
+
##
|
25
|
+
# This class represents a generic error.
|
8
26
|
class Error < StandardError
|
9
27
|
def initialize msg = "Error without specific message"
|
10
28
|
super(msg)
|
11
29
|
end
|
12
30
|
end
|
13
|
-
|
14
|
-
class InvalidParameter < Docker::API::ValidationError; end
|
15
|
-
class InvalidRequestBody < Docker::API::ValidationError; end
|
31
|
+
|
16
32
|
end
|
17
33
|
end
|
data/lib/docker/api/exec.rb
CHANGED
@@ -1,42 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
##
|
2
|
+
# This class represents the Docker API exec related endpoints.
|
3
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Exec
|
4
|
+
class Docker::API::Exec < Docker::API::Base
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
)
|
17
|
-
response.data.merge!({stream: stream})
|
18
|
-
response
|
19
|
-
end
|
6
|
+
##
|
7
|
+
# Run a command inside a running container.
|
8
|
+
#
|
9
|
+
# Docker API: POST /containers/{id}/exec
|
10
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerExec
|
11
|
+
#
|
12
|
+
# @param name [String]: The ID or name of the container.
|
13
|
+
# @param body [Hash]: Request body to be sent as json.
|
14
|
+
def create name, body = {}
|
15
|
+
@connection.request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json )
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
##
|
19
|
+
# Start a previously set up exec instance.
|
20
|
+
#
|
21
|
+
# Docker API: POST /exec/{id}/start
|
22
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ExecStart
|
23
|
+
#
|
24
|
+
# @param name [String]: Exec instance ID.
|
25
|
+
# @param body [Hash]: Request body to be sent as json.
|
26
|
+
# @param &block: Replace the default output to stdout behavior.
|
27
|
+
def start name, body = {}, &block
|
28
|
+
@connection.request(method: :post, path: "/exec/#{name}/start", headers: {"Content-Type": "application/json"}, body: body.to_json,
|
29
|
+
response_block: block_given? ? block : default_streamer )
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
details(name)
|
37
|
-
end
|
38
|
-
#################################################
|
32
|
+
##
|
33
|
+
# Resize the TTY session used by an exec instance.
|
34
|
+
#
|
35
|
+
# Docker API: POST /exec/{id}/resize
|
36
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ExecResize
|
37
|
+
#
|
38
|
+
# @param name [String]: Exec instance ID.
|
39
|
+
# @param body [Hash]: Request body to be sent as json.
|
40
|
+
def resize name, params = {}
|
41
|
+
@connection.post(build_path("/exec/#{name}/resize", params))
|
42
|
+
end
|
39
43
|
|
40
|
-
|
44
|
+
##
|
45
|
+
# Return low-level information about an exec instance.
|
46
|
+
#
|
47
|
+
# Docker API: GET /exec/{id}/json
|
48
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ExecInspect
|
49
|
+
#
|
50
|
+
# @param name [String]: Exec instance ID.
|
51
|
+
def details name
|
52
|
+
@connection.get("/exec/#{name}/json")
|
41
53
|
end
|
54
|
+
|
42
55
|
end
|
data/lib/docker/api/image.rb
CHANGED
@@ -21,8 +21,11 @@ class Docker::API::Image < Docker::API::Base
|
|
21
21
|
# @see https://docs.docker.com/engine/api/v1.40/#tag/Distribution
|
22
22
|
#
|
23
23
|
# @param name [String]: The ID or name of the image.
|
24
|
-
|
25
|
-
|
24
|
+
# @param authentication [Hash]: Authentication parameters.
|
25
|
+
def distribution name, authentication = {}
|
26
|
+
request = {method: :get, path: "/distribution/#{name}/json"}
|
27
|
+
request[:headers] = {"X-Registry-Auth" => auth_encoder(authentication)} if authentication.any?
|
28
|
+
@connection.request(request)
|
26
29
|
end
|
27
30
|
|
28
31
|
##
|
@@ -37,7 +40,7 @@ class Docker::API::Image < Docker::API::Base
|
|
37
40
|
end
|
38
41
|
|
39
42
|
##
|
40
|
-
#
|
43
|
+
# Return a list of images on the server. Note that it uses a different, smaller representation of an image than inspecting a single image.
|
41
44
|
#
|
42
45
|
# Docker API: GET /images/json
|
43
46
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageList
|
@@ -105,7 +108,7 @@ class Docker::API::Image < Docker::API::Base
|
|
105
108
|
# @param path [String]: Path to the exported file.
|
106
109
|
# @param &block: Replace the default file writing behavior.
|
107
110
|
def export name, path, &block
|
108
|
-
@connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block
|
111
|
+
@connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block : default_writer(path))
|
109
112
|
end
|
110
113
|
|
111
114
|
##
|
@@ -130,8 +133,8 @@ class Docker::API::Image < Docker::API::Base
|
|
130
133
|
# @param params [Hash]: Parameters that are appended to the URL.
|
131
134
|
# @param authentication [Hash]: Authentication parameters.
|
132
135
|
def push name, params = {}, authentication = {}
|
133
|
-
raise Docker::API::Error.new("Provide authentication parameters to push an image") unless authentication.
|
134
|
-
@connection.request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" =>
|
136
|
+
raise Docker::API::Error.new("Provide authentication parameters to push an image") unless authentication.any?
|
137
|
+
@connection.request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" => auth_encoder(authentication) } )
|
135
138
|
end
|
136
139
|
|
137
140
|
##
|
@@ -158,13 +161,13 @@ class Docker::API::Image < Docker::API::Base
|
|
158
161
|
# @param authentication [Hash]: Authentication parameters.
|
159
162
|
# @param &block: Replace the default output to stdout behavior.
|
160
163
|
def create params = {}, authentication = {}, &block
|
161
|
-
request = {method: :post, path: build_path("/images/create", params), response_block: block_given? ? block
|
164
|
+
request = {method: :post, path: build_path("/images/create", params), response_block: block_given? ? block : default_streamer }
|
162
165
|
if params.has_key? :fromSrc and !params[:fromSrc].match(/^(http|https)/) # then it's using a tar file
|
163
166
|
path = params[:fromSrc]
|
164
167
|
params[:fromSrc] = "-"
|
165
168
|
default_reader(path, build_path("/images/create", params))
|
166
169
|
else
|
167
|
-
request[:headers] = { "X-Registry-Auth" =>
|
170
|
+
request[:headers] = { "X-Registry-Auth" => auth_encoder(authentication) } if authentication.any?
|
168
171
|
@connection.request(request)
|
169
172
|
end
|
170
173
|
end
|
@@ -183,10 +186,10 @@ class Docker::API::Image < Docker::API::Base
|
|
183
186
|
raise Docker::API::Error.new("Expected path or params[:remote]") unless path || params[:remote]
|
184
187
|
|
185
188
|
headers = {"Content-type": "application/x-tar"}
|
186
|
-
headers.merge!({"X-Registry-Config":
|
189
|
+
headers.merge!({"X-Registry-Config": auth_encoder(authentication) }) if authentication.any?
|
187
190
|
|
188
191
|
if path == nil and params.has_key? :remote
|
189
|
-
response = @connection.request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block
|
192
|
+
response = @connection.request(method: :post, path: build_path("/build", params), headers: headers, response_block: block_given? ? block : default_streamer)
|
190
193
|
else
|
191
194
|
default_reader(path, build_path("/build", params), headers)
|
192
195
|
end
|
data/lib/docker/api/network.rb
CHANGED
@@ -1,50 +1,86 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
1
|
+
##
|
2
|
+
# This class represents the Docker API endpoints regarding networks.
|
3
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Network
|
4
|
+
class Docker::API::Network < Docker::API::Base
|
5
|
+
|
6
|
+
##
|
7
|
+
# List networks.
|
8
|
+
#
|
9
|
+
# Docker API: GET /networks
|
10
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkList
|
11
|
+
#
|
12
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
13
|
+
def list params = {}
|
14
|
+
@connection.get(build_path("/networks", params))
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Inspect a network.
|
19
|
+
#
|
20
|
+
# Docker API: GET /networks/{id}
|
21
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkInspect
|
22
|
+
#
|
23
|
+
# @param name [String]: The ID or name of the network.
|
24
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
25
|
+
def details name, params = {}
|
26
|
+
@connection.get(build_path("/networks/#{name}", params))
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Create a network.
|
31
|
+
#
|
32
|
+
# Docker API: POST /networks/create
|
33
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkCreate
|
34
|
+
#
|
35
|
+
# @param body [Hash]: Request body to be sent as json.
|
36
|
+
def create body = {}
|
37
|
+
@connection.request(method: :post, path: "/networks/create", headers: {"Content-Type": "application/json"}, body: body.to_json)
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Remove a network.
|
42
|
+
#
|
43
|
+
# Docker API: DELETE /networks/{id}
|
44
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkDelete
|
45
|
+
#
|
46
|
+
# @param name [String]: The ID or name of the network.
|
47
|
+
def remove name
|
48
|
+
@connection.delete("/networks/#{name}")
|
49
49
|
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Delete unused networks.
|
53
|
+
#
|
54
|
+
# Docker API: POST /networks/prune
|
55
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkPrune
|
56
|
+
#
|
57
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
58
|
+
def prune params = {}
|
59
|
+
@connection.post(build_path("/networks/prune", params))
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Connect a container to a network.
|
64
|
+
#
|
65
|
+
# Docker API: POST /networks/{id}/connect
|
66
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkConnect
|
67
|
+
#
|
68
|
+
# @param name [String]: The ID or name of the network.
|
69
|
+
# @param body [Hash]: Request body to be sent as json.
|
70
|
+
def connect name, body = {}
|
71
|
+
@connection.request(method: :post, path: "/networks/#{name}/connect", headers: {"Content-Type": "application/json"}, body: body.to_json)
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Disconnect a container from a network.
|
76
|
+
#
|
77
|
+
# Docker API: POST /networks/{id}/disconnect
|
78
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NetworkDisconnect
|
79
|
+
#
|
80
|
+
# @param name [String]: The ID or name of the network.
|
81
|
+
# @param body [Hash]: Request body to be sent as json.
|
82
|
+
def disconnect name, body = {}
|
83
|
+
@connection.request(method: :post, path: "/networks/#{name}/disconnect", headers: {"Content-Type": "application/json"}, body: body.to_json)
|
84
|
+
end
|
85
|
+
|
50
86
|
end
|
data/lib/docker/api/node.rb
CHANGED
@@ -1,34 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# This class represents the Docker API endpoints regarding nodes.
|
2
|
+
#
|
3
|
+
# Nodes are instances of the Engine participating in a swarm. Swarm mode must be enabled for these endpoints to work.
|
4
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Node
|
5
|
+
class Docker::API::Node < Docker::API::Base
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
7
|
+
##
|
8
|
+
# List nodes.
|
9
|
+
#
|
10
|
+
# Docker API: GET /nodes
|
11
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NodeList
|
12
|
+
#
|
13
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
14
|
+
def list params = {}
|
15
|
+
@connection.get(build_path("/nodes", params))
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
##
|
19
|
+
# Update a node.
|
20
|
+
#
|
21
|
+
# Docker API: POST /nodes/{id}/update
|
22
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NodeUpdate
|
23
|
+
#
|
24
|
+
# @param name [String]: The ID or name of the node.
|
25
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
26
|
+
# @param body [Hash]: Request body to be sent as json.
|
27
|
+
def update name, params = {}, body = {}
|
28
|
+
@connection.request(method: :post, path: build_path("nodes/#{name}/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
29
|
+
end
|
20
30
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
##
|
32
|
+
# Delete a node.
|
33
|
+
#
|
34
|
+
# Docker API: DELETE /nodes/{id}
|
35
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NodeDelete
|
36
|
+
#
|
37
|
+
# @param name [String]: The ID or name of the node.
|
38
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
39
|
+
def delete name, params = {}
|
40
|
+
@connection.delete(build_path("/nodes/#{name}", params))
|
41
|
+
end
|
31
42
|
|
32
|
-
|
43
|
+
##
|
44
|
+
# Inspect a node.
|
45
|
+
#
|
46
|
+
# Docker API: GET /nodes/{id}
|
47
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/NodeInspect
|
48
|
+
#
|
49
|
+
# @param name [String]: The ID or name of the node.
|
50
|
+
def details name
|
51
|
+
@connection.get("/nodes/#{name}")
|
33
52
|
end
|
34
53
|
end
|
data/lib/docker/api/response.rb
CHANGED
@@ -1,25 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
##
|
2
|
+
# Reponse class.
|
3
|
+
class Docker::API::Response < Excon::Response
|
4
|
+
attr_reader(:json, :path)
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
##
|
7
|
+
# Initialize a new Response object.
|
8
|
+
#
|
9
|
+
# @params data [Object]: Reponse's data.
|
10
|
+
def initialize data
|
11
|
+
super data
|
12
|
+
@json = parse_json @body
|
13
|
+
@path = @data[:path]
|
14
|
+
end
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
##
|
17
|
+
# Return true if Response status is in 200..204 range.
|
18
|
+
def success?
|
19
|
+
(200..204).include? @status
|
20
|
+
end
|
15
21
|
|
16
|
-
|
22
|
+
private
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
##
|
25
|
+
# Create a json from Response data attribute.
|
26
|
+
#
|
27
|
+
# @params data [String]: String to be converted in json.
|
28
|
+
def parse_json data
|
29
|
+
return nil unless headers["Content-Type"] == "application/json"
|
30
|
+
return nil if data == ""
|
31
|
+
data.split("\r\n").size > 1 ? data.split("\r\n").map{ |e| eval(e) } : JSON.parse(data)
|
24
32
|
end
|
25
33
|
end
|