docker-api 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -51,6 +51,18 @@ Docker.options = { :port => 5422 }
51
51
 
52
52
  Two things to note here. The first is that this gem uses [excon](http://www.github.com/geemus/excon), so any of the options that are valid for `Excon.new` are alse valid for `Docker.options`. Second, by default Docker runs on port 4243. The gem will assume you want to connnect to port 4243 unless you specify otherwise.
53
53
 
54
+ Also, you may set the above variables via `ENV` variables. For example:
55
+
56
+ ```shell
57
+ $ DOCKER_HOST=example.com DOCKER_PORT=1000 irb
58
+ irb(main):001:0> require 'docker'
59
+ => true
60
+ irb(main):002:0> Docker.url
61
+ => http://example.com
62
+ irb(main):003:0> Docker.options
63
+ => {:port=>1000}
64
+ ```
65
+
54
66
  Before doing anything else, ensure you have the correct version of the Docker API. To do this, run `Docker.validate_version!`. If your installed version is not supported, a `Docker::Error::VersionError` is raised.
55
67
 
56
68
  ## Global calls
@@ -13,11 +13,12 @@ module Docker
13
13
  attr_reader :creds
14
14
 
15
15
  def url
16
- @url ||= 'http://localhost'
16
+ @url ||= "http://#{ENV['DOCKER_HOST'] || 'localhost'}"
17
17
  end
18
18
 
19
19
  def options
20
- @options ||= { :port => 4243 }
20
+ port = (ENV['DOCKER_PORT'].nil? ? 4243 : ENV['DOCKER_PORT']).to_i
21
+ @options ||= { :port => port.to_i }
21
22
  end
22
23
 
23
24
  def url=(new_url)
@@ -53,12 +53,13 @@ private
53
53
  query ||= {}
54
54
  opts ||= {}
55
55
  headers = opts.delete(:headers) || {}
56
+ user_agent = "Swipely/Docker-API #{Docker::VERSION}"
56
57
  {
57
58
  :method => http_method,
58
59
  :path => "/v#{Docker::API_VERSION}#{path}",
59
60
  :query => query,
60
61
  :headers => { 'Content-Type' => 'text/plain',
61
- 'User-Agent' => 'Docker-Client/0.4.6'
62
+ 'User-Agent' => user_agent,
62
63
  }.merge(headers),
63
64
  :expects => (200..204),
64
65
  :idempotent => http_method == :get,
@@ -113,7 +113,7 @@ class Docker::Image
113
113
 
114
114
  def create_dir_tar(directory)
115
115
  cwd = FileUtils.pwd
116
- tempfile = File.new('/tmp/out', 'w')
116
+ tempfile = File.new('/tmp/out', 'wb')
117
117
  FileUtils.cd(directory)
118
118
  Archive::Tar::Minitar.pack('.', tempfile)
119
119
  File.new('/tmp/out', 'r')
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  # The version of the docker-api gem.
3
- VERSION = '1.2.0'
3
+ VERSION = '1.3.0'
4
4
 
5
5
  # The version of the compatible Docker remote API.
6
6
  API_VERSION = '1.3'
@@ -52,7 +52,8 @@ describe Docker::Connection do
52
52
  :path => "/v#{Docker::API_VERSION}#{path}",
53
53
  :query => query,
54
54
  :headers => { 'Content-Type' => 'text/plain',
55
- 'User-Agent' => 'Docker-Client/0.4.6' },
55
+ 'User-Agent' => "Swipely/Docker-API #{Docker::VERSION}",
56
+ },
56
57
  :expects => 201,
57
58
  :idempotent => true,
58
59
  :lol => true
@@ -3,11 +3,43 @@ require 'spec_helper'
3
3
  describe Docker do
4
4
  subject { Docker }
5
5
 
6
+ before do
7
+ ENV['DOCKER_HOST'] = nil
8
+ ENV['DOCKER_PORT'] = nil
9
+ end
10
+
6
11
  it { should be_a Module }
7
12
  its(:options) { should == { :port => 4243 } }
8
13
  its(:url) { should == 'http://localhost' }
9
14
  its(:connection) { should be_a Docker::Connection }
10
15
 
16
+ context 'when the DOCKER_HOST ENV variable is set' do
17
+ let(:host) { 'google.com' }
18
+ let(:url) { "http://#{host}" }
19
+
20
+ before do
21
+ Docker.instance_variable_set(:@url, nil)
22
+ ENV['DOCKER_HOST'] = host
23
+ end
24
+
25
+ it 'sets Docker.url to that variable' do
26
+ subject.url.should == url
27
+ end
28
+ end
29
+
30
+ context 'when the DOCKER_PORT ENV variable is set' do
31
+ let(:port) { 1234 }
32
+
33
+ before do
34
+ Docker.instance_variable_set(:@options, nil)
35
+ ENV['DOCKER_PORT'] = port.to_s
36
+ end
37
+
38
+ it 'sets Docker.options[:port] to that variable' do
39
+ subject.options[:port].should == port
40
+ end
41
+ end
42
+
11
43
  describe '#reset_connection!' do
12
44
  before { subject.connection }
13
45
  it 'sets the @connection to nil' do
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.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-05 00:00:00.000000000 Z
12
+ date: 2013-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon