dockerapi 0.13.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +35 -0
- data/Gemfile.lock +3 -3
- data/README.md +73 -23
- data/bin/setup +9 -1
- data/dockerapi.gemspec +5 -4
- data/lib/docker/api/base.rb +64 -20
- data/lib/docker/api/connection.rb +23 -17
- data/lib/docker/api/container.rb +306 -144
- data/lib/docker/api/error.rb +19 -3
- data/lib/docker/api/exec.rb +49 -36
- data/lib/docker/api/image.rb +32 -14
- 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 +1 -1
- data/lib/docker/api/volume.rb +56 -37
- data/lib/dockerapi.rb +8 -1
- metadata +10 -7
- data/.travis.yml +0 -6
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
|
data/lib/docker/api/secret.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# This class represents the Docker API endpoints regarding secrets.
|
2
2
|
#
|
3
|
-
# @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
|
4
|
-
#
|
5
3
|
# Secrets are sensitive data that can be used by services. Swarm mode must be enabled for these endpoints to work.
|
4
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Secret
|
6
5
|
class Docker::API::Secret < Docker::API::Base
|
7
6
|
|
8
7
|
# List secrets
|
9
8
|
#
|
10
9
|
# Docker API: GET /secrets
|
11
|
-
#
|
12
10
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/SecretList
|
13
11
|
#
|
14
12
|
# @param params [Hash]: Parameters that are appended to the URL.
|
@@ -19,7 +17,6 @@ class Docker::API::Secret < Docker::API::Base
|
|
19
17
|
# Create a secret
|
20
18
|
#
|
21
19
|
# Docker API: POST /secrets/create
|
22
|
-
#
|
23
20
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/SecretCreate
|
24
21
|
#
|
25
22
|
# @param body [Hash]: Request body to be sent as json.
|
@@ -30,7 +27,6 @@ class Docker::API::Secret < Docker::API::Base
|
|
30
27
|
# Inspect a secret
|
31
28
|
#
|
32
29
|
# Docker API: GET /secrets/{id}
|
33
|
-
#
|
34
30
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/SecretInspect
|
35
31
|
#
|
36
32
|
# @param name [String]: The ID or name of the secret.
|
@@ -41,13 +37,10 @@ class Docker::API::Secret < Docker::API::Base
|
|
41
37
|
# Update a secret
|
42
38
|
#
|
43
39
|
# Docker API: POST /secrets/{id}/update
|
44
|
-
#
|
45
40
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/SecretUpdate
|
46
41
|
#
|
47
42
|
# @param name [String]: The ID or name of the secret.
|
48
|
-
#
|
49
43
|
# @param params [Hash]: Parameters that are appended to the URL.
|
50
|
-
#
|
51
44
|
# @param body [Hash]: Request body to be sent as json.
|
52
45
|
def update name, params = {}, body = {}
|
53
46
|
@connection.request(method: :post, path: build_path("/secrets/#{name}/update",params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
@@ -56,7 +49,6 @@ class Docker::API::Secret < Docker::API::Base
|
|
56
49
|
# Delete a secret
|
57
50
|
#
|
58
51
|
# Docker API: DELETE /secrets/{id}
|
59
|
-
#
|
60
52
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/SecretDelete
|
61
53
|
#
|
62
54
|
# @param name [String]: The ID or name of the secret.
|
data/lib/docker/api/service.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# This class represents the Docker API endpoints regarding services.
|
2
2
|
#
|
3
|
-
# @see https://docs.docker.com/engine/api/v1.40/#tag/Service
|
4
|
-
#
|
5
3
|
# Services are the definitions of tasks to run on a swarm. Swarm mode must be enabled for these endpoints to work.
|
4
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Service
|
6
5
|
class Docker::API::Service < Docker::API::Base
|
7
6
|
|
8
7
|
# List services
|
9
8
|
#
|
10
9
|
# Docker API: GET /services
|
11
|
-
#
|
12
10
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceList
|
13
11
|
#
|
14
12
|
# @param params [Hash]: Parameters that are appended to the URL.
|
@@ -19,46 +17,38 @@ class Docker::API::Service < Docker::API::Base
|
|
19
17
|
# Create a service
|
20
18
|
#
|
21
19
|
# Docker API: POST /services/create
|
22
|
-
#
|
23
20
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceCreate
|
24
21
|
#
|
25
22
|
# @param body [Hash]: Request body to be sent as json.
|
26
|
-
#
|
27
23
|
# @param authentication [Hash]: Authentication parameters.
|
28
24
|
def create body = {}, authentication = {}
|
29
25
|
headers = {"Content-Type": "application/json"}
|
30
|
-
headers.merge!({"X-Registry-Auth" =>
|
26
|
+
headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
|
31
27
|
@connection.request(method: :post, path: "/services/create", headers: headers, body: body.to_json)
|
32
28
|
end
|
33
29
|
|
34
30
|
# Update a service
|
35
31
|
#
|
36
32
|
# Docker API: POST /services/{id}/update
|
37
|
-
#
|
38
33
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceUpdate
|
39
34
|
#
|
40
35
|
# @param name [String]: The ID or name of the service.
|
41
|
-
#
|
42
36
|
# @param params [Hash]: Parameters that are appended to the URL.
|
43
|
-
#
|
44
37
|
# @param body [Hash]: Request body to be sent as json.
|
45
|
-
#
|
46
38
|
# @param authentication [Hash]: Authentication parameters.
|
47
39
|
def update name, params = {}, body = {}, authentication = {}
|
48
40
|
# view https://github.com/docker/swarmkit/issues/1394#issuecomment-240850719
|
49
41
|
headers = {"Content-Type": "application/json"}
|
50
|
-
headers.merge!({"X-Registry-Auth" =>
|
42
|
+
headers.merge!({"X-Registry-Auth" => auth_encoder(authentication) }) if authentication.keys.size > 0
|
51
43
|
@connection.request(method: :post, path: build_path("/services/#{name}/update", params), headers: headers, body: body.to_json)
|
52
44
|
end
|
53
45
|
|
54
46
|
# Inspect a service
|
55
47
|
#
|
56
48
|
# Docker API: GET /services/{id}
|
57
|
-
#
|
58
49
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceInspect
|
59
50
|
#
|
60
51
|
# @param name [String]: The ID or name of the service.
|
61
|
-
#
|
62
52
|
# @param params [Hash]: Parameters that are appended to the URL.
|
63
53
|
def details name, params = {}
|
64
54
|
@connection.get(build_path("/services/#{name}", params))
|
@@ -66,14 +56,10 @@ class Docker::API::Service < Docker::API::Base
|
|
66
56
|
|
67
57
|
# Get stdout and stderr logs from a service.
|
68
58
|
#
|
69
|
-
# Note: This endpoint works only for services with the local, json-file or journald logging drivers.
|
70
|
-
#
|
71
59
|
# Docker API: GET /services/{id}/logs
|
72
|
-
#
|
73
60
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceLogs
|
74
61
|
#
|
75
62
|
# @param name [String]: The ID or name of the service.
|
76
|
-
#
|
77
63
|
# @param params [Hash]: Parameters that are appended to the URL.
|
78
64
|
def logs name, params = {}
|
79
65
|
@connection.get(build_path("/services/#{name}/logs", params))
|
@@ -82,7 +68,6 @@ class Docker::API::Service < Docker::API::Base
|
|
82
68
|
# Delete a service
|
83
69
|
#
|
84
70
|
# Docker API: DELETE /services/{id}
|
85
|
-
#
|
86
71
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ServiceDelete
|
87
72
|
#
|
88
73
|
# @param name [String]: The ID or name of the service.
|
data/lib/docker/api/swarm.rb
CHANGED
@@ -1,45 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
##
|
2
|
+
# This class represents the Docker API endpoints regarding swamrs.
|
3
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Swarm
|
4
|
+
class Docker::API::Swarm < Docker::API::Base
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
##
|
7
|
+
# Initialize a new swarm.
|
8
|
+
#
|
9
|
+
# Docker API: POST /swarm/init
|
10
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInit
|
11
|
+
#
|
12
|
+
# @param body [Hash]: Request body to be sent as json.
|
13
|
+
def init body = {}
|
14
|
+
@connection.request(method: :post, path: build_path("/swarm/init"), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
15
|
+
end
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
##
|
18
|
+
# Update a swarm.
|
19
|
+
#
|
20
|
+
# Docker API: POST /swarm/update
|
21
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUpdate
|
22
|
+
#
|
23
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
24
|
+
# @param body [Hash]: Request body to be sent as json.
|
25
|
+
def update params = {}, body = {}
|
26
|
+
@connection.request(method: :post, path: build_path("/swarm/update", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
27
|
+
end
|
16
28
|
|
17
|
-
|
18
|
-
|
19
|
-
|
29
|
+
##
|
30
|
+
# Inspect swarm.
|
31
|
+
#
|
32
|
+
# Docker API: GET /swarm
|
33
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmInspect
|
34
|
+
def details
|
35
|
+
@connection.get("/swarm")
|
36
|
+
end
|
20
37
|
|
21
|
-
|
22
|
-
|
23
|
-
|
38
|
+
##
|
39
|
+
# Get the unlock key.
|
40
|
+
#
|
41
|
+
# Docker API: GET /swarm/unlockkey
|
42
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlockkey
|
43
|
+
def unlock_key
|
44
|
+
@connection.get("/swarm/unlockkey")
|
45
|
+
end
|
24
46
|
|
25
|
-
|
26
|
-
|
27
|
-
|
47
|
+
##
|
48
|
+
# Unlock a locked manager.
|
49
|
+
#
|
50
|
+
# Docker API: POST /swarm/unlock
|
51
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmUnlock
|
52
|
+
#
|
53
|
+
# @param body [Hash]: Request body to be sent as json.
|
54
|
+
def unlock body = {}
|
55
|
+
@connection.request(method: :post, path: "/swarm/unlock", headers: {"Content-Type": "application/json"}, body: body.to_json)
|
56
|
+
end
|
28
57
|
|
29
|
-
|
30
|
-
|
31
|
-
|
58
|
+
##
|
59
|
+
# Join an existing swarm.
|
60
|
+
#
|
61
|
+
# Docker API: POST /swarm/join
|
62
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmJoin
|
63
|
+
#
|
64
|
+
# @param body [Hash]: Request body to be sent as json.
|
65
|
+
def join body = {}
|
66
|
+
@connection.request(method: :post, path: "/swarm/join", headers: {"Content-Type": "application/json"}, body: body.to_json)
|
67
|
+
end
|
32
68
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
69
|
+
##
|
70
|
+
# Leave a swarm.
|
71
|
+
#
|
72
|
+
# Docker API: POST /swarm/leave
|
73
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SwarmLeave
|
74
|
+
#
|
75
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
76
|
+
def leave params = {}
|
77
|
+
@connection.post(build_path("/swarm/leave", params))
|
44
78
|
end
|
45
79
|
end
|
data/lib/docker/api/system.rb
CHANGED
@@ -1,32 +1,65 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
##
|
2
|
+
# This class represents the Docker API system related endpoints.
|
3
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/System
|
4
|
+
class Docker::API::System < Docker::API::Base
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
##
|
7
|
+
# Validate credentials for a registry and, if available, get an identity token for accessing the registry without password.
|
8
|
+
#
|
9
|
+
# Docker API: POST /auth
|
10
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SystemAuth
|
11
|
+
#
|
12
|
+
# @param body [Hash]: Request body to be sent as json.
|
13
|
+
def auth body = {}
|
14
|
+
@connection.request(method: :post, path: "/auth", headers: { "Content-Type" => "application/json" }, body: body.to_json)
|
15
|
+
end
|
9
16
|
|
10
|
-
|
11
|
-
|
12
|
-
|
17
|
+
##
|
18
|
+
# Stream real-time events from the server.
|
19
|
+
#
|
20
|
+
# Docker API: GET /events
|
21
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SystemEvents
|
22
|
+
#
|
23
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
24
|
+
# @param &block: Replace the default output to stdout behavior.
|
25
|
+
def events params = {}, &block
|
26
|
+
@connection.request(method: :get, path: build_path("/events", params), response_block: block_given? ? block : default_streamer )
|
27
|
+
end
|
13
28
|
|
14
|
-
|
15
|
-
|
16
|
-
|
29
|
+
##
|
30
|
+
# This is a dummy endpoint you can use to test if the server is accessible.
|
31
|
+
#
|
32
|
+
# Docker API: GET /_ping
|
33
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SystemPing
|
34
|
+
def ping
|
35
|
+
@connection.get("/_ping")
|
36
|
+
end
|
17
37
|
|
18
|
-
|
19
|
-
|
20
|
-
|
38
|
+
##
|
39
|
+
# Get system information.
|
40
|
+
#
|
41
|
+
# Docker API: GET /info
|
42
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SystemInfo
|
43
|
+
def info
|
44
|
+
@connection.get("/info")
|
45
|
+
end
|
21
46
|
|
22
|
-
|
23
|
-
|
24
|
-
|
47
|
+
##
|
48
|
+
# Return the version of Docker that is running and various information about the system that Docker is running on.
|
49
|
+
#
|
50
|
+
# Docker API: GET /version
|
51
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SystemVersion
|
52
|
+
def version
|
53
|
+
@connection.get("/version")
|
54
|
+
end
|
25
55
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
56
|
+
##
|
57
|
+
# Get data usage information.
|
58
|
+
#
|
59
|
+
# Docker API: GET /system/df
|
60
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/SystemDataUsage
|
61
|
+
def df
|
62
|
+
@connection.get("/system/df")
|
31
63
|
end
|
64
|
+
|
32
65
|
end
|
data/lib/docker/api/task.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# This class represents the Docker API endpoints regarding tasks.
|
2
2
|
#
|
3
|
-
# @see https://docs.docker.com/engine/api/v1.40/#tag/Task
|
4
|
-
#
|
5
3
|
# 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.
|
4
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Task
|
6
5
|
class Docker::API::Task < Docker::API::Base
|
7
6
|
|
8
7
|
# List tasks
|
9
8
|
#
|
10
9
|
# Docker API: GET /tasks
|
11
|
-
#
|
12
10
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/TaskList
|
13
11
|
#
|
14
12
|
# @param params [Hash]: Parameters that are appended to the URL.
|
@@ -19,7 +17,6 @@ class Docker::API::Task < Docker::API::Base
|
|
19
17
|
# Inspect a task
|
20
18
|
#
|
21
19
|
# Docker API: GET /tasks/{id}
|
22
|
-
#
|
23
20
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/TaskInspect
|
24
21
|
#
|
25
22
|
# @param name [String]: The ID or name of the task.
|
@@ -29,16 +26,19 @@ class Docker::API::Task < Docker::API::Base
|
|
29
26
|
|
30
27
|
# Get stdout and stderr logs from a task.
|
31
28
|
#
|
32
|
-
# Note: This endpoint works only for services with the local, json-file or journald logging drivers.
|
33
|
-
#
|
34
29
|
# Docker API: GET /tasks/{id}/logs
|
35
|
-
#
|
36
30
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/TaskLogs
|
37
31
|
#
|
38
32
|
# @param name (String) : The ID or name of the task.
|
39
|
-
#
|
40
33
|
# @param params (Hash) : Parameters that are appended to the URL.
|
41
|
-
|
42
|
-
|
34
|
+
# @param &block: Replace the default output to stdout behavior.
|
35
|
+
def logs name, params = {}, &block
|
36
|
+
path = build_path("/tasks/#{name}/logs", params)
|
37
|
+
|
38
|
+
if [true, 1 ].include? params[:follow]
|
39
|
+
@connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
|
40
|
+
else
|
41
|
+
@connection.get(path)
|
42
|
+
end
|
43
43
|
end
|
44
44
|
end
|