docker-api 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +3 -3
- data/lib/docker/image.rb +16 -2
- data/lib/docker/version.rb +1 -1
- data/spec/docker/image_spec.rb +12 -4
- data/spec/vcr/Docker_Image/_insert/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/inserts_the_url_s_file_into_a_new_Image.yml +198 -0
- metadata +3 -4
- data/spec/vcr/Docker_Image/_insert/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/inserts_the_file.yml +0 -59
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -90,9 +90,9 @@ image.create!('fromRepo' => 'base', 'fromSrc' => '-')
|
|
90
90
|
image.created?
|
91
91
|
# => true
|
92
92
|
|
93
|
-
# Insert a file into an Image.
|
94
|
-
image.insert('path' => '/
|
95
|
-
# => {
|
93
|
+
# Insert a file into an Image. Returns a new Image that contains that file.
|
94
|
+
image.insert('path' => '/google', 'url' => 'http://google.com')
|
95
|
+
# => Docker::Image { :id => 11ef6c882, :connection => Docker::Connection { :url => http://localhost, :options => {:port=>4243} } }
|
96
96
|
|
97
97
|
# Tag an Image.
|
98
98
|
image.tag('repo' => 'base2', 'force' => true)
|
data/lib/docker/image.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# This class represents a Docker Image.
|
2
2
|
class Docker::Image
|
3
3
|
include Docker::Model
|
4
|
+
include Docker::Error
|
4
5
|
resource_prefix '/images'
|
5
6
|
|
6
7
|
create_request do |options|
|
@@ -20,11 +21,24 @@ class Docker::Image
|
|
20
21
|
docker_request :json, :get
|
21
22
|
# Push the Image to the Docker registry.
|
22
23
|
docker_request :push, :post
|
23
|
-
# Insert a file into the Image.
|
24
|
-
docker_request :insert, :post
|
25
24
|
# Get the history of the Image.
|
26
25
|
docker_request :history, :get
|
27
26
|
|
27
|
+
# Insert a file into the Image, returns a new Image that has that file.
|
28
|
+
def insert(query = {})
|
29
|
+
ensure_created!
|
30
|
+
body = self.connection.post(
|
31
|
+
:path => "/images/#{self.id}/insert",
|
32
|
+
:query => query,
|
33
|
+
:expects => (200..204)
|
34
|
+
).body
|
35
|
+
if (id = body.match(/{"Id":"([a-f0-9]+)"}\z/)).nil? || id[1].empty?
|
36
|
+
raise UnexpectedResponseError, "Could not find Id in '#{body}'"
|
37
|
+
else
|
38
|
+
Docker::Image.new(:id => id[1], :connection => self.connection)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
# Remove the Image from the server.
|
29
43
|
def remove
|
30
44
|
ensure_created!
|
data/lib/docker/version.rb
CHANGED
data/spec/docker/image_spec.rb
CHANGED
@@ -168,11 +168,19 @@ describe Docker::Image do
|
|
168
168
|
end
|
169
169
|
|
170
170
|
context 'when the HTTP response status is 200' do
|
171
|
-
|
171
|
+
subject { described_class.build('from base') }
|
172
|
+
let(:new_image) { subject.insert(:path => '/stallman',
|
173
|
+
:url => 'http://stallman.org') }
|
174
|
+
let(:container) { Docker::Container.new }
|
175
|
+
let(:ls_output) do
|
176
|
+
container.tap(&:start)
|
177
|
+
.attach(:stream => true, :stdout => true)
|
178
|
+
.split("\n")
|
179
|
+
end
|
180
|
+
before { container.create!('Image' => new_image.id, 'Cmd' => %w[ls /]) }
|
172
181
|
|
173
|
-
it 'inserts the file', :vcr do
|
174
|
-
|
175
|
-
.to_not raise_error
|
182
|
+
it 'inserts the url\'s file into a new Image', :vcr do
|
183
|
+
ls_output.should include('stallman')
|
176
184
|
end
|
177
185
|
end
|
178
186
|
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:4243/build
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ! "-------------RubyMultipartPost\r\nContent-Disposition: form-data;
|
9
|
+
name=\"Dockerfile\"; filename=\"Dockerfile\"\r\nContent-Length: 10\r\nContent-Type:
|
10
|
+
application/octet-stream\r\nContent-Transfer-Encoding: binary\r\n\r\nfrom
|
11
|
+
base\n\r\n-------------RubyMultipartPost--\r\n\r\n"
|
12
|
+
headers:
|
13
|
+
Accept:
|
14
|
+
- ! '*/*'
|
15
|
+
User-Agent:
|
16
|
+
- Ruby
|
17
|
+
Content-Type:
|
18
|
+
- multipart/form-data; boundary=-----------RubyMultipartPost
|
19
|
+
Content-Length:
|
20
|
+
- '251'
|
21
|
+
response:
|
22
|
+
status:
|
23
|
+
code: 200
|
24
|
+
message: OK
|
25
|
+
headers:
|
26
|
+
Content-Type:
|
27
|
+
- text/plain; charset=utf-8
|
28
|
+
Date:
|
29
|
+
- Thu, 20 Jun 2013 18:06:06 GMT
|
30
|
+
Transfer-Encoding:
|
31
|
+
- chunked
|
32
|
+
body:
|
33
|
+
encoding: US-ASCII
|
34
|
+
string: ! 'FROM base ()
|
35
|
+
|
36
|
+
===> b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc
|
37
|
+
|
38
|
+
Build successful.
|
39
|
+
|
40
|
+
===> b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc
|
41
|
+
|
42
|
+
'
|
43
|
+
http_version:
|
44
|
+
recorded_at: Thu, 20 Jun 2013 18:06:06 GMT
|
45
|
+
- request:
|
46
|
+
method: post
|
47
|
+
uri: http://localhost:4243/images/b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc/insert?path=/stallman&url=http://stallman.org
|
48
|
+
body:
|
49
|
+
encoding: US-ASCII
|
50
|
+
string: ''
|
51
|
+
headers: {}
|
52
|
+
response:
|
53
|
+
status:
|
54
|
+
code: 200
|
55
|
+
message: ''
|
56
|
+
headers:
|
57
|
+
!binary "Q29udGVudC1UeXBl":
|
58
|
+
- !binary |-
|
59
|
+
YXBwbGljYXRpb24vanNvbg==
|
60
|
+
!binary "RGF0ZQ==":
|
61
|
+
- !binary |-
|
62
|
+
VGh1LCAyMCBKdW4gMjAxMyAxODowNjowNyBHTVQ=
|
63
|
+
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
64
|
+
- !binary |-
|
65
|
+
Y2h1bmtlZA==
|
66
|
+
body:
|
67
|
+
encoding: US-ASCII
|
68
|
+
string: ! '{"status":"Downloading","progress":"6700/93351 (7%)"}{"status":"Downloading","progress":"12252/93351
|
69
|
+
(13%)"}{"status":"Downloading","progress":"16416/93351 (18%)"}{"status":"Downloading","progress":"23356/93351
|
70
|
+
(25%)"}{"status":"Downloading","progress":"27520/93351 (29%)"}{"status":"Downloading","progress":"33072/93351
|
71
|
+
(35%)"}{"status":"Downloading","progress":"37236/93351 (40%)"}{"status":"Downloading","progress":"44176/93351
|
72
|
+
(47%)"}{"status":"Downloading","progress":"49728/93351 (53%)"}{"status":"Downloading","progress":"53892/93351
|
73
|
+
(58%)"}{"status":"Downloading","progress":"58056/93351 (62%)"}{"status":"Downloading","progress":"62220/93351
|
74
|
+
(67%)"}{"status":"Downloading","progress":"66384/93351 (71%)"}{"status":"Downloading","progress":"71936/93351
|
75
|
+
(77%)"}{"status":"Downloading","progress":"77488/93351 (83%)"}{"status":"Downloading","progress":"81652/93351
|
76
|
+
(87%)"}{"status":"Downloading","progress":"87204/93351 (93%)"}{"status":"Downloading","progress":"91368/93351
|
77
|
+
(98%)"}{"status":"Downloading","progress":"93351/93351 (100%)"}{}{"status":"30c8d2ff0f6b646177231f6b5df651b231be1600b8fbe648f7c10092f394b759"}{"Id":"30c8d2ff0f6b"}'
|
78
|
+
http_version:
|
79
|
+
recorded_at: Thu, 20 Jun 2013 18:06:08 GMT
|
80
|
+
- request:
|
81
|
+
method: post
|
82
|
+
uri: http://localhost:4243/containers/create
|
83
|
+
body:
|
84
|
+
encoding: UTF-8
|
85
|
+
string: ! '{"Image":"30c8d2ff0f6b","Cmd":["ls","/"]}'
|
86
|
+
headers:
|
87
|
+
Content-Type:
|
88
|
+
- application/json
|
89
|
+
response:
|
90
|
+
status:
|
91
|
+
code: 201
|
92
|
+
message: ''
|
93
|
+
headers:
|
94
|
+
!binary "Q29udGVudC1UeXBl":
|
95
|
+
- !binary |-
|
96
|
+
dGV4dC9wbGFpbjsgY2hhcnNldD11dGYtOA==
|
97
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
98
|
+
- !binary |-
|
99
|
+
MjE=
|
100
|
+
!binary "RGF0ZQ==":
|
101
|
+
- !binary |-
|
102
|
+
VGh1LCAyMCBKdW4gMjAxMyAxODowNjowOCBHTVQ=
|
103
|
+
body:
|
104
|
+
encoding: US-ASCII
|
105
|
+
string: ! '{"Id":"153265f2e682"}'
|
106
|
+
http_version:
|
107
|
+
recorded_at: Thu, 20 Jun 2013 18:06:08 GMT
|
108
|
+
- request:
|
109
|
+
method: post
|
110
|
+
uri: http://localhost:4243/containers/153265f2e682/start
|
111
|
+
body:
|
112
|
+
encoding: US-ASCII
|
113
|
+
string: ''
|
114
|
+
headers:
|
115
|
+
Content-Type:
|
116
|
+
- application/json
|
117
|
+
response:
|
118
|
+
status:
|
119
|
+
code: 204
|
120
|
+
message: ''
|
121
|
+
headers:
|
122
|
+
!binary "Q29udGVudC1UeXBl":
|
123
|
+
- !binary |-
|
124
|
+
dGV4dC9wbGFpbjsgY2hhcnNldD11dGYtOA==
|
125
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
126
|
+
- !binary |-
|
127
|
+
MA==
|
128
|
+
!binary "RGF0ZQ==":
|
129
|
+
- !binary |-
|
130
|
+
VGh1LCAyMCBKdW4gMjAxMyAxODowNjowOCBHTVQ=
|
131
|
+
body:
|
132
|
+
encoding: US-ASCII
|
133
|
+
string: ''
|
134
|
+
http_version:
|
135
|
+
recorded_at: Thu, 20 Jun 2013 18:06:08 GMT
|
136
|
+
- request:
|
137
|
+
method: post
|
138
|
+
uri: http://localhost:4243/containers/153265f2e682/attach?stdout=true&stream=true
|
139
|
+
body:
|
140
|
+
encoding: US-ASCII
|
141
|
+
string: ''
|
142
|
+
headers: {}
|
143
|
+
response:
|
144
|
+
status:
|
145
|
+
code: 200
|
146
|
+
message: ''
|
147
|
+
headers:
|
148
|
+
!binary "Q29udGVudC1UeXBl":
|
149
|
+
- !binary |-
|
150
|
+
YXBwbGljYXRpb24vdm5kLmRvY2tlci5yYXctc3RyZWFt
|
151
|
+
body:
|
152
|
+
encoding: US-ASCII
|
153
|
+
string: ! 'bin
|
154
|
+
|
155
|
+
boot
|
156
|
+
|
157
|
+
dev
|
158
|
+
|
159
|
+
etc
|
160
|
+
|
161
|
+
home
|
162
|
+
|
163
|
+
lib
|
164
|
+
|
165
|
+
lib64
|
166
|
+
|
167
|
+
media
|
168
|
+
|
169
|
+
mnt
|
170
|
+
|
171
|
+
opt
|
172
|
+
|
173
|
+
proc
|
174
|
+
|
175
|
+
root
|
176
|
+
|
177
|
+
run
|
178
|
+
|
179
|
+
sbin
|
180
|
+
|
181
|
+
selinux
|
182
|
+
|
183
|
+
srv
|
184
|
+
|
185
|
+
stallman
|
186
|
+
|
187
|
+
sys
|
188
|
+
|
189
|
+
tmp
|
190
|
+
|
191
|
+
usr
|
192
|
+
|
193
|
+
var
|
194
|
+
|
195
|
+
'
|
196
|
+
http_version:
|
197
|
+
recorded_at: Thu, 20 Jun 2013 18:06:08 GMT
|
198
|
+
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: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -218,7 +218,7 @@ files:
|
|
218
218
|
- spec/vcr/Docker_Image/_build/with_an_invalid_Dockerfile/throws_a_UnexpectedResponseError.yml
|
219
219
|
- spec/vcr/Docker_Image/_create_/when_the_Image_does_not_yet_exist_and_the_body_is_a_Hash/when_the_HTTP_request_returns_a_200/sets_the_id.yml
|
220
220
|
- spec/vcr/Docker_Image/_history/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/returns_the_history_of_the_Image.yml
|
221
|
-
- spec/vcr/Docker_Image/_insert/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/
|
221
|
+
- spec/vcr/Docker_Image/_insert/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/inserts_the_url_s_file_into_a_new_Image.yml
|
222
222
|
- spec/vcr/Docker_Image/_json/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/returns_additional_information_about_image_image.yml
|
223
223
|
- spec/vcr/Docker_Image/_remove/when_the_Image_has_been_created/when_the_HTTP_response_status_is_204/nils_out_the_id.yml
|
224
224
|
- spec/vcr/Docker_Image/_search/when_the_HTTP_response_is_a_200/materializes_each_Container_into_a_Docker_Container.yml
|
@@ -273,9 +273,8 @@ test_files:
|
|
273
273
|
- spec/vcr/Docker_Image/_build/with_an_invalid_Dockerfile/throws_a_UnexpectedResponseError.yml
|
274
274
|
- spec/vcr/Docker_Image/_create_/when_the_Image_does_not_yet_exist_and_the_body_is_a_Hash/when_the_HTTP_request_returns_a_200/sets_the_id.yml
|
275
275
|
- spec/vcr/Docker_Image/_history/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/returns_the_history_of_the_Image.yml
|
276
|
-
- spec/vcr/Docker_Image/_insert/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/
|
276
|
+
- spec/vcr/Docker_Image/_insert/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/inserts_the_url_s_file_into_a_new_Image.yml
|
277
277
|
- spec/vcr/Docker_Image/_json/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/returns_additional_information_about_image_image.yml
|
278
278
|
- spec/vcr/Docker_Image/_remove/when_the_Image_has_been_created/when_the_HTTP_response_status_is_204/nils_out_the_id.yml
|
279
279
|
- spec/vcr/Docker_Image/_search/when_the_HTTP_response_is_a_200/materializes_each_Container_into_a_Docker_Container.yml
|
280
280
|
- spec/vcr/Docker_Image/_tag/when_the_Image_has_been_created/when_the_HTTP_response_status_is_200/tags_the_image_with_the_repo_name.yml
|
281
|
-
has_rdoc:
|
@@ -1,59 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: post
|
5
|
-
uri: http://localhost:4243/images/create
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: fromRepo=base&fromSrc=-
|
9
|
-
headers:
|
10
|
-
Content-Type:
|
11
|
-
- application/x-www-form-urlencoded
|
12
|
-
response:
|
13
|
-
status:
|
14
|
-
code: 200
|
15
|
-
message: ''
|
16
|
-
headers:
|
17
|
-
!binary "Q29udGVudC1UeXBl":
|
18
|
-
- !binary |-
|
19
|
-
YXBwbGljYXRpb24vanNvbg==
|
20
|
-
!binary "RGF0ZQ==":
|
21
|
-
- !binary |-
|
22
|
-
VHVlLCAxOCBKdW4gMjAxMyAxNjowNDozOSBHTVQ=
|
23
|
-
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
24
|
-
- !binary |-
|
25
|
-
Y2h1bmtlZA==
|
26
|
-
body:
|
27
|
-
encoding: US-ASCII
|
28
|
-
string: ! '{"status":"17c3631b2ef6"}'
|
29
|
-
http_version:
|
30
|
-
recorded_at: Tue, 18 Jun 2013 16:04:39 GMT
|
31
|
-
- request:
|
32
|
-
method: post
|
33
|
-
uri: http://localhost:4243/images/17c3631b2ef6/insert?path=/&url=lol
|
34
|
-
body:
|
35
|
-
encoding: US-ASCII
|
36
|
-
string: ''
|
37
|
-
headers:
|
38
|
-
Content-Type:
|
39
|
-
- application/json
|
40
|
-
response:
|
41
|
-
status:
|
42
|
-
code: 200
|
43
|
-
message: ''
|
44
|
-
headers:
|
45
|
-
!binary "Q29udGVudC1UeXBl":
|
46
|
-
- !binary |-
|
47
|
-
YXBwbGljYXRpb24vanNvbg==
|
48
|
-
!binary "RGF0ZQ==":
|
49
|
-
- !binary |-
|
50
|
-
VHVlLCAxOCBKdW4gMjAxMyAxNjowNDozOSBHTVQ=
|
51
|
-
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
52
|
-
- !binary |-
|
53
|
-
Y2h1bmtlZA==
|
54
|
-
body:
|
55
|
-
encoding: US-ASCII
|
56
|
-
string: ! '{"Id":""}'
|
57
|
-
http_version:
|
58
|
-
recorded_at: Tue, 18 Jun 2013 16:04:39 GMT
|
59
|
-
recorded_with: VCR 2.5.0
|