dockerapi 0.5.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +65 -11
- data/Gemfile.lock +1 -1
- data/README.md +186 -86
- data/bin/setup +17 -3
- data/lib/docker/api/base.rb +12 -10
- data/lib/docker/api/connection.rb +4 -10
- data/lib/docker/api/container.rb +64 -53
- data/lib/docker/api/exec.rb +46 -0
- data/lib/docker/api/image.rb +51 -43
- data/lib/docker/api/network.rb +29 -18
- data/lib/docker/api/node.rb +38 -0
- data/lib/docker/api/swarm.rb +51 -0
- data/lib/docker/api/system.rb +14 -13
- data/lib/docker/api/version.rb +1 -1
- data/lib/docker/api/volume.rb +26 -14
- data/lib/dockerapi.rb +3 -0
- metadata +5 -2
data/bin/setup
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
set -euo pipefail
|
3
3
|
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
4
|
+
#set -vx
|
7
5
|
|
8
6
|
# Do any other automated setup that you need to do here
|
7
|
+
if [ $USER == 'root' ]
|
8
|
+
then
|
9
|
+
echo "Enabling TCP port 2375 for external connection to Docker"
|
10
|
+
echo '{"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]}' > /etc/docker/daemon.json
|
11
|
+
mkdir -p /etc/systemd/system/docker.service.d
|
12
|
+
echo '[Service]' > /etc/systemd/system/docker.service.d/override.conf
|
13
|
+
echo 'ExecStart=' >> /etc/systemd/system/docker.service.d/override.conf
|
14
|
+
echo 'ExecStart=/usr/bin/dockerd' >> /etc/systemd/system/docker.service.d/override.conf
|
15
|
+
systemctl daemon-reload
|
16
|
+
systemctl restart docker.service
|
17
|
+
echo "Done!"
|
18
|
+
else
|
19
|
+
echo "Running bundle install"
|
20
|
+
bundle install
|
21
|
+
echo "Run this script as root for further configurations"
|
22
|
+
fi
|
data/lib/docker/api/base.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
module Docker
|
2
2
|
module API
|
3
3
|
class Base
|
4
|
+
|
5
|
+
def initialize connection = nil
|
6
|
+
raise Docker::API::Error.new("Expect connection to be a Docker::API::Connection class") if connection != nil && !connection.is_a?(Docker::API::Connection)
|
7
|
+
@connection = connection || Docker::API::Connection.new
|
8
|
+
end
|
4
9
|
|
5
10
|
private
|
6
11
|
|
7
|
-
def
|
12
|
+
def base_path # TODO: this method to be removed?
|
8
13
|
"/"
|
9
14
|
end
|
10
15
|
|
11
|
-
def
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.validate error, permitted, params
|
16
|
+
def validate error, permitted, params
|
17
|
+
return if params[:skip_validation]
|
16
18
|
unpermitted = params.keys.map(&:to_s) - permitted.map(&:to_s)
|
17
19
|
raise error.new(permitted, unpermitted) if unpermitted.size > 0
|
18
20
|
end
|
@@ -20,14 +22,14 @@ module Docker
|
|
20
22
|
## Converts Ruby Hash into query parameters
|
21
23
|
## In general, the format is key=value
|
22
24
|
## If value is another Hash, it should keep a json syntax {key:value}
|
23
|
-
def
|
25
|
+
def hash_to_params h
|
24
26
|
p = []
|
25
|
-
h.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
|
27
|
+
h.delete_if{ | k, v | k.to_s == "skip_validation" }.each { |k,v| p.push( v.is_a?(Hash) ? "#{k}=#{v.to_json}" : "#{k}=#{v}") }
|
26
28
|
p.join("&").gsub(" ","")
|
27
29
|
end
|
28
30
|
|
29
|
-
def
|
30
|
-
p = path.is_a?(Array) ? ([base_path] << path).join("/") : path
|
31
|
+
def build_path path, params = {}
|
32
|
+
p = path.is_a?(Array) ? ([base_path] << path).join("/") : path # TODO: this line to be removed?
|
31
33
|
params.size > 0 ? [p, hash_to_params(params)].join("?") : p
|
32
34
|
end
|
33
35
|
|
@@ -1,24 +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
11
|
|
19
|
-
|
20
|
-
|
21
|
-
|
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)
|
22
16
|
end
|
23
17
|
|
24
18
|
end
|
data/lib/docker/api/container.rb
CHANGED
@@ -5,111 +5,107 @@ module Docker
|
|
5
5
|
|
6
6
|
class Container < Docker::API::Base
|
7
7
|
|
8
|
-
def
|
9
|
-
"/containers"
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.list params = {}
|
8
|
+
def list params = {}
|
13
9
|
validate Docker::API::InvalidParameter, [:all, :limit, :size, :filters], params
|
14
|
-
connection.get(build_path(["json"], params))
|
10
|
+
@connection.get(build_path(["json"], params))
|
15
11
|
end
|
16
12
|
|
17
|
-
def
|
13
|
+
def details name, params = {}
|
18
14
|
validate Docker::API::InvalidParameter, [:size], params
|
19
|
-
connection.get(build_path([name, "json"], params))
|
15
|
+
@connection.get(build_path([name, "json"], params))
|
20
16
|
end
|
21
17
|
|
22
|
-
def
|
18
|
+
def top name, params = {}
|
23
19
|
validate Docker::API::InvalidParameter, [:ps_args], params
|
24
|
-
connection.get(build_path([name, "top"], params))
|
20
|
+
@connection.get(build_path([name, "top"], params))
|
25
21
|
end
|
26
22
|
|
27
|
-
def
|
28
|
-
connection.get(build_path([name, "changes"]))
|
23
|
+
def changes name
|
24
|
+
@connection.get(build_path([name, "changes"]))
|
29
25
|
end
|
30
26
|
|
31
|
-
def
|
27
|
+
def start name, params = {}
|
32
28
|
validate Docker::API::InvalidParameter, [:detachKeys], params
|
33
|
-
connection.post(build_path([name, "start"], params))
|
29
|
+
@connection.post(build_path([name, "start"], params))
|
34
30
|
end
|
35
31
|
|
36
|
-
def
|
32
|
+
def stop name, params = {}
|
37
33
|
validate Docker::API::InvalidParameter, [:t], params
|
38
|
-
connection.post(build_path([name, "stop"], params))
|
34
|
+
@connection.post(build_path([name, "stop"], params))
|
39
35
|
end
|
40
36
|
|
41
|
-
def
|
37
|
+
def restart name, params = {}
|
42
38
|
validate Docker::API::InvalidParameter, [:t], params
|
43
|
-
connection.post(build_path([name, "restart"], params))
|
39
|
+
@connection.post(build_path([name, "restart"], params))
|
44
40
|
end
|
45
41
|
|
46
|
-
def
|
42
|
+
def kill name, params = {}
|
47
43
|
validate Docker::API::InvalidParameter, [:signal], params
|
48
|
-
connection.post(build_path([name, "kill"], params))
|
44
|
+
@connection.post(build_path([name, "kill"], params))
|
49
45
|
end
|
50
46
|
|
51
|
-
def
|
47
|
+
def wait name, params = {}
|
52
48
|
validate Docker::API::InvalidParameter, [:condition], params
|
53
|
-
connection.post(build_path([name, "wait"], params))
|
49
|
+
@connection.post(build_path([name, "wait"], params))
|
54
50
|
end
|
55
51
|
|
56
|
-
def
|
52
|
+
def update name, body = {}
|
57
53
|
validate Docker::API::InvalidRequestBody, Docker::API::UpdateBody, body
|
58
|
-
connection.post
|
54
|
+
@connection.request(method: :post, path: build_path([name, "update"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
59
55
|
end
|
60
56
|
|
61
|
-
def
|
57
|
+
def rename name, params = {}
|
62
58
|
validate Docker::API::InvalidParameter, [:name], params
|
63
|
-
connection.post(build_path([name, "rename"], params))
|
59
|
+
@connection.post(build_path([name, "rename"], params))
|
64
60
|
end
|
65
61
|
|
66
|
-
def
|
62
|
+
def resize name, params = {}
|
67
63
|
validate Docker::API::InvalidParameter, [:w, :h], params
|
68
|
-
connection.post(build_path([name, "resize"], params))
|
64
|
+
@connection.post(build_path([name, "resize"], params))
|
69
65
|
end
|
70
66
|
|
71
|
-
def
|
67
|
+
def prune params = {}
|
72
68
|
validate Docker::API::InvalidParameter, [:filters], params
|
73
|
-
connection.post(build_path(["prune"], params))
|
69
|
+
@connection.post(build_path(["prune"], params))
|
74
70
|
end
|
75
71
|
|
76
|
-
def
|
77
|
-
connection.post(build_path([name, "pause"]))
|
72
|
+
def pause name
|
73
|
+
@connection.post(build_path([name, "pause"]))
|
78
74
|
end
|
79
75
|
|
80
|
-
def
|
81
|
-
connection.post(build_path([name, "unpause"]))
|
76
|
+
def unpause name
|
77
|
+
@connection.post(build_path([name, "unpause"]))
|
82
78
|
end
|
83
79
|
|
84
|
-
def
|
80
|
+
def remove name, params = {}
|
85
81
|
validate Docker::API::InvalidParameter, [:v, :force, :link], params
|
86
|
-
connection.delete(build_path([name]))
|
82
|
+
@connection.delete(build_path([name]))
|
87
83
|
end
|
88
84
|
|
89
|
-
def
|
85
|
+
def logs name, params = {}
|
90
86
|
validate Docker::API::InvalidParameter, [:follow, :stdout, :stderr, :since, :until, :timestamps, :tail], params
|
91
87
|
|
92
88
|
path = build_path([name, "logs"], params)
|
93
89
|
|
94
90
|
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 })
|
91
|
+
@connection.request(method: :get, path: path , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
96
92
|
else
|
97
|
-
connection.get(path)
|
93
|
+
@connection.get(path)
|
98
94
|
end
|
99
95
|
end
|
100
96
|
|
101
|
-
def
|
97
|
+
def attach name, params = {}
|
102
98
|
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 })
|
99
|
+
@connection.request(method: :post, path: build_path([name, "attach"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
104
100
|
end
|
105
101
|
|
106
|
-
def
|
102
|
+
def create params = {}, body = {}
|
107
103
|
validate Docker::API::InvalidParameter, [:name], params
|
108
104
|
validate Docker::API::InvalidRequestBody, Docker::API::CreateBody, body
|
109
|
-
connection.post
|
105
|
+
@connection.request(method: :post, path: build_path(["create"], params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
110
106
|
end
|
111
107
|
|
112
|
-
def
|
108
|
+
def stats name, params = {}
|
113
109
|
validate Docker::API::InvalidParameter, [:stream], params
|
114
110
|
path = build_path([name, "stats"], params)
|
115
111
|
|
@@ -117,43 +113,58 @@ module Docker
|
|
117
113
|
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
118
114
|
puts chunk
|
119
115
|
end
|
120
|
-
connection.request(method: :get, path: path , response_block: streamer)
|
116
|
+
@connection.request(method: :get, path: path , response_block: streamer)
|
121
117
|
else
|
122
|
-
connection.get(path)
|
118
|
+
@connection.get(path)
|
123
119
|
end
|
124
120
|
end
|
125
121
|
|
126
|
-
def
|
127
|
-
response =
|
122
|
+
def export name, path = "exported_container"
|
123
|
+
response = self.details(name)
|
128
124
|
if response.status == 200
|
129
125
|
file = File.open(File.expand_path(path), "wb")
|
130
126
|
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
131
127
|
file.write(chunk)
|
132
128
|
end
|
133
|
-
response = connection.request(method: :get, path: build_path([name, "export"]) , response_block: streamer)
|
129
|
+
response = @connection.request(method: :get, path: build_path([name, "export"]) , response_block: streamer)
|
134
130
|
file.close
|
135
131
|
end
|
136
132
|
response
|
137
133
|
end
|
138
134
|
|
139
|
-
def
|
135
|
+
def archive name, file, params = {}
|
140
136
|
validate Docker::API::InvalidParameter, [:path, :noOverwriteDirNonDir, :copyUIDGID], params
|
141
137
|
|
142
138
|
begin # File exists on disk, send it to container
|
143
139
|
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} )
|
140
|
+
response = @connection.request(method: :put, path: build_path([name, "archive"], params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
145
141
|
file.close
|
146
142
|
rescue Errno::ENOENT # File doesnt exist, get it from container
|
147
|
-
response = connection.head(build_path([name, "archive"], params))
|
143
|
+
response = @connection.head(build_path([name, "archive"], params))
|
148
144
|
if response.status == 200 # file exists in container
|
149
145
|
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) })
|
146
|
+
response = @connection.request(method: :get, path: build_path([name, "archive"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
|
151
147
|
file.close
|
152
148
|
end
|
153
149
|
end
|
154
150
|
response
|
155
151
|
end
|
156
152
|
|
153
|
+
#################################################
|
154
|
+
# Items in this area to be removed before 1.0.0 #
|
155
|
+
#################################################
|
156
|
+
def base_path
|
157
|
+
"/containers"
|
158
|
+
end
|
159
|
+
|
160
|
+
def inspect *args
|
161
|
+
return super.inspect if args.size == 0
|
162
|
+
warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
|
163
|
+
name, params = args[0], args[1] || {}
|
164
|
+
details(name, params)
|
165
|
+
end
|
166
|
+
#################################################
|
167
|
+
|
157
168
|
end
|
158
169
|
end
|
159
170
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Docker
|
2
|
+
module API
|
3
|
+
class Exec < Docker::API::Base
|
4
|
+
|
5
|
+
def create name, body = {}
|
6
|
+
validate Docker::API::InvalidRequestBody, [:AttachStdin, :AttachStdout, :AttachStderr, :DetachKeys, :Tty, :Env, :Cmd, :Privileged, :User, :WorkingDir], body
|
7
|
+
@connection.request(method: :post, path: "/containers/#{name}/exec", headers: {"Content-Type": "application/json"}, body: body.to_json )
|
8
|
+
end
|
9
|
+
|
10
|
+
def start name, body = {}
|
11
|
+
validate Docker::API::InvalidRequestBody, [:Detach, :Tty], body
|
12
|
+
|
13
|
+
stream = ""
|
14
|
+
response = @connection.request(method: :post,
|
15
|
+
path: "/exec/#{name}/start",
|
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
|
23
|
+
|
24
|
+
def resize name, params = {}
|
25
|
+
validate Docker::API::InvalidParameter, [:w, :h], params
|
26
|
+
@connection.post(build_path("/exec/#{name}/resize", params))
|
27
|
+
end
|
28
|
+
|
29
|
+
def details name
|
30
|
+
@connection.get("/exec/#{name}/json")
|
31
|
+
end
|
32
|
+
|
33
|
+
#################################################
|
34
|
+
# Items in this area to be removed before 1.0.0 #
|
35
|
+
#################################################
|
36
|
+
def inspect *args
|
37
|
+
return super.inspect if args.size == 0
|
38
|
+
warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
|
39
|
+
name = args[0]
|
40
|
+
details(name)
|
41
|
+
end
|
42
|
+
#################################################
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/docker/api/image.rb
CHANGED
@@ -7,113 +7,107 @@ 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
|
11
|
-
"
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.inspect name
|
15
|
-
connection.get(build_path([name, "json"]))
|
10
|
+
def details name
|
11
|
+
@connection.get(build_path([name, "json"]))
|
16
12
|
end
|
17
13
|
|
18
|
-
def
|
19
|
-
connection.get(build_path([name, "history"]))
|
14
|
+
def history name
|
15
|
+
@connection.get(build_path([name, "history"]))
|
20
16
|
end
|
21
17
|
|
22
|
-
def
|
18
|
+
def list params = {}
|
23
19
|
validate Docker::API::InvalidParameter, [:all, :filters, :digests], params
|
24
|
-
connection.get(build_path(["json"], params))
|
20
|
+
@connection.get(build_path(["json"], params))
|
25
21
|
end
|
26
22
|
|
27
|
-
def
|
23
|
+
def search params = {}
|
28
24
|
validate Docker::API::InvalidParameter, [:term, :limit, :filters], params
|
29
|
-
connection.get(build_path(["search"], params))
|
25
|
+
@connection.get(build_path(["search"], params))
|
30
26
|
end
|
31
27
|
|
32
|
-
def
|
28
|
+
def tag name, params = {}
|
33
29
|
validate Docker::API::InvalidParameter, [:repo, :tag], params
|
34
|
-
connection.post(build_path([name, "tag"], params))
|
30
|
+
@connection.post(build_path([name, "tag"], params))
|
35
31
|
end
|
36
32
|
|
37
|
-
def
|
33
|
+
def prune params = {}
|
38
34
|
validate Docker::API::InvalidParameter, [:filters], params
|
39
|
-
connection.post(build_path(["prune"], params))
|
35
|
+
@connection.post(build_path(["prune"], params))
|
40
36
|
end
|
41
37
|
|
42
|
-
def
|
38
|
+
def remove name, params = {}
|
43
39
|
validate Docker::API::InvalidParameter, [:force, :noprune], params
|
44
|
-
connection.delete(build_path([name], params))
|
40
|
+
@connection.delete(build_path([name], params))
|
45
41
|
end
|
46
42
|
|
47
|
-
def
|
43
|
+
def export name, path = "exported_image"
|
48
44
|
file = File.open("/tmp/exported-image", "wb")
|
49
45
|
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
50
46
|
file.write(chunk)
|
51
47
|
end
|
52
|
-
response = connection.request(method: :get, path: build_path([name, "get"]) , response_block: streamer)
|
48
|
+
response = @connection.request(method: :get, path: build_path([name, "get"]) , response_block: streamer)
|
53
49
|
file.close
|
54
50
|
response.status == 200 ? FileUtils.mv("/tmp/exported-image", File.expand_path(path)) : FileUtils.rm("/tmp/exported-image")
|
55
51
|
response
|
56
52
|
end
|
57
53
|
|
58
|
-
def
|
54
|
+
def import path, params = {}
|
59
55
|
validate Docker::API::InvalidParameter, [:quiet], params
|
60
56
|
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} )
|
57
|
+
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
58
|
file.close
|
63
59
|
response
|
64
60
|
end
|
65
61
|
|
66
|
-
def
|
62
|
+
def push name, params = {}, authentication = {}
|
67
63
|
validate Docker::API::InvalidParameter, [:tag], params
|
68
64
|
|
69
65
|
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 } )
|
66
|
+
@connection.request(method: :post, path: build_path([name, "push"], params), headers: { "X-Registry-Auth" => Base64.urlsafe_encode64(authentication.to_json.to_s).chomp } )
|
73
67
|
else
|
74
|
-
|
68
|
+
raise Docker::API::Error.new("Provide authentication parameters to push an image")
|
75
69
|
end
|
76
70
|
end
|
77
71
|
|
78
|
-
def
|
72
|
+
def commit params = {}, body = {}
|
79
73
|
validate Docker::API::InvalidParameter, [:container, :repo, :tag, :comment, :author, :pause, :changes], params
|
80
74
|
validate Docker::API::InvalidRequestBody, Docker::API::CommitBody, body
|
81
|
-
container = Docker::API::Container.
|
75
|
+
container = Docker::API::Container.new.details(params[:container])
|
82
76
|
return container if [404, 301].include? container.status
|
83
77
|
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)
|
78
|
+
@connection.request(method: :post, path: build_path("/commit", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
85
79
|
end
|
86
80
|
|
87
|
-
def
|
81
|
+
def create params = {}, authentication = {}
|
88
82
|
validate Docker::API::InvalidParameter, [:fromImage, :fromSrc, :repo, :tag, :message, :platform], params
|
89
83
|
|
90
84
|
if authentication.keys.size > 0
|
91
|
-
auth = Docker::API::System.auth(authentication)
|
85
|
+
auth = Docker::API::System.new.auth(authentication)
|
92
86
|
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 } )
|
87
|
+
@connection.request(method: :post, path: build_path(["create"], params), headers: { "X-Registry-Auth" => Base64.encode64(authentication.to_json.to_s).chomp } )
|
94
88
|
elsif params.has_key? :fromSrc
|
95
89
|
if params[:fromSrc].match(/^(http|https)/)
|
96
|
-
connection.request(method: :post, path: build_path(["create"], params))
|
90
|
+
@connection.request(method: :post, path: build_path(["create"], params))
|
97
91
|
else
|
98
92
|
file = File.open(File.expand_path(params[:fromSrc]), "r")
|
99
93
|
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} )
|
94
|
+
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
95
|
file.close
|
102
96
|
response
|
103
97
|
end
|
104
98
|
else
|
105
|
-
connection.post(build_path(["create"], params))
|
99
|
+
@connection.post(build_path(["create"], params))
|
106
100
|
end
|
107
101
|
end
|
108
102
|
|
109
|
-
def
|
103
|
+
def build path, params = {}, authentication = {}
|
110
104
|
raise Docker::API::Error.new("Expected path or params[:remote]") unless path || params[:remote]
|
111
105
|
validate Docker::API::InvalidParameter, Docker::API::BuildParams, params
|
112
106
|
|
113
107
|
header = {"Content-type": "application/x-tar"}
|
114
108
|
if authentication.keys.size > 0
|
115
109
|
authentication.each_key do |server|
|
116
|
-
auth = Docker::API::System.auth({username: authentication[server][:username] ,password:authentication[server][:password], serveraddress: server})
|
110
|
+
auth = Docker::API::System.new.auth({username: authentication[server][:username] ,password:authentication[server][:password], serveraddress: server})
|
117
111
|
return auth unless [200, 204].include? auth.status
|
118
112
|
end
|
119
113
|
header.merge!({"X-Registry-Config": Base64.urlsafe_encode64(authentication.to_json.to_s).chomp})
|
@@ -121,20 +115,34 @@ module Docker
|
|
121
115
|
|
122
116
|
begin
|
123
117
|
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})
|
118
|
+
response = @connection.request(method: :post, path: build_path("/build", params), headers: header, request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s})
|
125
119
|
file.close
|
126
120
|
rescue
|
127
|
-
response = connection.request(method: :post, path: build_path("/build", params), headers: header)
|
121
|
+
response = @connection.request(method: :post, path: build_path("/build", params), headers: header)
|
128
122
|
end
|
129
123
|
response
|
130
124
|
end
|
131
125
|
|
132
|
-
def
|
126
|
+
def delete_cache params = {}
|
133
127
|
validate Docker::API::InvalidParameter, [:all, "keep-storage", :filters], params
|
134
|
-
connection.post(build_path("/build/prune", params))
|
128
|
+
@connection.post(build_path("/build/prune", params))
|
135
129
|
end
|
136
130
|
|
137
|
-
|
131
|
+
#################################################
|
132
|
+
# Items in this area to be removed before 1.0.0 #
|
133
|
+
#################################################
|
134
|
+
def base_path
|
135
|
+
"/images"
|
136
|
+
end
|
138
137
|
|
138
|
+
def inspect *args
|
139
|
+
return super.inspect if args.size == 0
|
140
|
+
warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
|
141
|
+
name = args[0]
|
142
|
+
details(name)
|
143
|
+
end
|
144
|
+
#################################################
|
145
|
+
|
146
|
+
end
|
139
147
|
end
|
140
148
|
end
|