docker-api 1.29.2 → 1.30.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fbe16ce62bccd73978276f1f5cd535be61d33ac
4
- data.tar.gz: 206a85aba2ac9c0887e9210a9cc645c84bb6024e
3
+ metadata.gz: ccea9c7feff7598faa3a7454dc4288175b2cd85b
4
+ data.tar.gz: de4ce8b295ee655a7f5a50e32f381f09a615df22
5
5
  SHA512:
6
- metadata.gz: a239e8b043393b27f56ba122f4644c191a4ca781449bf2da41ba7c27ab4d53e192de188a85e1b285b369bcaf0d7c107d6fc44f726237476fa5c1a8bbf262b82f
7
- data.tar.gz: 35a0be04371987d822481238ca62f8ac05147788ab4465424a39eb3812b83a5c82da5734a8150a768ba84484c58cd4c826345549e0fab692ef9ba9d67445d107
6
+ metadata.gz: be98218b4aad256b5941ce2f512911685a0a3bd150b8c93be429e8ae61a70d6b29056058578139e49f0b96215cdca2dc247264223c9696744d80fe4087d8c401
7
+ data.tar.gz: 72c9c3bd8ddd07da6e0b2b3b393e6c35e3124ae975d37e26416bec14cea73eca2668e281c8d5a3d053c9503d31d98d55cf18f6099103c3401d3cdcfbb3ddbdb9
data/README.md CHANGED
@@ -324,6 +324,54 @@ container.kill(:signal => "SIGHUP")
324
324
  container.top
325
325
  # => [{"PID"=>"4851", "TTY"=>"pts/0", "TIME"=>"00:00:00", "CMD"=>"lxc-start"}]
326
326
 
327
+ # To expose 1234 to bridge
328
+ # In Dockerfile: EXPOSE 1234/tcp
329
+ # docker run resulting-image-name
330
+ Docker::Container.create(
331
+ 'Image' => 'image-name',
332
+ 'HostConfig' => {
333
+ 'PortBindings' => {
334
+ '1234/tcp' => [{}]
335
+ }
336
+ }
337
+ )
338
+
339
+ # To expose 1234 to host with any port
340
+ # docker run -p 1234 image-name
341
+ Docker::Container.create(
342
+ 'Image' => 'image-name',
343
+ 'ExposedPorts' => { '1234/tcp' => {} },
344
+ 'HostConfig' => {
345
+ 'PortBindings' => {
346
+ '1234/tcp' => [{}]
347
+ }
348
+ }
349
+ )
350
+
351
+ # To expose 1234 to host with a specified host port
352
+ # docker run -p 1234:1234 image-name
353
+ Docker::Container.create(
354
+ 'Image' => 'image-name',
355
+ 'ExposedPorts' => { '1234/tcp' => {} },
356
+ 'HostConfig' => {
357
+ 'PortBindings' => {
358
+ '1234/tcp' => [{ 'HostPort' => '1234' }]
359
+ }
360
+ }
361
+ )
362
+
363
+ # To expose 1234 to host with a specified host port and host IP
364
+ # docker run -p 192.168.99.100:1234:1234 image-name
365
+ Docker::Container.create(
366
+ 'Image' => 'image-name',
367
+ 'ExposedPorts' => { '1234/tcp' => {} },
368
+ 'HostConfig' => {
369
+ 'PortBindings' => {
370
+ '1234/tcp' => [{ 'HostPort' => '1234', 'HostIp' => '192.168.99.100' }]
371
+ }
372
+ }
373
+ )
374
+
327
375
  # Export a Container. Since an export is typically at least 300M, chunks of the
328
376
  # export are yielded instead of just returning the whole thing.
329
377
  File.open('export.tar', 'w') do |f|
@@ -2,15 +2,26 @@
2
2
  class Docker::Event
3
3
  include Docker::Error
4
4
 
5
- attr_accessor :status, :id, :from, :time
5
+ # Represents the actor object nested within an event
6
+ class Actor
7
+ attr_accessor :ID, :Attributes
6
8
 
7
- def initialize(status, id, from, time)
8
- @status, @id, @from, @time = status, id, from, time
9
- end
9
+ def initialize(actor_attributes = {})
10
+ [:ID, :Attributes].each do |sym|
11
+ value = actor_attributes[sym]
12
+ if value.nil?
13
+ value = actor_attributes[sym.to_s]
14
+ end
15
+ send("#{sym}=", value)
16
+ end
10
17
 
11
- def to_s
12
- "Docker::Event { :status => #{self.status}, :id => #{self.id}, "\
13
- ":from => #{self.from}, :time => #{self.time} }"
18
+ if self.Attributes.nil?
19
+ self.Attributes = {}
20
+ end
21
+ end
22
+
23
+ alias_method :id, :ID
24
+ alias_method :attributes, :Attributes
14
25
  end
15
26
 
16
27
  class << self
@@ -29,12 +40,89 @@ class Docker::Event
29
40
  def new_event(body, remaining, total)
30
41
  return if body.nil? || body.empty?
31
42
  json = Docker::Util.parse_json(body)
32
- Docker::Event.new(
33
- json['status'],
34
- json['id'],
35
- json['from'],
36
- json['time']
37
- )
43
+ Docker::Event.new(json)
38
44
  end
39
45
  end
46
+
47
+ attr_accessor :Type, :Action, :time, :timeNano
48
+ attr_reader :Actor
49
+ # Deprecated interface
50
+ attr_accessor :status, :from
51
+
52
+ def initialize(event_attributes = {})
53
+ [:Type, :Action, :Actor, :time, :timeNano, :status, :from].each do |sym|
54
+ value = event_attributes[sym]
55
+ if value.nil?
56
+ value = event_attributes[sym.to_s]
57
+ end
58
+ send("#{sym}=", value)
59
+ end
60
+
61
+ if @Actor.nil?
62
+ value = event_attributes[:id]
63
+ if value.nil?
64
+ value = event_attributes['id']
65
+ end
66
+ self.Actor = Actor.new(ID: value)
67
+ end
68
+ end
69
+
70
+ def ID
71
+ self.actor.ID
72
+ end
73
+
74
+ def Actor=(actor)
75
+ return if actor.nil?
76
+ if actor.is_a? Actor
77
+ @Actor = actor
78
+ else
79
+ @Actor = Actor.new(actor)
80
+ end
81
+ end
82
+
83
+ alias_method :type, :Type
84
+ alias_method :action, :Action
85
+ alias_method :actor, :Actor
86
+ alias_method :time_nano, :timeNano
87
+ alias_method :id, :ID
88
+
89
+ def to_s
90
+ if type.nil? && action.nil?
91
+ to_s_legacy
92
+ else
93
+ to_s_actor_style
94
+ end
95
+ end
96
+
97
+ private
98
+
99
+ def to_s_legacy
100
+ attributes = []
101
+ attributes << "from=#{from}" unless from.nil?
102
+
103
+ unless attributes.empty?
104
+ attribute_string = "(#{attributes.join(', ')}) "
105
+ end
106
+
107
+ "Docker::Event { #{time} #{status} #{id} #{attribute_string}}"
108
+ end
109
+
110
+ def to_s_actor_style
111
+ most_accurate_time = if !time_nano.nil?
112
+ time_nano
113
+ elsif !time.nil?
114
+ time
115
+ end
116
+
117
+ attributes = []
118
+ actor.attributes.each do |attribute, value|
119
+ attributes << "#{attribute}=#{value}"
120
+ end
121
+
122
+ unless attributes.empty?
123
+ attribute_string = "(#{attributes.join(', ')}) "
124
+ end
125
+
126
+ "Docker::Event { #{most_accurate_time} #{type} #{action} #{actor.id} #{attribute_string}}"
127
+ end
40
128
  end
@@ -1,6 +1,6 @@
1
1
  module Docker
2
2
  # The version of the docker-api gem.
3
- VERSION = '1.29.2'
3
+ VERSION = '1.30.0'
4
4
 
5
5
  # The version of the compatible Docker remote API.
6
6
  API_VERSION = '1.16'
@@ -1,21 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Docker::Event do
4
+ let(:api_response) do
5
+ {
6
+ 'Action' => 'start',
7
+ 'Actor' => {
8
+ 'Attributes' => {
9
+ 'image' => 'tianon/true',
10
+ 'name' => 'true-dat'
11
+ },
12
+ 'ID' => 'bb2c783a32330b726f18d1eb44d80c899ef45771b4f939326e0fefcfc7e05db8'
13
+ },
14
+ 'Type' => 'container',
15
+ 'from' => 'tianon/true',
16
+ 'id' => 'bb2c783a32330b726f18d1eb44d80c899ef45771b4f939326e0fefcfc7e05db8',
17
+ 'status' => 'start',
18
+ 'time' => 1461083270,
19
+ 'timeNano' => 1461083270652069004
20
+ }
21
+ end
22
+
4
23
  describe "#to_s" do
5
- subject { described_class.new(status, id, from, time) }
24
+ context 'with an old event' do
25
+ let(:event) do
26
+ described_class.new(
27
+ status: status,
28
+ id: id,
29
+ from: from,
30
+ time: time
31
+ )
32
+ end
6
33
 
7
- let(:status) { "start" }
8
- let(:id) { "398c9f77b5d2" }
9
- let(:from) { "debian:wheezy" }
10
- let(:time) { 1381956164 }
34
+ let(:status) { "start" }
35
+ let(:id) { "398c9f77b5d2" }
36
+ let(:from) { "debian:wheezy" }
37
+ let(:time) { 1381956164 }
11
38
 
12
- let(:expected_string) {
13
- "Docker::Event { :status => #{status}, :id => #{id}, "\
14
- ":from => #{from}, :time => #{time.to_s} }"
15
- }
39
+ let(:expected_string) {
40
+ "Docker::Event { #{time} #{status} #{id} (from=#{from}) }"
41
+ }
42
+
43
+ it "equals the expected string" do
44
+ expect(event.to_s).to eq(expected_string)
45
+ end
46
+ end
47
+
48
+ context 'with a new event' do
49
+ let(:event) { described_class.new(api_response) }
16
50
 
17
- it "equals the expected string" do
18
- expect(subject.to_s).to eq(expected_string)
51
+ let(:expected_string) do
52
+ 'Docker::Event { 1461083270652069004 container start '\
53
+ 'bb2c783a32330b726f18d1eb44d80c899ef45771b4f939326e0fefcfc7e05db8 '\
54
+ '(image=tianon/true, name=true-dat) }'
55
+ end
56
+
57
+ it 'equals the expected string' do
58
+ expect(event.to_s).to eq(expected_string)
59
+ end
19
60
  end
20
61
  end
21
62
 
@@ -68,22 +109,40 @@ describe Docker::Event do
68
109
  end
69
110
 
70
111
  describe ".new_event" do
71
- subject { Docker::Event.new_event(response_body, nil, nil) }
72
- let(:status) { "start" }
73
- let(:id) { "398c9f77b5d2" }
74
- let(:from) { "debian:wheezy" }
75
- let(:time) { 1381956164 }
76
- let(:response_body) {
77
- "{\"status\":\"#{status}\",\"id\":\"#{id}\""\
78
- ",\"from\":\"#{from}\",\"time\":#{time}}"
79
- }
112
+ context 'with an old api response' do
113
+ let(:event) { Docker::Event.new_event(response_body, nil, nil) }
114
+ let(:status) { "start" }
115
+ let(:id) { "398c9f77b5d2" }
116
+ let(:from) { "debian:wheezy" }
117
+ let(:time) { 1381956164 }
118
+ let(:response_body) {
119
+ "{\"status\":\"#{status}\",\"id\":\"#{id}\""\
120
+ ",\"from\":\"#{from}\",\"time\":#{time}}"
121
+ }
80
122
 
81
- it "returns a Docker::Event" do
82
- expect(subject).to be_kind_of(Docker::Event)
83
- expect(subject.status).to eq(status)
84
- expect(subject.id).to eq(id)
85
- expect(subject.from).to eq(from)
86
- expect(subject.time).to eq(time)
123
+ it "returns a Docker::Event" do
124
+ expect(event).to be_kind_of(Docker::Event)
125
+ expect(event.status).to eq(status)
126
+ expect(event.id).to eq(id)
127
+ expect(event.from).to eq(from)
128
+ expect(event.time).to eq(time)
129
+ end
130
+ end
131
+
132
+ context 'with a new api response' do
133
+ let(:event) { Docker::Event.new_event(api_response.to_json, nil, nil) }
134
+
135
+ it 'returns a Docker::Event' do
136
+ expect(event).to be_kind_of(Docker::Event)
137
+ expect(event.type).to eq('container')
138
+ expect(event.action).to eq('start')
139
+ expect(
140
+ event.actor.id
141
+ ).to eq('bb2c783a32330b726f18d1eb44d80c899ef45771b4f939326e0fefcfc7e05db8')
142
+ expect(event.actor.attributes).to eq('image' => 'tianon/true', 'name' => 'true-dat')
143
+ expect(event.time).to eq 1461083270
144
+ expect(event.time_nano).to eq 1461083270652069004
145
+ end
87
146
  end
88
147
  end
89
148
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.2
4
+ version: 1.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swipely, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon