spurious-server 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/bin/spurious-server +16 -0
- data/config/images.yaml +23 -0
- data/lib/spurious/server.rb +23 -0
- data/lib/spurious/server/app.rb +39 -0
- data/lib/spurious/server/config.rb +22 -0
- data/lib/spurious/server/state/base.rb +55 -0
- data/lib/spurious/server/state/delete.rb +28 -0
- data/lib/spurious/server/state/error.rb +29 -0
- data/lib/spurious/server/state/factory.rb +39 -0
- data/lib/spurious/server/state/init.rb +38 -0
- data/lib/spurious/server/state/ports.rb +40 -0
- data/lib/spurious/server/state/stop.rb +24 -0
- data/lib/spurious/server/state/up.rb +28 -0
- data/lib/spurious/server/state/update.rb +20 -0
- data/lib/spurious/server/version.rb +5 -0
- data/spec/app_spec.rb +31 -0
- data/spec/config_spec.rb +37 -0
- data/spec/factory_spec.rb +14 -0
- data/spec/fixtures/config.yaml +6 -0
- data/spec/helper/client.rb +21 -0
- data/spec/helper/spec.rb +18 -0
- data/spec/server_spec.rb +17 -0
- data/spec/state_init_spec.rb +26 -0
- data/spurious-server.gemspec +30 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b00c1454c5618c7808f7b7a374f1b4b4f020a04
|
4
|
+
data.tar.gz: 4b6b8c18d0dcae10060988c3950b5260208e2bbf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 815c667179bd03cff5d31b54a30d63ace256741d403542e691096ce8ee862e6b970eb45b6ab4e6851304756cecb97ae468b88e66a295647ed6e8b9a8614e2d61
|
7
|
+
data.tar.gz: 179d4b5eeac8d8872242ea9f50e6339a0c1cdb9a689d623cbcb94e6593087aea050ab1f3392a46133884efbe11fdc55f5068c799becd972a5b834978f417e9ef
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Steven Jack
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Steven Jack
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Spurious::Server
|
2
|
+
|
3
|
+
Spurious server is used by the [spurious](https://www.github.com/stevenjack/spurious) cli client.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'spurious-server'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install spurious-server
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```bash
|
22
|
+
spurious-server start
|
23
|
+
```
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( http://github.com/<my-github-username>/spurious-server/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/spurious-server
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
require 'spurious/server'
|
5
|
+
require 'daemons'
|
6
|
+
|
7
|
+
Daemons.run_proc(
|
8
|
+
'Spurious Server', # name of daemon
|
9
|
+
:dir => '/tmp', # directory where pid file will be stored
|
10
|
+
:log_output => true
|
11
|
+
) do
|
12
|
+
Docker.url = 'http://0.0.0.0:2375'
|
13
|
+
EventMachine.run {
|
14
|
+
Spurious::Server.run!
|
15
|
+
}
|
16
|
+
end
|
data/config/images.yaml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
'spurious-sqs':
|
2
|
+
:image: 'bbcnews/fake-sqs'
|
3
|
+
|
4
|
+
'spurious-s3':
|
5
|
+
:image: 'bbcnews/fake-s3'
|
6
|
+
|
7
|
+
'spurious-dynamo':
|
8
|
+
:image: 'smaj/local-dynamo'
|
9
|
+
|
10
|
+
'spurious-elasticache':
|
11
|
+
:image: 'smaj/fake-elasticache'
|
12
|
+
:link:
|
13
|
+
- 'spurious-memcached:memcached01'
|
14
|
+
:env:
|
15
|
+
FAKEELASTICACHE_DEFAULT_HOST: '127.0.0.1'
|
16
|
+
|
17
|
+
'spurious-elasticache-docker':
|
18
|
+
:image: 'smaj/fake-elasticache'
|
19
|
+
:link:
|
20
|
+
- 'spurious-memcached:memcached01'
|
21
|
+
|
22
|
+
'spurious-memcached':
|
23
|
+
:image: 'smaj/memcached'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spurious/server/version"
|
2
|
+
require "eventmachine"
|
3
|
+
require "spurious/server/app"
|
4
|
+
|
5
|
+
module Spurious
|
6
|
+
module Server
|
7
|
+
|
8
|
+
@@containers = []
|
9
|
+
|
10
|
+
def self.add_container(name, meta)
|
11
|
+
@@containers[name] = meta
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_container(name)
|
15
|
+
@@containers[name]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.run!
|
19
|
+
EventMachine.start_server '0.0.0.0', 4590, Spurious::Server::App
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spurious/server/state/factory"
|
2
|
+
require "spurious/server/config"
|
3
|
+
|
4
|
+
require "eventmachine"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module Spurious
|
8
|
+
module Server
|
9
|
+
class App < EventMachine::Connection
|
10
|
+
|
11
|
+
def receive_data data
|
12
|
+
payload = parse_payload data
|
13
|
+
state(payload[:type]).execute!
|
14
|
+
rescue Exception => e
|
15
|
+
puts e.message
|
16
|
+
state(:error).tap { |s| s.message = "JSON payload malformed" }.execute!
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def state(type)
|
22
|
+
Spurious::Server::State::Factory.create(type, self, config)
|
23
|
+
end
|
24
|
+
|
25
|
+
def config
|
26
|
+
@config ||= Spurious::Server::Config.new(config_location)
|
27
|
+
end
|
28
|
+
|
29
|
+
def config_location
|
30
|
+
File.join(File.dirname(__FILE__), '..','..', '..', 'config', 'images.yaml')
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_payload(payload)
|
34
|
+
JSON.parse(payload.strip, :symbolize_names => true)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Spurious
|
4
|
+
module Server
|
5
|
+
class Config
|
6
|
+
attr_accessor :app
|
7
|
+
|
8
|
+
def initialize(config_location)
|
9
|
+
@app = YAML::load_file(config_location)
|
10
|
+
end
|
11
|
+
|
12
|
+
def name_exists?(name)
|
13
|
+
app.has_key? name
|
14
|
+
end
|
15
|
+
|
16
|
+
def for(name)
|
17
|
+
app[name]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'peach'
|
3
|
+
require 'spurious/server'
|
4
|
+
|
5
|
+
module Spurious
|
6
|
+
module Server
|
7
|
+
module State
|
8
|
+
class Base
|
9
|
+
attr_accessor :connection, :config
|
10
|
+
|
11
|
+
def initialize(connection, config)
|
12
|
+
@connection = connection
|
13
|
+
@config = config
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute!
|
17
|
+
raise NotImplementedError("You must implement execute!")
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def spurious_containers
|
23
|
+
Docker::Container.all(:all => true).select do |container|
|
24
|
+
config.name_exists?(sanitize(container.json["Name"]))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def app_config
|
29
|
+
config.app
|
30
|
+
end
|
31
|
+
|
32
|
+
def container_config(image)
|
33
|
+
config.for sanitize(image)
|
34
|
+
end
|
35
|
+
|
36
|
+
def send(data)
|
37
|
+
connection.send_data JSON.generate({:type => state_identifer, :response => data}) + "\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def sanitize(name)
|
41
|
+
name.gsub('/', '')
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def state_identifer
|
47
|
+
self.class.to_s.downcase.split("::").last
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'peach'
|
3
|
+
require 'spurious/server/state/base'
|
4
|
+
|
5
|
+
module Spurious
|
6
|
+
module Server
|
7
|
+
module State
|
8
|
+
class Delete < Base
|
9
|
+
|
10
|
+
def execute!
|
11
|
+
containers = spurious_containers.length
|
12
|
+
spurious_containers.peach do |container|
|
13
|
+
send "Removing container #{container.json["Name"]}..."
|
14
|
+
container.tap do |c|
|
15
|
+
c.kill
|
16
|
+
c.delete(:force => true)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
send "#{containers} containers successfully removed"
|
20
|
+
|
21
|
+
connection.unbind
|
22
|
+
rescue Exception => e
|
23
|
+
puts e.message
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "docker"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Spurious
|
5
|
+
module Server
|
6
|
+
module State
|
7
|
+
class Error
|
8
|
+
attr_reader :connection
|
9
|
+
attr_accessor :message
|
10
|
+
|
11
|
+
def initialize(connection, message = nil)
|
12
|
+
@connection = connection
|
13
|
+
@message = message
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute!
|
17
|
+
send :type => 'error', :response => { :message => message }
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def send(data)
|
23
|
+
connection.send_data JSON.generate(data)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spurious/server/state/init'
|
2
|
+
require 'spurious/server/state/up'
|
3
|
+
require 'spurious/server/state/stop'
|
4
|
+
require 'spurious/server/state/delete'
|
5
|
+
require 'spurious/server/state/update'
|
6
|
+
require 'spurious/server/state/ports'
|
7
|
+
require 'spurious/server/state/error'
|
8
|
+
|
9
|
+
module Spurious
|
10
|
+
module Server
|
11
|
+
module State
|
12
|
+
module Factory
|
13
|
+
|
14
|
+
def self.create(type, connection, config)
|
15
|
+
case type.to_sym
|
16
|
+
when :init
|
17
|
+
Init.new(connection, config)
|
18
|
+
when :up
|
19
|
+
Up.new(connection, config)
|
20
|
+
when :stop
|
21
|
+
Stop.new(connection, config)
|
22
|
+
when :ports
|
23
|
+
Ports.new(connection, config)
|
24
|
+
|
25
|
+
when :delete
|
26
|
+
Delete.new(connection, config)
|
27
|
+
when :update
|
28
|
+
Update.new(connection, config)
|
29
|
+
when :error
|
30
|
+
Error.new(connection)
|
31
|
+
else
|
32
|
+
Error.new(connection, "Type: #{type} is not recognised")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'peach'
|
3
|
+
require 'spurious/server'
|
4
|
+
require 'spurious/server/state/base'
|
5
|
+
|
6
|
+
module Spurious
|
7
|
+
module Server
|
8
|
+
module State
|
9
|
+
class Init < Base
|
10
|
+
|
11
|
+
def execute!
|
12
|
+
|
13
|
+
app_config.each do |name, meta|
|
14
|
+
begin
|
15
|
+
send "Pulling #{name} from the public repo..."
|
16
|
+
image_meta = { 'fromImage' => meta[:image]}
|
17
|
+
image_meta['Env'] = meta[:env] unless meta[:env].nil?
|
18
|
+
Docker::Image.create(image_meta)
|
19
|
+
|
20
|
+
send "Creating container with name: #{name}"
|
21
|
+
Docker::Container.create("name" => name, "Image" => meta[:image])
|
22
|
+
|
23
|
+
rescue Exception => e
|
24
|
+
case e.message
|
25
|
+
when /409 Conflict/
|
26
|
+
puts "Container with name: #{name} already exists"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
send "#{config.app.length} containers successfully initialized"
|
32
|
+
connection.unbind
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'peach'
|
3
|
+
require 'spurious/server/state/base'
|
4
|
+
|
5
|
+
module Spurious
|
6
|
+
module Server
|
7
|
+
module State
|
8
|
+
class Ports < Base
|
9
|
+
|
10
|
+
def execute!
|
11
|
+
ports = {}
|
12
|
+
spurious_containers.peach do |container|
|
13
|
+
config = container_config(container.json["Name"])
|
14
|
+
ports[sanitize(container.json["Name"])] = []
|
15
|
+
|
16
|
+
if !container.json["NetworkSettings"]["Ports"].nil? then
|
17
|
+
|
18
|
+
container.json["NetworkSettings"]["Ports"].each do |guest, mapping|
|
19
|
+
mapping.each do |map|
|
20
|
+
ports[sanitize(container.json["Name"])] << {
|
21
|
+
:GuestPort => guest.split('/').first,
|
22
|
+
:HostPort => map["HostPort"]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
send ports
|
31
|
+
|
32
|
+
connection.unbind
|
33
|
+
rescue Exception => e
|
34
|
+
puts e.message
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'peach'
|
3
|
+
require 'spurious/server/state/base'
|
4
|
+
|
5
|
+
module Spurious
|
6
|
+
module Server
|
7
|
+
module State
|
8
|
+
class Stop < Base
|
9
|
+
|
10
|
+
def execute!
|
11
|
+
spurious_containers.peach do |container|
|
12
|
+
send "Stopping container #{container.json["Name"]}..."
|
13
|
+
container.stop
|
14
|
+
end
|
15
|
+
send "#{spurious_containers.length} containers successfully stopped"
|
16
|
+
|
17
|
+
connection.unbind
|
18
|
+
rescue Exception => e
|
19
|
+
puts e.message
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'peach'
|
3
|
+
require 'spurious/server/state/base'
|
4
|
+
|
5
|
+
module Spurious
|
6
|
+
module Server
|
7
|
+
module State
|
8
|
+
class Up < Base
|
9
|
+
|
10
|
+
def execute!
|
11
|
+
spurious_containers.each do |container|
|
12
|
+
config = container_config(container.json["Name"])
|
13
|
+
send "Starting container #{container.json["Name"]}..."
|
14
|
+
meta = {"PublishAllPorts" => true}
|
15
|
+
meta["Links"] = config[:link] unless config[:link].nil?
|
16
|
+
container.start meta
|
17
|
+
end
|
18
|
+
send "#{spurious_containers.length} containers successfully started"
|
19
|
+
|
20
|
+
connection.unbind
|
21
|
+
rescue Exception => e
|
22
|
+
puts e.message
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'peach'
|
3
|
+
require 'json'
|
4
|
+
require 'spurious/server/state/base'
|
5
|
+
|
6
|
+
module Spurious
|
7
|
+
module Server
|
8
|
+
module State
|
9
|
+
class Update < Base
|
10
|
+
|
11
|
+
def execute!
|
12
|
+
['stop', 'delete', 'init', 'up'].each do |state|
|
13
|
+
connection.receive_data(JSON.generate({:type => state}))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/app_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "helper/spec"
|
2
|
+
|
3
|
+
describe Spurious::Server::App do
|
4
|
+
subject(:app) { Spurious::Server::App.new('blah')}
|
5
|
+
|
6
|
+
describe "#receive_data(data)" do
|
7
|
+
let(:data) { {:type => :init} }
|
8
|
+
let(:state) { double('Spurious::Server::State::Init', :execute! => nil) }
|
9
|
+
|
10
|
+
it "responds to an init message" do
|
11
|
+
expect(state).to receive(:execute!)
|
12
|
+
expect(Spurious::Server::State::Factory).to receive(:create).and_return(state)
|
13
|
+
app.receive_data(data.to_json)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "sends an error back if payload is malformed" do
|
17
|
+
response = "{\"type\":\"error\",\"response\":{\"message\":\"JSON payload malformed\"}}"
|
18
|
+
expect(EventMachine).to receive(:send_data).with(anything(), response, response.length)
|
19
|
+
app.receive_data("{ Test / Malformed }")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "sends an error back if the type is not recognised" do
|
23
|
+
data[:type] = 'test'
|
24
|
+
response = "{\"type\":\"error\",\"response\":{\"message\":\"Type: test is not recognised\"}}"
|
25
|
+
expect(EventMachine).to receive(:send_data).with(anything(), response, response.length)
|
26
|
+
app.receive_data(data.to_json)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "helper/spec"
|
2
|
+
|
3
|
+
describe Spurious::Server::Config do
|
4
|
+
let(:expected_hash) {
|
5
|
+
{
|
6
|
+
'foo-bar' => {
|
7
|
+
:image => 'foo/bar',
|
8
|
+
:link => [
|
9
|
+
'foo:bar'
|
10
|
+
],
|
11
|
+
:env => {
|
12
|
+
'FOO' => 'bar'
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
let (:config_location) { File.join(File.dirname(__FILE__),'fixtures', 'config.yaml') }
|
18
|
+
let (:config) { Spurious::Server::Config.new(config_location) }
|
19
|
+
|
20
|
+
describe ".app" do
|
21
|
+
it "Loads the config from a yaml file" do
|
22
|
+
expect(config.app).to be_a(Hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "Has the data needed to be a container" do
|
26
|
+
expect(config.app['foo-bar']).to eq(expected_hash['foo-bar'])
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".name_exists(name)" do
|
32
|
+
it "Indicates that an name exists in the config" do
|
33
|
+
expect(config.name_exists? expected_hash.keys[0]).to be_truthy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "helper/spec"
|
2
|
+
|
3
|
+
describe Spurious::Server::State::Factory do
|
4
|
+
|
5
|
+
it "Returns an instance based on the specified type" do
|
6
|
+
app_double = double('Spurious::Server::App')
|
7
|
+
config_stub = { 'test/image' => {:foo => :bar} }
|
8
|
+
state = Spurious::Server::State::Factory.create(:init, app_double, config_stub)
|
9
|
+
|
10
|
+
expect(state).to be_a(Spurious::Server::State::Init)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
module Helper
|
4
|
+
class Client < EventMachine::Connection
|
5
|
+
|
6
|
+
attr_accessor :received_data
|
7
|
+
attr_reader :data_to_send
|
8
|
+
|
9
|
+
def initialize(data_to_send = 'test')
|
10
|
+
@data_to_send = data_to_send
|
11
|
+
end
|
12
|
+
|
13
|
+
def post_init
|
14
|
+
send_data data_to_send
|
15
|
+
end
|
16
|
+
|
17
|
+
def receive_data(data)
|
18
|
+
received_data = data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/helper/spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
+
|
3
|
+
require "spurious/server"
|
4
|
+
require "spurious/server/app"
|
5
|
+
require "spurious/server/state/factory"
|
6
|
+
require "spurious/server/config"
|
7
|
+
require "helper/client"
|
8
|
+
require "eventmachine"
|
9
|
+
require "json"
|
10
|
+
|
11
|
+
def event_timer(timeout = 1)
|
12
|
+
EventMachine.add_timer timeout do
|
13
|
+
puts 'Second passed, stopping event loop'
|
14
|
+
EventMachine.stop_event_loop
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
data/spec/server_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "helper/spec"
|
2
|
+
|
3
|
+
describe Spurious::Server do
|
4
|
+
|
5
|
+
it "starts a server and receives data" do
|
6
|
+
EventMachine.run {
|
7
|
+
|
8
|
+
Spurious::Server.run!
|
9
|
+
expect_any_instance_of(Spurious::Server::App).to receive(:receive_data)
|
10
|
+
EventMachine.connect '0.0.0.0', 4590, Helper::Client
|
11
|
+
|
12
|
+
event_timer
|
13
|
+
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "helper/spec"
|
2
|
+
|
3
|
+
describe Spurious::Server::State::Init do
|
4
|
+
|
5
|
+
it "Pulls down the docker images down and sends response back to client" do
|
6
|
+
connection_double = double('Spurious::Server::App')
|
7
|
+
config_stub = {
|
8
|
+
:foo => {
|
9
|
+
:image => 'foo/bar',
|
10
|
+
:name => 'foo-bar'
|
11
|
+
}
|
12
|
+
}
|
13
|
+
config = double('Spurious::Server::Config', :app => config_stub, :length => 0)
|
14
|
+
|
15
|
+
state = Spurious::Server::State::Init.new(connection_double, config)
|
16
|
+
allow(Docker::Image).to receive(:create).once.with('fromImage' => 'foo/bar').and_return(true)
|
17
|
+
allow(Docker::Container).to receive(:create).once.with('name' => 'foo-bar', 'Image' => 'foo/bar').and_return(true)
|
18
|
+
|
19
|
+
expect(connection_double).to receive(:send_data).exactly(3).times
|
20
|
+
expect(connection_double).to receive(:unbind)
|
21
|
+
state.execute!
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spurious/server/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "spurious-server"
|
8
|
+
spec.version = Spurious::Server::VERSION
|
9
|
+
spec.authors = ["Steven Jack"]
|
10
|
+
spec.email = ["stevenmajack@gmail.com"]
|
11
|
+
spec.summary = %q{The server component that the spurious cli client connects to}
|
12
|
+
spec.description = %q{The server component that the spurious cli client connects to}
|
13
|
+
spec.homepage = "https://www.github.com/stevenjack/spurious-server§"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "eventmachine"
|
26
|
+
spec.add_runtime_dependency "docker-api"
|
27
|
+
spec.add_runtime_dependency "daemons"
|
28
|
+
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spurious-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Jack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: eventmachine
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: docker-api
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: daemons
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: The server component that the spurious cli client connects to
|
98
|
+
email:
|
99
|
+
- stevenmajack@gmail.com
|
100
|
+
executables:
|
101
|
+
- spurious-server
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/spurious-server
|
112
|
+
- config/images.yaml
|
113
|
+
- lib/spurious/server.rb
|
114
|
+
- lib/spurious/server/app.rb
|
115
|
+
- lib/spurious/server/config.rb
|
116
|
+
- lib/spurious/server/state/base.rb
|
117
|
+
- lib/spurious/server/state/delete.rb
|
118
|
+
- lib/spurious/server/state/error.rb
|
119
|
+
- lib/spurious/server/state/factory.rb
|
120
|
+
- lib/spurious/server/state/init.rb
|
121
|
+
- lib/spurious/server/state/ports.rb
|
122
|
+
- lib/spurious/server/state/stop.rb
|
123
|
+
- lib/spurious/server/state/up.rb
|
124
|
+
- lib/spurious/server/state/update.rb
|
125
|
+
- lib/spurious/server/version.rb
|
126
|
+
- spec/app_spec.rb
|
127
|
+
- spec/config_spec.rb
|
128
|
+
- spec/factory_spec.rb
|
129
|
+
- spec/fixtures/config.yaml
|
130
|
+
- spec/helper/.client.rb.swp
|
131
|
+
- spec/helper/client.rb
|
132
|
+
- spec/helper/spec.rb
|
133
|
+
- spec/server_spec.rb
|
134
|
+
- spec/state_init_spec.rb
|
135
|
+
- spurious-server.gemspec
|
136
|
+
homepage: https://www.github.com/stevenjack/spurious-server§
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.0.3
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: The server component that the spurious cli client connects to
|
160
|
+
test_files:
|
161
|
+
- spec/app_spec.rb
|
162
|
+
- spec/config_spec.rb
|
163
|
+
- spec/factory_spec.rb
|
164
|
+
- spec/fixtures/config.yaml
|
165
|
+
- spec/helper/.client.rb.swp
|
166
|
+
- spec/helper/client.rb
|
167
|
+
- spec/helper/spec.rb
|
168
|
+
- spec/server_spec.rb
|
169
|
+
- spec/state_init_spec.rb
|