vx-container_connector 0.2.9 → 0.3.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 +4 -4
- data/lib/vx/container_connector/docker/default.rb +52 -0
- data/lib/vx/container_connector/docker.rb +36 -37
- data/lib/vx/container_connector/local.rb +9 -6
- data/lib/vx/container_connector/mixin/instrument.rb +21 -0
- data/lib/vx/container_connector/mixin/retriable.rb +0 -1
- data/lib/vx/container_connector/version.rb +1 -1
- data/lib/vx/container_connector.rb +6 -4
- data/spec/lib/docker_spec.rb +0 -8
- data/spec/lib/local_spec.rb +2 -2
- data/spec/spec_helper.rb +5 -13
- data/vx-container_connector.gemspec +0 -1
- metadata +4 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84082fa207a3f63e5f75028ddc74136a95c4629
|
4
|
+
data.tar.gz: dc1ce66f51fac9b33871bc76fcdab207315b2a6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b760b4adf849aadb3bab434bbd74f686510073c05363df48ad3f09333f32f3691a18cc16b24dcdb8fbe47b2f97752ae6773fea35186b9490eb5a778fd08d742c
|
7
|
+
data.tar.gz: cc7278b8aa10f12bdff3faa504b5207ed97fb48fa1a01b1a1c30a279d70012b061814cc4f7cc2bd1f0d48e0084dca96718cd1ec74faa3f85dd6b876a62d5ec2c
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Vx
|
2
|
+
module ContainerConnector
|
3
|
+
|
4
|
+
class Docker
|
5
|
+
|
6
|
+
class Default
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def ssh_host
|
11
|
+
if testing?
|
12
|
+
'localhost'
|
13
|
+
else
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def ssh_port
|
19
|
+
if testing?
|
20
|
+
2122
|
21
|
+
else
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_container_options
|
27
|
+
if testing?
|
28
|
+
{ "ExposedPorts" => { "22/tcp" => {} } }
|
29
|
+
else
|
30
|
+
{}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def start_container_options
|
35
|
+
if testing?
|
36
|
+
{ "PortBindings" => { "22/tcp" => [{ "HostPort" => "2022" }] } }
|
37
|
+
else
|
38
|
+
{}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def testing?
|
43
|
+
ENV['VX_ENV'] == 'test'
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'docker'
|
2
|
-
require 'logger'
|
3
2
|
require 'vx/common/spawn'
|
4
3
|
require 'net/ssh'
|
5
4
|
|
@@ -9,31 +8,13 @@ module Vx
|
|
9
8
|
class Docker
|
10
9
|
|
11
10
|
autoload :Spawner, File.expand_path("../docker/spawner", __FILE__)
|
11
|
+
autoload :Default, File.expand_path("../docker/default", __FILE__)
|
12
12
|
|
13
13
|
include Vx::Common::Spawn
|
14
14
|
include ContainerConnector::Retriable
|
15
|
+
include Instrument
|
15
16
|
|
16
|
-
attr_reader :user, :password, :init, :image, :remote_dir
|
17
|
-
|
18
|
-
@@default_container_options = {}
|
19
|
-
@@default_ssh_port = 22
|
20
|
-
@@host_to_connect_override = nil
|
21
|
-
|
22
|
-
class << self
|
23
|
-
def default_container_options
|
24
|
-
@@default_container_options
|
25
|
-
end
|
26
|
-
|
27
|
-
def default_ssh_port(val = nil)
|
28
|
-
@@default_ssh_port = val if val
|
29
|
-
@@default_ssh_port
|
30
|
-
end
|
31
|
-
|
32
|
-
def host_to_connect_override(val = nil)
|
33
|
-
@@host_to_connect_override = val if val
|
34
|
-
@@host_to_connect_override
|
35
|
-
end
|
36
|
-
end
|
17
|
+
attr_reader :user, :password, :init, :image, :remote_dir
|
37
18
|
|
38
19
|
def initialize(options = {})
|
39
20
|
@user = options[:user] || "vexor"
|
@@ -41,7 +22,6 @@ module Vx
|
|
41
22
|
@init = options[:init] || %w{ /sbin/init --startup-event dockerboot }
|
42
23
|
@image = options[:image] || "dmexe/precise"
|
43
24
|
@remote_dir = options[:remote_dir] || "/home/#{user}"
|
44
|
-
@logger = options[:logger] || ::Logger.new(STDOUT)
|
45
25
|
end
|
46
26
|
|
47
27
|
def start(&block)
|
@@ -50,51 +30,70 @@ module Vx
|
|
50
30
|
end
|
51
31
|
end
|
52
32
|
|
53
|
-
def
|
54
|
-
|
55
|
-
'Cmd'
|
56
|
-
'Image'
|
33
|
+
def create_container_options
|
34
|
+
Default.create_container_options.merge(
|
35
|
+
'Cmd' => init,
|
36
|
+
'Image' => image,
|
57
37
|
)
|
58
38
|
end
|
59
39
|
|
40
|
+
def start_container_options
|
41
|
+
Default.start_container_options
|
42
|
+
end
|
43
|
+
|
60
44
|
private
|
61
45
|
|
62
46
|
def open_ssh_session(container)
|
63
|
-
host =
|
47
|
+
host = Default.ssh_host || container.json['NetworkSettings']['IPAddress']
|
64
48
|
|
65
49
|
ssh_options = {
|
66
50
|
password: password,
|
67
|
-
port:
|
51
|
+
port: Default.ssh_port,
|
68
52
|
paranoid: false,
|
69
53
|
forward_agent: false
|
70
54
|
}
|
71
|
-
|
55
|
+
|
56
|
+
instrumentation = {
|
57
|
+
container_type: "docker",
|
58
|
+
container: container.json,
|
59
|
+
ssh_host: host
|
60
|
+
}
|
61
|
+
|
72
62
|
with_retries ::Net::SSH::AuthenticationFailed, limit: 3, sleep: 3 do
|
63
|
+
instrument("starting_ssh_session", instrumentation)
|
73
64
|
open_ssh(host, user, ssh_options) do |ssh|
|
74
|
-
logger.info "ssh session opened"
|
75
65
|
yield Spawner.new(container, ssh, remote_dir)
|
76
66
|
end
|
77
67
|
end
|
78
68
|
end
|
79
69
|
|
80
70
|
def start_container(&block)
|
81
|
-
container =
|
71
|
+
container = instrument("create_container", container_type: "docker", container_options: create_container_options) do
|
72
|
+
::Docker::Container.create create_container_options
|
73
|
+
end
|
74
|
+
|
75
|
+
instrumentation = {
|
76
|
+
container_type: "docker",
|
77
|
+
container: container.json,
|
78
|
+
container_options: start_container_options,
|
79
|
+
}
|
82
80
|
|
83
81
|
with_retries ::Docker::Error::NotFoundError, limit: 3, sleep: 3 do
|
84
|
-
|
82
|
+
instrument("start_container", instrumentation) do
|
83
|
+
container.start start_container_options
|
84
|
+
end
|
85
85
|
end
|
86
86
|
|
87
87
|
begin
|
88
|
-
logger.info "start container #{container.id}"
|
89
88
|
sleep 3
|
90
89
|
yield container
|
91
90
|
ensure
|
92
|
-
|
93
|
-
|
91
|
+
instrument("kill_container", instrumentation) do
|
92
|
+
container.kill
|
93
|
+
end
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
|
98
97
|
end
|
99
98
|
end
|
100
99
|
end
|
@@ -7,29 +7,32 @@ module Vx
|
|
7
7
|
|
8
8
|
class Local
|
9
9
|
|
10
|
+
include Instrument
|
11
|
+
|
10
12
|
autoload :Spawner, File.expand_path("../local/spawner", __FILE__)
|
11
13
|
|
12
|
-
attr_reader :work_dir
|
14
|
+
attr_reader :work_dir
|
13
15
|
|
14
16
|
def initialize(options = {})
|
15
17
|
@work_dir = options[:work_dir] || default_work_dir
|
16
18
|
@work_dir = File.expand_path(@work_dir)
|
17
|
-
@logger = options[:logger] || Logger.new(STDOUT)
|
18
19
|
end
|
19
20
|
|
20
21
|
def start(&block)
|
21
|
-
|
22
|
-
|
22
|
+
instrument( "start_container", container_type: 'local', container: { work_dir: work_dir }) do
|
23
|
+
FileUtils.rm_rf(work_dir)
|
24
|
+
FileUtils.mkdir_p(work_dir)
|
25
|
+
end
|
23
26
|
|
24
27
|
spawner = Spawner.new(work_dir)
|
25
|
-
|
28
|
+
|
26
29
|
yield spawner
|
27
30
|
end
|
28
31
|
|
29
32
|
private
|
30
33
|
|
31
34
|
def default_work_dir
|
32
|
-
"#{Dir.tmpdir}/.
|
35
|
+
"#{Dir.tmpdir}/.vx_local_connector"
|
33
36
|
end
|
34
37
|
|
35
38
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Vx
|
2
|
+
module ContainerConnector
|
3
|
+
module Instrument
|
4
|
+
|
5
|
+
def instrument(name, payload, &block)
|
6
|
+
name = "#{name}.container_connector.vx"
|
7
|
+
|
8
|
+
if ENV['VX_CONTAINER_CONNECTOR_DEBUG']
|
9
|
+
$stdout.puts " --> #{name}: #{payload}"
|
10
|
+
end
|
11
|
+
|
12
|
+
if inst = ContainerConnector.instrumenter
|
13
|
+
inst.instrument(name, payload, &block)
|
14
|
+
else
|
15
|
+
yield if block_given?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -4,13 +4,15 @@ require File.expand_path("../container_connector/errors", __FILE__)
|
|
4
4
|
module Vx
|
5
5
|
module ContainerConnector
|
6
6
|
|
7
|
-
autoload :Local,
|
8
|
-
autoload :Docker,
|
9
|
-
autoload :Retriable,
|
10
|
-
|
7
|
+
autoload :Local, File.expand_path("../container_connector/local", __FILE__)
|
8
|
+
autoload :Docker, File.expand_path("../container_connector/docker", __FILE__)
|
9
|
+
autoload :Retriable, File.expand_path("../container_connector/mixin/retriable", __FILE__)
|
10
|
+
autoload :Instrument, File.expand_path("../container_connector/mixin/instrument", __FILE__)
|
11
11
|
|
12
12
|
extend self
|
13
13
|
|
14
|
+
attr_accessor :instrumenter
|
15
|
+
|
14
16
|
def lookup(name, options = {})
|
15
17
|
case name.to_sym
|
16
18
|
when :docker
|
data/spec/lib/docker_spec.rb
CHANGED
@@ -5,14 +5,6 @@ describe Vx::ContainerConnector::Docker do
|
|
5
5
|
|
6
6
|
it { should be }
|
7
7
|
|
8
|
-
its(:logger) { should be }
|
9
|
-
|
10
|
-
context "container_options" do
|
11
|
-
subject { conn.container_options }
|
12
|
-
it { should eq("Cmd" => ["/sbin/init", "--startup-event", "dockerboot"],
|
13
|
-
"Image" => "dmexe/precise") }
|
14
|
-
end
|
15
|
-
|
16
8
|
context "user" do
|
17
9
|
subject { conn.user }
|
18
10
|
|
data/spec/lib/local_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Vx::ContainerConnector::Local do
|
|
8
8
|
|
9
9
|
context "work_dir" do
|
10
10
|
it "by default should be inside Dir.tmpdir" do
|
11
|
-
expect(conn.work_dir).to eq("#{Dir.tmpdir}/.
|
11
|
+
expect(conn.work_dir).to eq("#{Dir.tmpdir}/.vx_local_connector")
|
12
12
|
end
|
13
13
|
|
14
14
|
it "when passed via options, should be" do
|
@@ -37,7 +37,7 @@ describe Vx::ContainerConnector::Local do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
dir = "#{Dir.tmpdir}/.
|
40
|
+
dir = "#{Dir.tmpdir}/.vx_local_connector\n"
|
41
41
|
if RUBY_PLATFORM =~ /darwin/
|
42
42
|
dir.gsub!(/^\/var/, '/private/var')
|
43
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,12 @@
|
|
1
|
-
require File.expand_path '../../lib/vx/container_connector', __FILE__
|
2
|
-
|
3
1
|
Bundler.require(:test)
|
2
|
+
|
3
|
+
ENV['VX_ENV'] = 'test'
|
4
|
+
ENV['DOCKER_URL'] = "tcp://localhost:4243"
|
5
|
+
|
6
|
+
require File.expand_path '../../lib/vx/container_connector', __FILE__
|
4
7
|
require 'rspec/autorun'
|
5
8
|
|
6
9
|
Dir[File.expand_path("../..", __FILE__) + "/spec/support/**/*.rb"].each {|f| require f}
|
7
10
|
|
8
11
|
RSpec.configure do |config|
|
9
|
-
config.mock_with :rr
|
10
|
-
|
11
|
-
config.before(:suite) do
|
12
|
-
=begin
|
13
|
-
Vx::ContainerConnector::Docker.default_container_options.merge!(
|
14
|
-
'PortSpecs' => ['2022:22']
|
15
|
-
)
|
16
|
-
Vx::ContainerConnector::Docker.default_ssh_port 2223
|
17
|
-
Vx::ContainerConnector::Docker.host_to_connect_override 'localhost'
|
18
|
-
=end
|
19
|
-
end
|
20
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vx-container_connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Galinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docker-api
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rr
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '>='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '>='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
description: ' description '
|
98
84
|
email:
|
99
85
|
- dima.exe@gmail.com
|
@@ -109,10 +95,12 @@ files:
|
|
109
95
|
- Rakefile
|
110
96
|
- lib/vx/container_connector.rb
|
111
97
|
- lib/vx/container_connector/docker.rb
|
98
|
+
- lib/vx/container_connector/docker/default.rb
|
112
99
|
- lib/vx/container_connector/docker/spawner.rb
|
113
100
|
- lib/vx/container_connector/errors.rb
|
114
101
|
- lib/vx/container_connector/local.rb
|
115
102
|
- lib/vx/container_connector/local/spawner.rb
|
103
|
+
- lib/vx/container_connector/mixin/instrument.rb
|
116
104
|
- lib/vx/container_connector/mixin/retriable.rb
|
117
105
|
- lib/vx/container_connector/version.rb
|
118
106
|
- spec/lib/container_connector_spec.rb
|