spurious-server 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/spurious-server +5 -4
- data/lib/spurious/server.rb +2 -2
- data/lib/spurious/server/app.rb +9 -1
- data/lib/spurious/server/state/factory.rb +2 -3
- data/lib/spurious/server/state/start.rb +26 -5
- data/lib/spurious/server/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2857a7501dfa9a6cb090fdf6bd03b3c3b0e93b57
|
4
|
+
data.tar.gz: c9443a29a589e2d45dac9759800243c5b420a465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f78bd3c063f303a3087d4ca85992c190665daa2e1e8c3ee7d218f3a2a51b2be3e1c58a95976de2f7ce8627e227813e58856edcd1454204be565590a102faec27
|
7
|
+
data.tar.gz: 164f8828dde6b394ccfc2f9c60ee2658336d654ddc61474247f3b9d8395da084cea7b3227230df91decf6ffee87d7d700350c63263d01b98f99f5090b7e9b222
|
data/bin/spurious-server
CHANGED
@@ -7,13 +7,14 @@ require "spurious/server/version"
|
|
7
7
|
require 'daemons'
|
8
8
|
require "eventmachine"
|
9
9
|
|
10
|
-
|
11
|
-
ip
|
12
|
-
port
|
10
|
+
docker_host = ENV.fetch('DOCKER_HOST', 'tcp://0.0.0.0:2375')
|
11
|
+
ip = ENV.fetch('SPURIOUS_SERVER_IP', '0.0.0.0')
|
12
|
+
port = ENV.fetch('SPURIOUS_SERVER_PORT', 4590)
|
13
|
+
Docker.url = docker_host
|
13
14
|
|
14
15
|
Excon.defaults[:write_timeout] = 20000
|
15
16
|
Excon.defaults[:read_timeout] = 20000
|
16
17
|
|
17
18
|
Daemons.run_proc('Spurious Server', :dir => '/tmp', :log_output => true) do
|
18
|
-
EventMachine.run Spurious::Server.handle(ip, port)
|
19
|
+
EventMachine.run Spurious::Server.handle(ip, port, docker_host)
|
19
20
|
end
|
data/lib/spurious/server.rb
CHANGED
@@ -5,9 +5,9 @@ require "spurious/server/app"
|
|
5
5
|
module Spurious
|
6
6
|
module Server
|
7
7
|
|
8
|
-
def self.handle(ip, port)
|
8
|
+
def self.handle(ip, port, docker_host)
|
9
9
|
Proc.new do
|
10
|
-
EventMachine.start_server ip, port, Spurious::Server::App
|
10
|
+
EventMachine.start_server ip, port, Spurious::Server::App, docker_host
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/lib/spurious/server/app.rb
CHANGED
@@ -8,6 +8,14 @@ module Spurious
|
|
8
8
|
module Server
|
9
9
|
class App < EventMachine::Connection
|
10
10
|
|
11
|
+
def initialize(docker_host)
|
12
|
+
@docker_host = docker_host
|
13
|
+
end
|
14
|
+
|
15
|
+
def docker_host_ip
|
16
|
+
@docker_host[/\/\/([0-9\.]+):/,1]
|
17
|
+
end
|
18
|
+
|
11
19
|
def receive_data data
|
12
20
|
payload = parse_payload data
|
13
21
|
state(payload[:type]).execute!
|
@@ -19,7 +27,7 @@ module Spurious
|
|
19
27
|
protected
|
20
28
|
|
21
29
|
def state(type)
|
22
|
-
Spurious::Server::State::Factory.create(type, self, config)
|
30
|
+
Spurious::Server::State::Factory.create(type, self, config, docker_host_ip)
|
23
31
|
end
|
24
32
|
|
25
33
|
def config
|
@@ -11,17 +11,16 @@ module Spurious
|
|
11
11
|
module State
|
12
12
|
module Factory
|
13
13
|
|
14
|
-
def self.create(type, connection, config)
|
14
|
+
def self.create(type, connection, config, docker_host_ip)
|
15
15
|
case type.to_sym
|
16
16
|
when :init
|
17
17
|
Init.new(connection, config)
|
18
18
|
when :start
|
19
|
-
Start.new(connection, config)
|
19
|
+
Start.new(connection, config, docker_host_ip)
|
20
20
|
when :stop
|
21
21
|
Stop.new(connection, config)
|
22
22
|
when :ports
|
23
23
|
Ports.new(connection, config)
|
24
|
-
|
25
24
|
when :delete
|
26
25
|
Delete.new(connection, config)
|
27
26
|
when :update
|
@@ -1,20 +1,41 @@
|
|
1
1
|
require 'docker'
|
2
2
|
require 'peach'
|
3
3
|
require 'spurious/server/state/base'
|
4
|
+
require 'net/http'
|
4
5
|
|
5
6
|
module Spurious
|
6
7
|
module Server
|
7
8
|
module State
|
8
9
|
class Start < Base
|
10
|
+
attr_accessor :docker_host_ip
|
11
|
+
|
12
|
+
def initialize(connection, config, docker_host_ip)
|
13
|
+
super(connection, config)
|
14
|
+
@docker_host_ip = docker_host_ip
|
15
|
+
end
|
9
16
|
|
10
17
|
def execute!
|
11
18
|
spurious_containers.each do |container|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
begin
|
20
|
+
config = container_config(container.json["Name"])
|
21
|
+
send "Starting container #{container.json["Name"]}..."
|
22
|
+
meta = {"PublishAllPorts" => true}
|
23
|
+
meta["Links"] = config[:link] unless config[:link].nil?
|
24
|
+
container.start meta
|
25
|
+
|
26
|
+
if container.json["Name"] == '/spurious-sqs' then
|
27
|
+
port_setup = Proc.new do
|
28
|
+
port = container.json["NetworkSettings"]["Ports"]['4568/tcp'].first['HostPort']
|
29
|
+
Net::HTTP.get(URI("http://#{docker_host_ip}:#{port}/host-details?host=#{docker_host_ip}&port=#{port}"))
|
30
|
+
end
|
31
|
+
|
32
|
+
EM.add_timer(5) { EM.defer(port_setup) }
|
33
|
+
end
|
34
|
+
rescue Exception => e
|
35
|
+
error(e.message)
|
36
|
+
end
|
17
37
|
end
|
38
|
+
|
18
39
|
send "#{spurious_containers.length} containers successfully started", true
|
19
40
|
|
20
41
|
connection.unbind
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spurious-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|