docker-api 0.0.3 → 0.0.4
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/README.md +6 -0
- data/lib/docker.rb +45 -42
- data/lib/docker/image.rb +13 -2
- data/lib/docker/version.rb +1 -1
- data/spec/docker_spec.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
docker-api
|
2
2
|
==========
|
3
|
+
[](https://travis-ci.org/swipely/docker-api) [](https://codeclimate.com/github/swipely/docker-api)
|
3
4
|
|
4
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.0.
|
5
6
|
|
@@ -106,6 +107,11 @@ image.json
|
|
106
107
|
image.history
|
107
108
|
# => [{"Id"=>"67859327bf22", "Created"=>1371681778}]
|
108
109
|
|
110
|
+
# Push the Image to the Docker registry. Note that you have to login using
|
111
|
+
# `Docker.authenticate!` and tag the Image first.
|
112
|
+
image.push
|
113
|
+
# => true
|
114
|
+
|
109
115
|
# Remove the Image from the server.
|
110
116
|
image.remove
|
111
117
|
# => true
|
data/lib/docker.rb
CHANGED
@@ -6,48 +6,51 @@ require 'net/http/post/multipart'
|
|
6
6
|
# The top-level module for this gem. It's purpose is to hold global
|
7
7
|
# configuration variables that are used as defaults in other classes.
|
8
8
|
module Docker
|
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
|
-
|
9
|
+
extend self
|
10
|
+
|
11
|
+
attr_reader :creds
|
12
|
+
|
13
|
+
def url
|
14
|
+
@url ||= 'http://localhost'
|
15
|
+
end
|
16
|
+
|
17
|
+
def options
|
18
|
+
@options ||= { :port => 4243 }
|
19
|
+
end
|
20
|
+
|
21
|
+
def url=(new_url)
|
22
|
+
@url = new_url
|
23
|
+
reset_connection!
|
24
|
+
end
|
25
|
+
|
26
|
+
def options=(new_options)
|
27
|
+
@options = { :port => 4243 }.merge(new_options)
|
28
|
+
reset_connection!
|
29
|
+
end
|
30
|
+
|
31
|
+
def connection
|
32
|
+
@connection ||= Connection.new(url, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def reset_connection!
|
36
|
+
@connection = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get the version of Go, Docker, and optionally the Git commit.
|
40
|
+
def version
|
41
|
+
connection.json_request(:get, '/version')
|
42
|
+
end
|
43
|
+
|
44
|
+
# Get more information about the Docker server.
|
45
|
+
def info
|
46
|
+
connection.json_request(:get, '/info')
|
47
|
+
end
|
48
|
+
|
49
|
+
# Login to the Docker registry.
|
50
|
+
def authenticate!(options = {})
|
51
|
+
connection.post(:path => '/auth', :body => options)
|
52
|
+
@creds = options.to_json
|
53
|
+
true
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
data/lib/docker/image.rb
CHANGED
@@ -19,11 +19,22 @@ class Docker::Image
|
|
19
19
|
docker_request :tag, :post
|
20
20
|
# Get more information about the Image.
|
21
21
|
docker_request :json, :get
|
22
|
-
# Push the Image to the Docker registry.
|
23
|
-
docker_request :push, :post
|
24
22
|
# Get the history of the Image.
|
25
23
|
docker_request :history, :get
|
26
24
|
|
25
|
+
# Push the Image to the Docker registry.
|
26
|
+
def push(options = {})
|
27
|
+
ensure_created!
|
28
|
+
self.connection.post(
|
29
|
+
:path => "/images/#{self.id}/push",
|
30
|
+
:headers => { 'Content-Type' => 'application/json' },
|
31
|
+
:query => options,
|
32
|
+
:body => Docker.creds,
|
33
|
+
:expects => (200..204)
|
34
|
+
)
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
27
38
|
# Insert a file into the Image, returns a new Image that has that file.
|
28
39
|
def insert(query = {})
|
29
40
|
ensure_created!
|
data/lib/docker/version.rb
CHANGED
data/spec/docker_spec.rb
CHANGED