docker-api 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +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
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
- class << self
10
- def url
11
- @url ||= 'http://localhost'
12
- end
13
-
14
- def options
15
- @options ||= { :port => 4243 }
16
- end
17
-
18
- def url=(new_url)
19
- @url = new_url
20
- reset_connection!
21
- end
22
-
23
- def options=(new_options)
24
- @options = { :port => 4243 }.merge(new_options)
25
- reset_connection!
26
- end
27
-
28
- def connection
29
- @connection ||= Connection.new(url, options)
30
- end
31
-
32
- def reset_connection!
33
- @connection = nil
34
- end
35
-
36
- # Get the version of Go, Docker, and optionally the Git commit.
37
- def version
38
- connection.json_request(:get, '/version')
39
- end
40
-
41
- # Get more information about the Docker server.
42
- def info
43
- connection.json_request(:get, '/info')
44
- end
45
-
46
- # Login to the Docker registry.
47
- def authenticate!(options = {})
48
- connection.post(:path => '/auth', :body => options)
49
- true
50
- end
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!
@@ -1,3 +1,3 @@
1
1
  module Docker
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/docker_spec.rb CHANGED
@@ -50,7 +50,7 @@ describe Docker do
50
50
  end
51
51
  end
52
52
 
53
- describe '#auth' do
53
+ describe '#authenticate!' do
54
54
  it 'logs in' do
55
55
  pending
56
56
  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: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: