centurion 1.0.7 → 1.0.8

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.
@@ -87,7 +87,7 @@ module Centurion::Deploy
87
87
  end
88
88
  end
89
89
 
90
- def container_config_for(target_server, image_id, port_bindings=nil, env_vars=nil)
90
+ def container_config_for(target_server, image_id, port_bindings=nil, env_vars=nil, volumes=nil)
91
91
  container_config = {
92
92
  'Image' => image_id,
93
93
  'Hostname' => target_server.hostname,
@@ -101,16 +101,24 @@ module Centurion::Deploy
101
101
  container_config['Env'] = env_vars.map { |k,v| "#{k}=#{v}" }
102
102
  end
103
103
 
104
+ if volumes
105
+ container_config['Volumes'] = volumes.inject({}) do |memo, v|
106
+ memo[v.split(/:/).last] = {}
107
+ memo
108
+ end
109
+ container_config['VolumesFrom'] = 'parent'
110
+ end
111
+
104
112
  container_config
105
113
  end
106
114
 
107
115
  def start_new_container(target_server, image_id, port_bindings, volumes, env_vars=nil)
108
- container_config = container_config_for(target_server, image_id, port_bindings, env_vars)
116
+ container_config = container_config_for(target_server, image_id, port_bindings, env_vars, volumes)
109
117
  start_container_with_config(target_server, volumes, port_bindings, container_config)
110
118
  end
111
119
 
112
120
  def launch_console(target_server, image_id, port_bindings, volumes, env_vars=nil)
113
- container_config = container_config_for(target_server, image_id, port_bindings, env_vars).merge(
121
+ container_config = container_config_for(target_server, image_id, port_bindings, env_vars, volumes).merge(
114
122
  'Cmd' => [ '/bin/bash' ],
115
123
  'AttachStdin' => true,
116
124
  'Tty' => true,
@@ -128,11 +136,11 @@ module Centurion::Deploy
128
136
  info "Creating new container for #{container_config['Image'][0..7]}"
129
137
  new_container = target_server.create_container(container_config)
130
138
 
131
- host_config = {
132
- 'PortBindings' => port_bindings
133
- }
139
+ host_config = {}
134
140
  # Map some host volumes if needed
135
141
  host_config['Binds'] = volumes if volumes && !volumes.empty?
142
+ # Bind the ports
143
+ host_config['PortBindings'] = port_bindings
136
144
 
137
145
  info "Starting new container #{new_container['Id'][0..7]}"
138
146
  target_server.start_container(new_container['Id'], host_config)
@@ -61,7 +61,7 @@ class Centurion::DockerViaApi
61
61
  end
62
62
 
63
63
  def create_container(configuration)
64
- path = "/v1.7/containers/create"
64
+ path = "/v1.10/containers/create"
65
65
  response = Excon.post(
66
66
  @base_uri + path,
67
67
  :body => configuration.to_json,
@@ -72,7 +72,7 @@ class Centurion::DockerViaApi
72
72
  end
73
73
 
74
74
  def start_container(container_id, configuration)
75
- path = "/v1.7/containers/#{container_id}/start"
75
+ path = "/v1.10/containers/#{container_id}/start"
76
76
  response = Excon.post(
77
77
  @base_uri + path,
78
78
  :body => configuration.to_json,
@@ -1,3 +1,3 @@
1
1
  module Centurion
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
  end
@@ -158,13 +158,21 @@ describe Centurion::Deploy do
158
158
  expect(config).to be_a(Hash)
159
159
  expect(config.keys).to match_array(%w{ Hostname Image })
160
160
  end
161
+
162
+ it 'handles mapping host volumes' do
163
+ config = test_deploy.container_config_for(server, 'image_id', nil, nil, ["/tmp/foo:/tmp/chaucer"])
164
+
165
+ expect(config).to be_a(Hash)
166
+ expect(config.keys).to match_array(%w{ Hostname Image Volumes VolumesFrom })
167
+ expect(config['Volumes']['/tmp/chaucer']).to eq({})
168
+ end
161
169
  end
162
170
 
163
171
  describe '#start_new_container' do
164
172
  let(:bindings) { {'80/tcp'=>[{'HostIp'=>'0.0.0.0', 'HostPort'=>'80'}]} }
165
173
 
166
174
  it 'configures the container' do
167
- expect(test_deploy).to receive(:container_config_for).with(server, 'image_id', bindings, nil).once
175
+ expect(test_deploy).to receive(:container_config_for).with(server, 'image_id', bindings, nil, {}).once
168
176
  test_deploy.stub(:start_container_with_config)
169
177
 
170
178
  test_deploy.start_new_container(server, 'image_id', bindings, {})
@@ -193,7 +201,7 @@ describe Centurion::Deploy do
193
201
  let(:bindings) { {'80/tcp'=>[{'HostIp'=>'0.0.0.0', 'HostPort'=>'80'}]} }
194
202
 
195
203
  it 'configures the container' do
196
- expect(test_deploy).to receive(:container_config_for).with(server, 'image_id', bindings, nil).once
204
+ expect(test_deploy).to receive(:container_config_for).with(server, 'image_id', bindings, nil, {}).once
197
205
  test_deploy.stub(:start_container_with_config)
198
206
 
199
207
  test_deploy.start_new_container(server, 'image_id', bindings, {})
@@ -5,7 +5,7 @@ describe Centurion::DockerViaApi do
5
5
  let(:hostname) { 'example.com' }
6
6
  let(:port) { '4243' }
7
7
  let(:api) { Centurion::DockerViaApi.new(hostname, port) }
8
- let(:excon_uri) { "http://#{hostname}:#{port}/v1.7" }
8
+ let(:excon_uri) { "http://#{hostname}:#{port}/" }
9
9
  let(:json_string) { '[{ "Hello": "World" }]' }
10
10
  let(:json_value) { JSON.load(json_string) }
11
11
  let(:inspected_containers) do
@@ -18,21 +18,21 @@ describe Centurion::DockerViaApi do
18
18
 
19
19
  it 'lists processes' do
20
20
  expect(Excon).to receive(:get).
21
- with(excon_uri + "/containers/json").
21
+ with(excon_uri + "v1.7" + "/containers/json").
22
22
  and_return(double(body: json_string, status: 200))
23
23
  expect(api.ps).to eq(json_value)
24
24
  end
25
25
 
26
26
  it 'lists all processes' do
27
27
  expect(Excon).to receive(:get).
28
- with(excon_uri + "/containers/json?all=1").
28
+ with(excon_uri + "v1.7" + "/containers/json?all=1").
29
29
  and_return(double(body: json_string, status: 200))
30
30
  expect(api.ps(all: true)).to eq(json_value)
31
31
  end
32
32
 
33
33
  it 'inspects an image' do
34
34
  expect(Excon).to receive(:get).
35
- with(excon_uri + "/images/foo:bar/json",
35
+ with(excon_uri + "v1.7" + "/images/foo:bar/json",
36
36
  headers: {'Accept' => 'application/json'}).
37
37
  and_return(double(body: json_string, status: 200))
38
38
  expect(api.inspect_image('foo', 'bar')).to eq(json_value)
@@ -42,7 +42,7 @@ describe Centurion::DockerViaApi do
42
42
  configuration_as_json = double
43
43
  configuration = double(:to_json => configuration_as_json)
44
44
  expect(Excon).to receive(:post).
45
- with(excon_uri + "/containers/create",
45
+ with(excon_uri + "v1.10" + "/containers/create",
46
46
  body: configuration_as_json,
47
47
  headers: {'Content-Type' => 'application/json'}).
48
48
  and_return(double(body: json_string, status: 201))
@@ -53,7 +53,7 @@ describe Centurion::DockerViaApi do
53
53
  configuration_as_json = double
54
54
  configuration = double(:to_json => configuration_as_json)
55
55
  expect(Excon).to receive(:post).
56
- with(excon_uri + "/containers/12345/start",
56
+ with(excon_uri + "v1.10" + "/containers/12345/start",
57
57
  body: configuration_as_json,
58
58
  headers: {'Content-Type' => 'application/json'}).
59
59
  and_return(double(body: json_string, status: 204))
@@ -62,34 +62,34 @@ describe Centurion::DockerViaApi do
62
62
 
63
63
  it 'stops a container' do
64
64
  expect(Excon).to receive(:post).
65
- with(excon_uri + "/containers/12345/stop?t=30").
65
+ with(excon_uri + "v1.7" + "/containers/12345/stop?t=30").
66
66
  and_return(double(status: 204))
67
67
  api.stop_container('12345')
68
68
  end
69
69
 
70
70
  it 'inspects a container' do
71
71
  expect(Excon).to receive(:get).
72
- with(excon_uri + "/containers/12345/json").
72
+ with(excon_uri + "v1.7" + "/containers/12345/json").
73
73
  and_return(double(body: json_string, status: 200))
74
74
  expect(api.inspect_container('12345')).to eq(json_value)
75
75
  end
76
76
 
77
77
  it 'removes a container' do
78
78
  expect(Excon).to receive(:delete).
79
- with(excon_uri + "/containers/12345").
79
+ with(excon_uri + "v1.7" + "/containers/12345").
80
80
  and_return(double(status: 204))
81
81
  expect(api.remove_container('12345')).to eq(true)
82
82
  end
83
83
 
84
84
  it 'lists old containers for a port' do
85
85
  expect(Excon).to receive(:get).
86
- with(excon_uri + "/containers/json?all=1").
86
+ with(excon_uri + "v1.7" + "/containers/json?all=1").
87
87
  and_return(double(body: inspected_containers.to_json, status: 200))
88
88
  expect(Excon).to receive(:get).
89
- with(excon_uri + "/containers/123/json").
89
+ with(excon_uri + "v1.7" + "/containers/123/json").
90
90
  and_return(double(body: inspected_container_on_port("123", 8485).to_json, status: 200))
91
91
  expect(Excon).to receive(:get).
92
- with(excon_uri + "/containers/789/json").
92
+ with(excon_uri + "v1.7" + "/containers/789/json").
93
93
  and_return(double(body: inspected_container_on_port("789", 8486).to_json, status: 200))
94
94
 
95
95
  expect(api.old_containers_for_port(8485)).to eq([{"Id" => "123", "Status" => "Exit 0"}])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centurion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: