spurious 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 267928e2d8b40c77bc453cc5548d1305e2c5ad35
4
+ data.tar.gz: abd8ac6ba42b552cb0539d2ae7a5ddbaac38dff4
5
+ SHA512:
6
+ metadata.gz: c86e9fd3584e407556de56db6fc09da5bfc5f26560adb0a2b413cc5aa7907c694b383c009d87b8b3644a06624fe46c50504fad21f9efc809b73ef18f03823542
7
+ data.tar.gz: a17a5a3204a1fd3e2c923ad0069011001e6ece6b4636b6c32d7970611b04cc232c4ce07e041d2760305c252d818bd996dccd0d8012a71a6a90cf4c0a20be0f1a
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spurious.gemspec
4
+ gemspec
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,29 @@
1
+ # Spurious
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'spurious'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install spurious
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/stevenjack/spurious/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/spurious ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ $: << File.join(Pathname.new(__FILE__).dirname.parent, 'lib')
5
+
6
+ require 'spurious/app'
7
+ Spurious::App.start
@@ -0,0 +1,78 @@
1
+ require 'thor'
2
+ require 'eventmachine'
3
+ require 'spurious/command/state'
4
+ require 'spurious/command/ports'
5
+ require 'timeout'
6
+
7
+ module Spurious
8
+ class App < Thor
9
+ include Thor::Actions
10
+
11
+ namespace :spurious
12
+
13
+ class_option :server_port, :type => :string, :default => ENV.fetch('SPURIOUS_SERVER_PORT', 4590), :desc => "The port of spurious server"
14
+ class_option :server_ip, :type => :string, :default => ENV.fetch('SPURIOUS_SERVER_IP', 'localhost'), :desc => "The ip address of spurious server"
15
+ def initialize(*args)
16
+ super
17
+ end
18
+
19
+
20
+ def self.state_methods
21
+ %w(init start update stop delete).each do |meth|
22
+ desc meth, "#{meth} for the spurious containers"
23
+ define_method(meth) do
24
+ event_loop meth.to_sym
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ state_methods
31
+
32
+ desc "ports", "List ports for the spurious containers"
33
+ def ports
34
+ EventMachine.run do
35
+ EventMachine::connect options[:server_ip], options[:server_port], Spurious::Command::Ports, :ports, self
36
+ end
37
+ end
38
+
39
+ protected
40
+
41
+ def server_available?
42
+ available = true
43
+
44
+ Timeout.timeout(1) do
45
+ begin
46
+ TCPSocket.new(options[:server_ip], options[:server_port])
47
+ rescue Exception
48
+ available = false
49
+ say <<-eos
50
+
51
+ #{set_color("Connection to spurious server: #{options[:server_ip]}:#{options[:server_port]} has timed out.", :red)}
52
+
53
+ #{set_color('To check the status of the server, run:', :white)}
54
+ #{set_color('$ spurious-server status', :cyan)}
55
+
56
+ #{set_color('To start the server, run:', :white)}
57
+ #{set_color('$ spurious-server start', :cyan)}
58
+
59
+ eos
60
+ end
61
+ end
62
+
63
+ available
64
+
65
+ end
66
+
67
+
68
+ def event_loop(type)
69
+
70
+ if server_available? then
71
+ EventMachine.run do
72
+ EventMachine::connect options[:server_ip], options[:server_port], Spurious::Command::State, type, self
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,46 @@
1
+ require 'eventmachine'
2
+ require 'json'
3
+ require 'spurious/command/state'
4
+
5
+ module Spurious
6
+ module Command
7
+ class Ports < State
8
+
9
+ def receive_data(data)
10
+ parsed_data = JSON.parse(data.strip)
11
+ data = []
12
+ parsed_data['response'].each do |type, mapping|
13
+ mapping.each do |mapping_data|
14
+ data << [
15
+ type,
16
+ mapping_data["GuestPort"],
17
+ mapping_data["HostPort"]
18
+ ]
19
+ end
20
+ end
21
+
22
+ app.say "\n"
23
+
24
+ app.print_table(
25
+ build_table(['Service', 'Guest port', 'Host port'], data)
26
+ ) unless parsed_data['response'].empty?
27
+
28
+ EventMachine.stop_event_loop if parsed_data['close']
29
+
30
+ end
31
+
32
+ def build_table(headers, data)
33
+ [].tap do |table|
34
+ table << headers.reduce([]) do |array, header|
35
+ array << app.set_color(header, :cyan)
36
+ end
37
+
38
+ data.each do |items|
39
+ table << items.map { |item| app.set_color(item, :white) }
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ require 'eventmachine'
2
+ require 'json'
3
+ require 'thor'
4
+
5
+ module Spurious
6
+ module Command
7
+ class State < EventMachine::Connection
8
+ attr_accessor :app
9
+ attr_reader :type
10
+
11
+ include Thor::Actions
12
+
13
+ def initialize(type, app, *args)
14
+ super
15
+ @type = type
16
+ @app = app
17
+ end
18
+
19
+ def post_init
20
+ send_data JSON.generate(:type => type)
21
+ end
22
+
23
+ def receive_data(data)
24
+ data_parts = data.split("\n")
25
+ data_parts.each do |data_part|
26
+ parsed_data = JSON.parse(data_part.strip)
27
+ app.say parsed_data['response'], parsed_data['type'] == 'error' ? :red : :green
28
+ EventMachine.stop_event_loop if parsed_data['close']
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ require 'yaml'
2
+
3
+ module Spurious
4
+ module Config
5
+
6
+ CONFIG_LOCATION = 'config/containers.yaml'
7
+
8
+ def self.app
9
+ @@config ||= YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', CONFIG_LOCATION))
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Spurious
2
+ VERSION = "0.1.0"
3
+ end
data/lib/spurious.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "spurious/version"
2
+
3
+ module Spurious
4
+ # Your code goes here...
5
+ end
data/spec/app_spec.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ describe Spurious::App do
4
+
5
+ describe "#init" do
6
+
7
+ it 'Pulls the correct images down' do
8
+ docker_provider = double('Docker::Image', :pull => false)
9
+ allow(Docker::Image).to receive(:create).twice.and_return(true)
10
+ allow(Spurious::Config).to receive(:app).and_return({:images => {:item1 => nil, :item2 => nil}})
11
+
12
+ args = %w[init]
13
+ content = capture(:stdout) { Spurious::App.start args }
14
+
15
+ expect(content).to match(/2 containers successfully initialized/)
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ describe Spurious::Config do
4
+
5
+ describe ".app" do
6
+
7
+ it 'Loads the config' do
8
+ expect(Spurious::Config.app[:images]["bbcnews/fake-sqs".to_sym]).to eq({:port => 4568, :name => 'spurious-sqs'})
9
+
10
+ end
11
+
12
+ end
13
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'pathname'
2
+ $: << File.join(Pathname.new(__FILE__).dirname.parent, 'lib')
3
+
4
+ require 'spurious/app'
5
+ require 'spurious/config'
6
+ require 'stringio'
7
+
8
+ def capture(stream)
9
+ begin
10
+ stream = stream.to_s
11
+ eval "$#{stream} = StringIO.new"
12
+ yield
13
+ result = eval("$#{stream}").string
14
+ ensure
15
+ eval("$#{stream} = #{stream.upcase}")
16
+ end
17
+
18
+ result
19
+ end
data/spurious.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spurious/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spurious"
8
+ spec.version = Spurious::VERSION
9
+ spec.authors = ["Steven Jack"]
10
+ spec.email = ["stevenmajack@gmail.com"]
11
+ spec.summary = %q{Spurious is a cli tool that interacts with the spurious server}
12
+ spec.description = %q{Spurious is a cli tool that interacts with the spurious server}
13
+ spec.homepage = ""
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_runtime_dependency "docker"
22
+ spec.add_runtime_dependency "docker-api"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+
28
+ spec.add_runtime_dependency "spurious-server"
29
+ spec.add_runtime_dependency "eventmachine"
30
+ spec.add_runtime_dependency "timeout"
31
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spurious
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steven Jack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: docker-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
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: spurious-server
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
+ - !ruby/object:Gem::Dependency
98
+ name: eventmachine
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timeout
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Spurious is a cli tool that interacts with the spurious server
126
+ email:
127
+ - stevenmajack@gmail.com
128
+ executables:
129
+ - spurious
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - bin/spurious
139
+ - lib/spurious.rb
140
+ - lib/spurious/app.rb
141
+ - lib/spurious/command/ports.rb
142
+ - lib/spurious/command/state.rb
143
+ - lib/spurious/config.rb
144
+ - lib/spurious/version.rb
145
+ - spec/app_spec.rb
146
+ - spec/config_spec.rb
147
+ - spec/helper.rb
148
+ - spurious.gemspec
149
+ homepage: ''
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.2.2
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Spurious is a cli tool that interacts with the spurious server
173
+ test_files:
174
+ - spec/app_spec.rb
175
+ - spec/config_spec.rb
176
+ - spec/helper.rb