dockerapi 0.12.0 → 0.17.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 +40 -0
- data/Gemfile.lock +3 -3
- data/README.md +69 -24
- data/dockerapi.gemspec +4 -3
- data/lib/docker/api/base.rb +101 -29
- data/lib/docker/api/config.rb +0 -4
- data/lib/docker/api/connection.rb +23 -17
- data/lib/docker/api/container.rb +306 -166
- data/lib/docker/api/error.rb +19 -3
- data/lib/docker/api/exec.rb +49 -40
- data/lib/docker/api/image.rb +201 -148
- data/lib/docker/api/network.rb +84 -54
- data/lib/docker/api/node.rb +47 -32
- data/lib/docker/api/plugin.rb +0 -6
- data/lib/docker/api/response.rb +27 -19
- data/lib/docker/api/secret.rb +1 -13
- data/lib/docker/api/service.rb +3 -24
- data/lib/docker/api/swarm.rb +70 -42
- data/lib/docker/api/system.rb +57 -26
- data/lib/docker/api/task.rb +10 -12
- data/lib/docker/api/version.rb +1 -1
- data/lib/docker/api/volume.rb +56 -41
- data/lib/dockerapi.rb +143 -0
- metadata +10 -7
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,46 +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
|
-
headers: {"Content-Type": "application/json"},
|
17
|
-
body: body.to_json,
|
18
|
-
response_block: lambda { |chunk, remaining_bytes, total_bytes| stream += chunk.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') }
|
19
|
-
)
|
20
|
-
response.data.merge!({stream: stream})
|
21
|
-
response
|
22
|
-
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
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
##
|
19
|
+
# Starts 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
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
details(name)
|
41
|
-
end
|
42
|
-
#################################################
|
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
|
43
43
|
|
44
|
-
|
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")
|
45
53
|
end
|
54
|
+
|
46
55
|
end
|
data/lib/docker/api/image.rb
CHANGED
@@ -1,152 +1,205 @@
|
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
# Items in this area to be removed before 1.0.0 #
|
137
|
-
#################################################
|
138
|
-
def base_path
|
139
|
-
"/images"
|
140
|
-
end
|
141
|
-
|
142
|
-
def inspect *args
|
143
|
-
return super.inspect if args.size == 0
|
144
|
-
warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
|
145
|
-
name = args[0]
|
146
|
-
details(name)
|
147
|
-
end
|
148
|
-
#################################################
|
1
|
+
##
|
2
|
+
# This class represents the Docker API endpoints regarding images.
|
3
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Image
|
4
|
+
class Docker::API::Image < Docker::API::Base
|
5
|
+
|
6
|
+
##
|
7
|
+
# Return low-level information about an image.
|
8
|
+
#
|
9
|
+
# Docker API: GET /images/{name}/json
|
10
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageInspect
|
11
|
+
#
|
12
|
+
# @param name [String]: The ID or name of the image.
|
13
|
+
def details name
|
14
|
+
@connection.get("/images/#{name}/json")
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Return image digest and platform information by contacting the registry.
|
19
|
+
#
|
20
|
+
# Docker API: GET /distribution/{name}/json
|
21
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Distribution
|
22
|
+
#
|
23
|
+
# @param name [String]: The ID or name of the image.
|
24
|
+
def distribution name
|
25
|
+
@connection.get("/distribution/#{name}/json")
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Return parent layers of an image.
|
30
|
+
#
|
31
|
+
# Docker API: GET /images/{name}/history
|
32
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageHistory
|
33
|
+
#
|
34
|
+
# @param name [String]: The ID or name of the image.
|
35
|
+
def history name
|
36
|
+
@connection.get("/images/#{name}/history")
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Returns a list of images on the server. Note that it uses a different, smaller representation of an image than inspecting a single image.
|
41
|
+
#
|
42
|
+
# Docker API: GET /images/json
|
43
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageList
|
44
|
+
#
|
45
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
46
|
+
def list params = {}
|
47
|
+
@connection.get(build_path("/images/json", params))
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Search for an image on Docker Hub.
|
52
|
+
#
|
53
|
+
# Docker API: GET /images/search
|
54
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageSearch
|
55
|
+
#
|
56
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
57
|
+
def search params = {}
|
58
|
+
@connection.get(build_path("/images/search", params))
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Tag an image so that it becomes part of a repository.
|
63
|
+
#
|
64
|
+
# Docker API: POST /images/{name}/tag
|
65
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageTag
|
66
|
+
#
|
67
|
+
# @param name [String]: The ID or name of the image.
|
68
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
69
|
+
def tag name, params = {}
|
70
|
+
@connection.post(build_path("/images/#{name}/tag", params))
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Delete unused images.
|
75
|
+
#
|
76
|
+
# Docker API: POST /images/prune
|
77
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImagePrune
|
78
|
+
#
|
79
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
80
|
+
def prune params = {}
|
81
|
+
@connection.post(build_path("/images/prune", params))
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Remove an image, along with any untagged parent images that were referenced by that image.
|
86
|
+
#
|
87
|
+
# Images can't be removed if they have descendant images, are being used by a running container or are being used by a build.
|
88
|
+
#
|
89
|
+
# Docker API: DELETE /images/{name}
|
90
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageDelete
|
91
|
+
#
|
92
|
+
# @param name [String]: The ID or name of the image.
|
93
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
94
|
+
def remove name, params = {}
|
95
|
+
@connection.delete(build_path("/images/#{name}", params))
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Export an image.
|
100
|
+
#
|
101
|
+
# Docker API: GET /images/{name}/get
|
102
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageGet
|
103
|
+
#
|
104
|
+
# @param name [String]: The ID or name of the image.
|
105
|
+
# @param path [String]: Path to the exported file.
|
106
|
+
# @param &block: Replace the default file writing behavior.
|
107
|
+
def export name, path, &block
|
108
|
+
@connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block : default_writer(path))
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Import images.
|
113
|
+
#
|
114
|
+
# Docker API: POST /images/load
|
115
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageLoad
|
116
|
+
#
|
117
|
+
# @param name [String]: The ID or name of the image.
|
118
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
119
|
+
def import path, params = {}
|
120
|
+
default_reader(path, build_path("/images/load", params))
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Push an image to a registry.
|
125
|
+
#
|
126
|
+
# Docker API: POST /images/{name}/push
|
127
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImagePush
|
128
|
+
#
|
129
|
+
# @param name [String]: The ID or name of the image.
|
130
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
131
|
+
# @param authentication [Hash]: Authentication parameters.
|
132
|
+
def push name, params = {}, authentication = {}
|
133
|
+
raise Docker::API::Error.new("Provide authentication parameters to push an image") unless authentication.keys.size > 0
|
134
|
+
@connection.request(method: :post, path: build_path("/images/#{name}/push", params), headers: { "X-Registry-Auth" => auth_encoder(authentication) } )
|
135
|
+
end
|
149
136
|
|
137
|
+
##
|
138
|
+
# Create a new image from a container.
|
139
|
+
#
|
140
|
+
# Docker API: POST /commit
|
141
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageCommit
|
142
|
+
#
|
143
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
144
|
+
# @param body [Hash]: Request body to be sent as json.
|
145
|
+
def commit params = {}, body = {}
|
146
|
+
container = Docker::API::Container.new.details(params[:container])
|
147
|
+
return container if [404, 301].include? container.status
|
148
|
+
@connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: container.json["Config"].merge(body).to_json)
|
149
|
+
end
|
150
|
+
|
151
|
+
##
|
152
|
+
# Create an image by either pulling it from a registry or importing it.
|
153
|
+
#
|
154
|
+
# Docker API: POST /images/create
|
155
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageCreate
|
156
|
+
#
|
157
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
158
|
+
# @param authentication [Hash]: Authentication parameters.
|
159
|
+
# @param &block: Replace the default output to stdout behavior.
|
160
|
+
def create params = {}, authentication = {}, &block
|
161
|
+
request = {method: :post, path: build_path("/images/create", params), response_block: block_given? ? block : default_streamer }
|
162
|
+
if params.has_key? :fromSrc and !params[:fromSrc].match(/^(http|https)/) # then it's using a tar file
|
163
|
+
path = params[:fromSrc]
|
164
|
+
params[:fromSrc] = "-"
|
165
|
+
default_reader(path, build_path("/images/create", params))
|
166
|
+
else
|
167
|
+
request[:headers] = { "X-Registry-Auth" => auth_encoder(authentication) } if authentication.keys.size > 0
|
168
|
+
@connection.request(request)
|
150
169
|
end
|
151
170
|
end
|
171
|
+
|
172
|
+
##
|
173
|
+
# Build an image from a tar archive with a Dockerfile in it.
|
174
|
+
#
|
175
|
+
# Docker API: POST /build
|
176
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageBuild
|
177
|
+
#
|
178
|
+
# @param path [String]: Path to the tar file.
|
179
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
180
|
+
# @param authentication [Hash]: Authentication parameters.
|
181
|
+
# @param &block: Replace the default output to stdout behavior.
|
182
|
+
def build path, params = {}, authentication = {}, &block
|
183
|
+
raise Docker::API::Error.new("Expected path or params[:remote]") unless path || params[:remote]
|
184
|
+
|
185
|
+
headers = {"Content-type": "application/x-tar"}
|
186
|
+
headers.merge!({"X-Registry-Config": auth_encoder(authentication) }) if authentication.keys.size > 0
|
187
|
+
|
188
|
+
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 : default_streamer)
|
190
|
+
else
|
191
|
+
default_reader(path, build_path("/build", params), headers)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
##
|
196
|
+
# Delete builder cache.
|
197
|
+
#
|
198
|
+
# Docker API: POST /build/prune
|
199
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/BuildPrune
|
200
|
+
#
|
201
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
202
|
+
def delete_cache params = {}
|
203
|
+
@connection.post(build_path("/build/prune", params))
|
204
|
+
end
|
152
205
|
end
|