docker-api 1.30.2 → 1.31.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e2975a50b698d9d6a2a5fdaecd477f160677427
4
- data.tar.gz: e652feb4204f7e52d5877a388820dfd5a31c13e2
3
+ metadata.gz: a1d9749b7eea95cde9fd6bf9acf5f0f37417b2d0
4
+ data.tar.gz: 75453af3775a005fead451d161c2571cf2efb6d4
5
5
  SHA512:
6
- metadata.gz: ab26e9e3ba3f505ad0ac1ebb8b594913128473f7d7900c35886d867f041ba2dad1259162cdda3ce4bd51634107a44736667c82f3205f5d804f2ca35f0808ea63
7
- data.tar.gz: 4e5d8807fa2a6942662dea8a7e29e0fcc93deb4aa15fa097f29a9f265f765b961920df6276efc60c1e021d4d88fc9df81c35ab7c3aa90e7e61188e0381c644a6
6
+ metadata.gz: b0850b2386f8a5ab23a5a2c82b562eca9a7e0e2ffb0ced598003f59c91f57ed9c97a5f1f2f35f84f59d240e4763e168e2d9279815138bfaa2d7adb60164f2968
7
+ data.tar.gz: 77dbcc8610a471671e087c6f76c1530d664cf8afb76742cc1c86fd16240759f068e47dd21cab1e1a306d1985f39131c38e1e07a4606314aada69ed4f811c74c2
data/README.md CHANGED
@@ -372,6 +372,13 @@ Docker::Container.create(
372
372
  }
373
373
  )
374
374
 
375
+ # Stores a file with the given content in the container
376
+ container.store_file("/test", "Hello world")
377
+
378
+ # Reads a file from the container
379
+ container.read_file("/test")
380
+ # => "Hello world"
381
+
375
382
  # Export a Container. Since an export is typically at least 300M, chunks of the
376
383
  # export are yielded instead of just returning the whole thing.
377
384
  File.open('export.tar', 'w') do |f|
@@ -498,6 +505,9 @@ container.exec(command, wait: 120)
498
505
  container.delete(:force => true)
499
506
  # => nil
500
507
 
508
+ # Update the container.
509
+ container.update("CpuShares" => 50000")
510
+
501
511
  # Request a Container by ID or name.
502
512
  Docker::Container.get('500f53b25e6e')
503
513
  # => Docker::Container { :id => , :connection => Docker::Connection { :url => tcp://localhost, :options => {:port=>2375} } }
@@ -51,27 +51,29 @@ class Docker::Container
51
51
  # @param options [Hash] The options to pass to Docker::Exec
52
52
  #
53
53
  # @return [Docker::Exec] The Exec instance
54
- def exec(command, opts = {}, &block)
54
+ def exec(command, options = {}, &block)
55
55
  # Establish values
56
- tty = opts.delete(:tty) || false
57
- detach = opts.delete(:detach) || false
58
- user = opts.delete(:user)
59
- stdin = opts.delete(:stdin)
60
- stdout = opts.delete(:stdout) || !detach
61
- stderr = opts.delete(:stderr) || !detach
62
- wait = opts.delete(:wait)
56
+ tty = options.delete(:tty) || false
57
+ detach = options.delete(:detach) || false
58
+ user = options.delete(:user)
59
+ stdin = options.delete(:stdin)
60
+ stdout = options.delete(:stdout) || !detach
61
+ stderr = options.delete(:stderr) || !detach
62
+ wait = options.delete(:wait)
63
+
64
+ opts = {
65
+ 'Container' => self.id,
66
+ 'User' => user,
67
+ 'AttachStdin' => !!stdin,
68
+ 'AttachStdout' => stdout,
69
+ 'AttachStderr' => stderr,
70
+ 'Tty' => tty,
71
+ 'Cmd' => command
72
+ }.merge(options)
63
73
 
64
74
  # Create Exec Instance
65
75
  instance = Docker::Exec.create(
66
- {
67
- 'Container' => self.id,
68
- 'User' => user,
69
- 'AttachStdin' => !!stdin,
70
- 'AttachStdout' => stdout,
71
- 'AttachStderr' => stderr,
72
- 'Tty' => tty,
73
- 'Cmd' => command
74
- },
76
+ opts,
75
77
  self.connection
76
78
  )
77
79
 
@@ -169,6 +171,10 @@ class Docker::Container
169
171
  connection.post(path_for(:rename), query)
170
172
  end
171
173
 
174
+ def update(opts)
175
+ connection.post(path_for(:update), {}, body: opts.to_json)
176
+ end
177
+
172
178
  def streaming_logs(opts = {}, &block)
173
179
  stack_size = opts.delete('stack_size') || -1
174
180
  tty = opts.delete('tty') || opts.delete(:tty) || false
@@ -276,6 +282,31 @@ class Docker::Container
276
282
  self
277
283
  end
278
284
 
285
+ def read_file(path)
286
+ content = StringIO.new
287
+ archive_out(path) do |chunk|
288
+ content.write chunk
289
+ end
290
+
291
+ content.rewind
292
+
293
+ Gem::Package::TarReader.new(content) do |tar|
294
+ tar.each do |tarfile|
295
+ return tarfile.read
296
+ end
297
+ end
298
+ end
299
+
300
+ def store_file(path, file_content)
301
+ output_io = StringIO.new(
302
+ Docker::Util.create_tar(
303
+ path => file_content
304
+ )
305
+ )
306
+
307
+ archive_in_stream("/", overwrite: true) { output_io.read }
308
+ end
309
+
279
310
  # Create a new Container.
280
311
  def self.create(opts = {}, conn = Docker.connection)
281
312
  name = opts.delete('name')
data/lib/docker/image.rb CHANGED
@@ -6,8 +6,8 @@ class Docker::Image
6
6
  # an Image. This will not modify the Image, but rather create a new Container
7
7
  # to run the Image. If the image has an embedded config, no command is
8
8
  # necessary, but it will fail with 500 if no config is saved with the image
9
- def run(cmd=nil)
10
- opts = { 'Image' => self.id }
9
+ def run(cmd = nil, options = {})
10
+ opts = {'Image' => self.id}.merge(options)
11
11
  opts["Cmd"] = cmd.is_a?(String) ? cmd.split(/\s+/) : cmd
12
12
  begin
13
13
  Docker::Container.create(opts, connection)
@@ -128,6 +128,12 @@ class Docker::Image
128
128
  new(conn, hash)
129
129
  end
130
130
 
131
+ # Delete a specific image
132
+ def remove(id, opts = {}, conn = Docker.connection)
133
+ conn.delete("/images/#{id}", opts)
134
+ end
135
+ alias_method :delete, :remove
136
+
131
137
  # Save the raw binary representation or one or more Docker images
132
138
  #
133
139
  # @param names [String, Array#String] The image(s) you wish to save
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  # The version of the docker-api gem.
3
- VERSION = '1.30.2'
3
+ VERSION = '1.31.0'
4
4
 
5
5
  # The version of the compatible Docker remote API.
6
6
  API_VERSION = '1.16'
@@ -153,6 +153,30 @@ describe Docker::Container do
153
153
  end
154
154
  end
155
155
 
156
+ describe "#update", :docker_1_10 do
157
+ subject {
158
+ described_class.create({
159
+ "name" => "foo",
160
+ "Cmd" => %w[true],
161
+ "Image" => "debian:wheezy",
162
+ "HostConfig" => {
163
+ "CpuShares" => 60000
164
+ }
165
+ })
166
+ }
167
+
168
+ before { subject.start }
169
+ after(:each) { subject.tap(&:wait).remove }
170
+
171
+ it "updates the container" do
172
+ subject.refresh!
173
+ expect(subject.info.fetch("Config").fetch("CpuShares")).to eq 60000
174
+ subject.update("CpuShares" => 50000)
175
+ subject.refresh!
176
+ expect(subject.info.fetch("Config").fetch("CpuShares")).to eq 50000
177
+ end
178
+ end
179
+
156
180
  describe '#changes' do
157
181
  subject {
158
182
  described_class.create(
@@ -325,6 +349,37 @@ describe Docker::Container do
325
349
  end
326
350
  end
327
351
 
352
+ describe "#read_file", :docker_1_8 do
353
+ subject {
354
+ Docker::Container.create(
355
+ "Image" => "debian:wheezy",
356
+ "Cmd" => ["/bin/bash", "-c", "echo \"Hello world\" > /test"]
357
+ )
358
+ }
359
+
360
+ after { subject.remove }
361
+
362
+ before do
363
+ subject.start
364
+ subject.wait
365
+ end
366
+
367
+ it "reads contents from files" do
368
+ expect(subject.read_file("/test")).to eq "Hello world\n"
369
+ end
370
+ end
371
+
372
+ describe "#store_file", :docker_1_8 do
373
+ subject { Docker::Container.create('Image' => 'debian:wheezy', 'Cmd' => ["ls"]) }
374
+
375
+ after { subject.remove }
376
+
377
+ it "stores content in files" do
378
+ subject.store_file("/test", "Hello\nWorld")
379
+ expect(subject.read_file("/test")).to eq "Hello\nWorld"
380
+ end
381
+ end
382
+
328
383
  describe '#export' do
329
384
  subject { described_class.create('Cmd' => %w[/true],
330
385
  'Image' => 'tianon/true') }
@@ -33,6 +33,17 @@ describe Docker::Image do
33
33
  end
34
34
  end
35
35
 
36
+ context 'when using the class' do
37
+ let(:id) { subject.id }
38
+ subject { described_class.create('fromImage' => 'busybox:latest') }
39
+ after { described_class.create('fromImage' => 'busybox:latest') }
40
+
41
+ it 'removes the Image' do
42
+ Docker::Image.remove(id, force: true)
43
+ expect(Docker::Image.all.map(&:id)).to_not include(id)
44
+ end
45
+ end
46
+
36
47
  context 'when a valid tag is given' do
37
48
  it 'untags the Image'
38
49
  end
@@ -216,11 +227,18 @@ describe Docker::Image do
216
227
  end
217
228
 
218
229
  describe '#run' do
219
- subject { described_class.create('fromImage' => 'debian:wheezy') }
220
- let(:container) { subject.run(cmd).tap(&:wait) }
230
+ let(:cmd) { nil }
231
+ let(:options) { {} }
232
+
233
+ subject do
234
+ described_class.create(
235
+ {'fromImage' => 'debian:wheezy'})
236
+ end
237
+
238
+ let(:container) { subject.run(cmd, options).tap(&:wait) }
221
239
  let(:output) { container.streaming_logs(stdout: true) }
222
240
 
223
- context 'when the argument is a String' do
241
+ context 'when cmd is a String' do
224
242
  let(:cmd) { 'ls /lib64/' }
225
243
  after { container.remove }
226
244
 
@@ -229,7 +247,7 @@ describe Docker::Image do
229
247
  end
230
248
  end
231
249
 
232
- context 'when the argument is an Array' do
250
+ context 'when cmd is an Array' do
233
251
  let(:cmd) { %w[which pwd] }
234
252
  after { container.remove }
235
253
 
@@ -238,7 +256,7 @@ describe Docker::Image do
238
256
  end
239
257
  end
240
258
 
241
- context 'when the argument is nil' do
259
+ context 'when cmd is nil' do
242
260
  let(:cmd) { nil }
243
261
  context 'no command configured in image' do
244
262
  subject { described_class.create('fromImage' => 'swipely/base') }
@@ -257,6 +275,15 @@ describe Docker::Image do
257
275
  end
258
276
  end
259
277
  end
278
+
279
+ context 'when using cpu shares' do
280
+ let(:options) { { 'CpuShares' => 50 } }
281
+ after { container.remove }
282
+
283
+ it 'returns 50' do
284
+ expect(container.json["Config"]["CpuShares"]).to eq 50
285
+ end
286
+ end
260
287
  end
261
288
 
262
289
  describe '#save' do
data/spec/spec_helper.rb CHANGED
@@ -27,10 +27,15 @@ RSpec.configure do |config|
27
27
  when /1\.6/
28
28
  config.filter_run_excluding :docker_1_8 => true
29
29
  config.filter_run_excluding :docker_1_9 => true
30
+ config.filter_run_excluding :docker_1_10 => true
30
31
  when /1\.7/
31
32
  config.filter_run_excluding :docker_1_8 => true
32
33
  config.filter_run_excluding :docker_1_9 => true
34
+ config.filter_run_excluding :docker_1_10 => true
33
35
  when /1\.8/
34
36
  config.filter_run_excluding :docker_1_9 => true
37
+ config.filter_run_excluding :docker_1_10 => true
38
+ when /1\.9/
39
+ config.filter_run_excluding :docker_1_10 => true
35
40
  end
36
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.30.2
4
+ version: 1.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swipely, Inc.