docker-api 1.1.1 → 1.1.2

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.
data/.cane CHANGED
@@ -1 +1 @@
1
- --abc-max 16
1
+ --abc-max 12
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  docker-api
2
2
  ==========
3
- [![travis-ci](https://travis-ci.org/swipely/docker-api.png?branch=master)](https://travis-ci.org/swipely/docker-api) [![Code Climate](https://codeclimate.com/github/swipely/docker-api.png)](https://codeclimate.com/github/swipely/docker-api)
3
+ [![Gem Version](https://badge.fury.io/rb/docker-api.png)](http://badge.fury.io/rb/docker-api) [![travis-ci](https://travis-ci.org/swipely/docker-api.png?branch=master)](https://travis-ci.org/swipely/docker-api) [![Code Climate](https://codeclimate.com/github/swipely/docker-api.png)](https://codeclimate.com/github/swipely/docker-api) [![Dependency Status](https://gemnasium.com/swipely/docker-api.png)](https://gemnasium.com/swipely/docker-api)
4
4
 
5
5
  This gem provides an object-oriented interface to the [Docker Remote API](http://docs.docker.io/en/latest/api/docker_remote_api_v1.2/). Every method listed there is implemented, with the exception of attaching to the STDIN of a Container. At the time of this writing, docker-api is meant to interface with Docker version 0.4.6.
6
6
 
@@ -173,8 +173,9 @@ end
173
173
  container.changes
174
174
  # => [{'Path'=>'/dev', 'Kind'=>0}, {'Path'=>'/dev/kmsg', 'Kind'=>1}]
175
175
 
176
- # Wait for the current command to finish executing.
177
- container.wait
176
+ # Wait for the current command to finish executing. If an argument is given,
177
+ # will timeout after that number of seconds. The default is one minute.
178
+ container.wait(15)
178
179
  # => {'StatusCode'=>0}
179
180
 
180
181
  # Attach to the Container. Currently, the below options are the only valid ones.
@@ -33,6 +33,8 @@ class Docker::Connection
33
33
  raise ClientError, ex.message
34
34
  rescue Excon::Errors::InternalServerError => ex
35
35
  raise ServerError, ex.message
36
+ rescue Excon::Errors::Timeout => ex
37
+ raise TimeoutError, ex.message
36
38
  end
37
39
 
38
40
  # Delegate all HTTP methods to the #request.
@@ -2,6 +2,7 @@
2
2
  # is cached so that the information is always up to date.
3
3
  class Docker::Container
4
4
  include Docker::Model
5
+ include Docker::Error
5
6
 
6
7
  set_resource_prefix '/containers'
7
8
 
@@ -13,8 +14,6 @@ class Docker::Container
13
14
 
14
15
  # Get more information about the Container.
15
16
  request :get, :json
16
- # Wait for the current command to finish executing.
17
- request :post, :wait
18
17
  # Start the Container.
19
18
  request :post, :start
20
19
  # Inspect the Container's changes to the filesysetem
@@ -26,6 +25,12 @@ class Docker::Container
26
25
  # Restart the Container
27
26
  request :post, :restart
28
27
 
28
+ # Wait for the current command to finish executing.
29
+ def wait(time = 60)
30
+ resp = connection.post("/containers/#{id}/wait", nil, :read_timeout => time)
31
+ Docker::Util.parse_json(resp)
32
+ end
33
+
29
34
  # Export the Container as a tar.
30
35
  def export(&block)
31
36
  connection.get("/containers/#{id}/export", nil, :response_block => block)
data/lib/docker/error.rb CHANGED
@@ -19,4 +19,7 @@ module Docker::Error
19
19
 
20
20
  # Raised when there is an incompatible version of Docker.
21
21
  class VersionError < DockerError; end
22
+
23
+ # Raised when a request times out.
24
+ class TimeoutError < DockerError; end
22
25
  end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  # The version of the docker-api gem.
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.2'
4
4
 
5
5
  # The version of the compatible Docker remote API.
6
6
  API_VERSION = '1.3'
@@ -144,6 +144,22 @@ describe Docker::Container do
144
144
  it 'waits for the command to finish', :vcr do
145
145
  subject.wait['StatusCode'].should == 64
146
146
  end
147
+
148
+ context 'when an argument is given' do
149
+ subject { described_class.create('Cmd' => %w[sleep 5],
150
+ 'Image' => 'base') }
151
+
152
+ it 'sets the :read_timeout to that amount of time', :vcr do
153
+ subject.wait(6)['StatusCode'].should be_zero
154
+ end
155
+
156
+ context 'and a command runs for too long' do
157
+ it 'raises a ServerError', :vcr do
158
+ pending "VCR doesn't like to record errors"
159
+ expect { subject.wait(4) }.to raise_error(Docker::Error::TimeoutError)
160
+ end
161
+ end
162
+ end
147
163
  end
148
164
 
149
165
  describe '#commit' do
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:4243/v1.3/containers/create
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"Cmd":["sleep","5"],"Image":"base"}'
9
+ headers:
10
+ Content-Type:
11
+ - text/plain
12
+ User-Agent:
13
+ - Docker-Client/0.4.6
14
+ response:
15
+ status:
16
+ code: 201
17
+ message: ''
18
+ headers:
19
+ !binary "Q29udGVudC1UeXBl":
20
+ - !binary |-
21
+ dGV4dC9wbGFpbjsgY2hhcnNldD11dGYtOA==
22
+ !binary "Q29udGVudC1MZW5ndGg=":
23
+ - !binary |-
24
+ MjE=
25
+ !binary "RGF0ZQ==":
26
+ - !binary |-
27
+ VGh1LCAyNyBKdW4gMjAxMyAxODo0MDoxMiBHTVQ=
28
+ body:
29
+ encoding: US-ASCII
30
+ string: ! '{"Id":"f09a4f65f2d7"}'
31
+ http_version:
32
+ recorded_at: Thu, 27 Jun 2013 18:40:12 GMT
33
+ - request:
34
+ method: post
35
+ uri: http://localhost:4243/v1.3/containers/f09a4f65f2d7/start
36
+ body:
37
+ encoding: US-ASCII
38
+ string: ''
39
+ headers:
40
+ Content-Type:
41
+ - text/plain
42
+ User-Agent:
43
+ - Docker-Client/0.4.6
44
+ response:
45
+ status:
46
+ code: 204
47
+ message: ''
48
+ headers:
49
+ !binary "Q29udGVudC1UeXBl":
50
+ - !binary |-
51
+ dGV4dC9wbGFpbjsgY2hhcnNldD11dGYtOA==
52
+ !binary "Q29udGVudC1MZW5ndGg=":
53
+ - !binary |-
54
+ MA==
55
+ !binary "RGF0ZQ==":
56
+ - !binary |-
57
+ VGh1LCAyNyBKdW4gMjAxMyAxODo0MDoxMiBHTVQ=
58
+ body:
59
+ encoding: US-ASCII
60
+ string: ''
61
+ http_version:
62
+ recorded_at: Thu, 27 Jun 2013 18:40:12 GMT
63
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,93 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:4243/v1.3/containers/create
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"Cmd":["sleep","5"],"Image":"base"}'
9
+ headers:
10
+ Content-Type:
11
+ - text/plain
12
+ User-Agent:
13
+ - Docker-Client/0.4.6
14
+ response:
15
+ status:
16
+ code: 201
17
+ message: ''
18
+ headers:
19
+ !binary "Q29udGVudC1UeXBl":
20
+ - !binary |-
21
+ dGV4dC9wbGFpbjsgY2hhcnNldD11dGYtOA==
22
+ !binary "Q29udGVudC1MZW5ndGg=":
23
+ - !binary |-
24
+ MjE=
25
+ !binary "RGF0ZQ==":
26
+ - !binary |-
27
+ VGh1LCAyNyBKdW4gMjAxMyAxODowMjo0NiBHTVQ=
28
+ body:
29
+ encoding: US-ASCII
30
+ string: ! '{"Id":"19068c1d921a"}'
31
+ http_version:
32
+ recorded_at: Thu, 27 Jun 2013 18:02:46 GMT
33
+ - request:
34
+ method: post
35
+ uri: http://localhost:4243/v1.3/containers/19068c1d921a/start
36
+ body:
37
+ encoding: US-ASCII
38
+ string: ''
39
+ headers:
40
+ Content-Type:
41
+ - text/plain
42
+ User-Agent:
43
+ - Docker-Client/0.4.6
44
+ response:
45
+ status:
46
+ code: 204
47
+ message: ''
48
+ headers:
49
+ !binary "Q29udGVudC1UeXBl":
50
+ - !binary |-
51
+ dGV4dC9wbGFpbjsgY2hhcnNldD11dGYtOA==
52
+ !binary "Q29udGVudC1MZW5ndGg=":
53
+ - !binary |-
54
+ MA==
55
+ !binary "RGF0ZQ==":
56
+ - !binary |-
57
+ VGh1LCAyNyBKdW4gMjAxMyAxODowMjo0NiBHTVQ=
58
+ body:
59
+ encoding: US-ASCII
60
+ string: ''
61
+ http_version:
62
+ recorded_at: Thu, 27 Jun 2013 18:02:46 GMT
63
+ - request:
64
+ method: post
65
+ uri: http://localhost:4243/v1.3/containers/19068c1d921a/wait
66
+ body:
67
+ encoding: US-ASCII
68
+ string: ''
69
+ headers:
70
+ Content-Type:
71
+ - text/plain
72
+ User-Agent:
73
+ - Docker-Client/0.4.6
74
+ response:
75
+ status:
76
+ code: 200
77
+ message: ''
78
+ headers:
79
+ !binary "Q29udGVudC1UeXBl":
80
+ - !binary |-
81
+ YXBwbGljYXRpb24vanNvbg==
82
+ !binary "Q29udGVudC1MZW5ndGg=":
83
+ - !binary |-
84
+ MTY=
85
+ !binary "RGF0ZQ==":
86
+ - !binary |-
87
+ VGh1LCAyNyBKdW4gMjAxMyAxODowMjo1MSBHTVQ=
88
+ body:
89
+ encoding: US-ASCII
90
+ string: ! '{"StatusCode":0}'
91
+ http_version:
92
+ recorded_at: Thu, 27 Jun 2013 18:02:51 GMT
93
+ recorded_with: VCR 2.5.0
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.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -201,6 +201,8 @@ files:
201
201
  - spec/vcr/Docker_Container/_start/starts_the_container.yml
202
202
  - spec/vcr/Docker_Container/_stop/stops_the_container.yml
203
203
  - spec/vcr/Docker_Container/_wait/waits_for_the_command_to_finish.yml
204
+ - spec/vcr/Docker_Container/_wait/when_an_argument_is_given/and_a_command_runs_for_too_long/raises_a_ServerError.yml
205
+ - spec/vcr/Docker_Container/_wait/when_an_argument_is_given/sets_the_read_timeout_to_that_amount_of_time.yml
204
206
  - spec/vcr/Docker_Image/_all/materializes_each_Image_into_a_Docker_Image.yml
205
207
  - spec/vcr/Docker_Image/_build/with_a_valid_Dockerfile/builds_an_image.yml
206
208
  - spec/vcr/Docker_Image/_build/with_an_invalid_Dockerfile/throws_a_UnexpectedResponseError.yml
@@ -263,6 +265,8 @@ test_files:
263
265
  - spec/vcr/Docker_Container/_start/starts_the_container.yml
264
266
  - spec/vcr/Docker_Container/_stop/stops_the_container.yml
265
267
  - spec/vcr/Docker_Container/_wait/waits_for_the_command_to_finish.yml
268
+ - spec/vcr/Docker_Container/_wait/when_an_argument_is_given/and_a_command_runs_for_too_long/raises_a_ServerError.yml
269
+ - spec/vcr/Docker_Container/_wait/when_an_argument_is_given/sets_the_read_timeout_to_that_amount_of_time.yml
266
270
  - spec/vcr/Docker_Image/_all/materializes_each_Image_into_a_Docker_Image.yml
267
271
  - spec/vcr/Docker_Image/_build/with_a_valid_Dockerfile/builds_an_image.yml
268
272
  - spec/vcr/Docker_Image/_build/with_an_invalid_Dockerfile/throws_a_UnexpectedResponseError.yml