battlestation 0.0.2 → 0.0.3
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.
- data/.gitignore +0 -1
- data/README.md +61 -0
- data/examples/Battlestation +26 -0
- data/lib/battlestation.rb +18 -4
- data/lib/battlestation/cli.rb +23 -5
- data/lib/battlestation/operations.rb +14 -0
- data/lib/battlestation/operations/executable_check.rb +29 -0
- data/lib/battlestation/operations/file_exists_check.rb +27 -0
- data/lib/battlestation/operations/process_check.rb +28 -0
- data/lib/battlestation/operations/runner.rb +24 -0
- data/lib/battlestation/plan.rb +17 -11
- data/lib/battlestation/task.rb +61 -0
- data/lib/battlestation/ui.rb +40 -1
- data/lib/battlestation/version.rb +1 -1
- data/spec/battle_station_spec.rb +21 -0
- data/spec/cli_spec.rb +80 -8
- data/spec/operations/executable_spec.rb +28 -0
- data/spec/operations/file_exists_spec.rb +30 -0
- data/spec/operations/process_spec.rb +36 -0
- data/spec/operations/runner_spec.rb +23 -0
- data/spec/plan_spec.rb +2 -8
- data/spec/support/helpers.rb +21 -6
- data/spec/task_spec.rb +15 -0
- metadata +29 -16
- data/examples/redis_plan.rb +0 -6
- data/lib/battlestation/dependency.rb +0 -31
- data/spec/dependency_spec.rb +0 -41
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -4,3 +4,64 @@
|
|
4
4
|
|
5
5
|
Battle Station allows you to get your development environment up-and-running *fast*. This is still a work in progress.
|
6
6
|
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install is as a gem
|
10
|
+
|
11
|
+
gem install battlestation
|
12
|
+
|
13
|
+
It's a good idea to add it to the `:development` group in your `Gemfile` as well, but the idea is that you can run
|
14
|
+
battlestation right after cloning your repository.
|
15
|
+
|
16
|
+
Also, battlestation could take care of running `bundle install` for you.
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
In the root of your project create a file named `Battlestation`. This file defines your Battlestation plan.
|
21
|
+
|
22
|
+
You can create tasks or dependencies that will be executed sequencially. Each task is composed of one ore more operations.
|
23
|
+
|
24
|
+
Operations include:
|
25
|
+
|
26
|
+
* Checking for an executable file in your path
|
27
|
+
* Check if a process is running
|
28
|
+
* Run system commands
|
29
|
+
|
30
|
+
These are three very basic building blocks, but together they allow you to plan your complete development environment. (We'll be happy to add more, but these'll get you started.)
|
31
|
+
|
32
|
+
See [this example](https://github.com/ariejan/battlestation/blob/master/examples/Battlestation) for details.
|
33
|
+
|
34
|
+
## Bugs / Feature Requests
|
35
|
+
|
36
|
+
Please post them to [Github Issues](https://github.com/ariejan/battlestation/issues).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Feel free to help out. Fork the project, write your specs and code and create a pull request.
|
41
|
+
|
42
|
+
## Contributors
|
43
|
+
|
44
|
+
* Ariejan de Vroom <ariejan> - original author
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
Copyright (c) 2012 Ariejan de Vroom
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
51
|
+
a copy of this software and associated documentation files (the
|
52
|
+
"Software"), to deal in the Software without restriction, including
|
53
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
54
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
55
|
+
permit persons to whom the Software is furnished to do so, subject to
|
56
|
+
the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
64
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
65
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
66
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
67
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Battlestation.plan do
|
2
|
+
|
3
|
+
dependency :redis do
|
4
|
+
executable 'redis-server'
|
5
|
+
process 'redis-server', resolution: "Install redis with `brew install redis` or `apt-get install redis`"
|
6
|
+
end
|
7
|
+
|
8
|
+
dependency :postgresql do
|
9
|
+
process 'postgres'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :bundler do
|
13
|
+
run 'bundle install'
|
14
|
+
end
|
15
|
+
|
16
|
+
task :database do
|
17
|
+
file_exists 'config/database.yml', resolution: "Copy config/database.yml.example to config/databse.yml"
|
18
|
+
run 'rake db:create'
|
19
|
+
run 'rake db:migrate'
|
20
|
+
end
|
21
|
+
|
22
|
+
task :documentation do
|
23
|
+
run 'rm -rf .yardoc'
|
24
|
+
run 'yard'
|
25
|
+
end
|
26
|
+
end
|
data/lib/battlestation.rb
CHANGED
@@ -2,23 +2,37 @@ require 'thor'
|
|
2
2
|
|
3
3
|
require "battlestation/version"
|
4
4
|
require 'battlestation/plan'
|
5
|
-
require 'battlestation/
|
5
|
+
require 'battlestation/task'
|
6
|
+
require 'battlestation/operations'
|
6
7
|
require 'battlestation/ui'
|
7
8
|
require 'battlestation/cli'
|
8
9
|
|
9
10
|
module Battlestation
|
10
|
-
|
11
11
|
class << self
|
12
12
|
attr_writer :ui
|
13
13
|
|
14
|
-
#
|
14
|
+
# Load the Battlestation or Battlestation.rb file
|
15
|
+
def load(filename)
|
16
|
+
plan = eval(File.read(filename))
|
17
|
+
return plan
|
18
|
+
rescue SyntaxError, NameError
|
19
|
+
Battlestation.ui.error("Your Battlestation has syntax errors.")
|
20
|
+
return nil
|
21
|
+
rescue
|
22
|
+
Battlestation.ui.error("Some error occured, but we're not sure what happened.")
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# Plan a new battlestation
|
27
|
+
#
|
28
|
+
# See README for details
|
15
29
|
def plan(opts = {}, &block)
|
16
30
|
return Plan.new opts, &block
|
17
31
|
end
|
18
32
|
|
33
|
+
# UI output
|
19
34
|
def ui
|
20
35
|
@ui ||= UI.new
|
21
36
|
end
|
22
37
|
end
|
23
|
-
|
24
38
|
end
|
data/lib/battlestation/cli.rb
CHANGED
@@ -7,6 +7,9 @@ module Battlestation
|
|
7
7
|
|
8
8
|
the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
|
9
9
|
Battlestation.ui = UI::Shell.new(the_shell)
|
10
|
+
|
11
|
+
Battlestation.ui.info("Manning battlestation...")
|
12
|
+
Battlestation.ui.info("")
|
10
13
|
end
|
11
14
|
|
12
15
|
check_unknown_options!
|
@@ -24,16 +27,31 @@ module Battlestation
|
|
24
27
|
in order to run this project.
|
25
28
|
D
|
26
29
|
def check
|
27
|
-
|
30
|
+
plan = nil
|
31
|
+
filenames = ["Battlestation", "Battlestation.rb"].select { |f| File.exists?(f) }
|
32
|
+
|
33
|
+
case filenames.size
|
34
|
+
when 0
|
28
35
|
Battlestation.ui.error "Could not read your Battlestation file"
|
29
36
|
exit 1
|
37
|
+
when 1
|
38
|
+
plan = Battlestation.load(filenames.first)
|
39
|
+
exit 1 if plan.nil?
|
40
|
+
else # >1
|
41
|
+
Battlestation.ui.error "You cannot have both Battlestation and Battlestation.rb files. Choose one, remove the other."
|
42
|
+
exit 1
|
30
43
|
end
|
31
44
|
|
32
|
-
#
|
33
|
-
plan
|
45
|
+
# Execute tasks in order
|
46
|
+
plan.tasks.each_pair do |name, task|
|
47
|
+
Battlestation.ui.group task.title do
|
48
|
+
# Show a notice for empty tasks
|
49
|
+
if task.operations.empty?
|
50
|
+
Battlestation.ui.notice("Nothing defined for #{task.name}")
|
51
|
+
end
|
34
52
|
|
35
|
-
|
36
|
-
|
53
|
+
task.execute
|
54
|
+
end
|
37
55
|
end
|
38
56
|
end
|
39
57
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Battlestation
|
2
|
+
module Operations
|
3
|
+
class ExecutableCheck < Base
|
4
|
+
attr_accessor :filename
|
5
|
+
|
6
|
+
def initialize(filename, opts = {})
|
7
|
+
@filename = filename
|
8
|
+
@type = :executable
|
9
|
+
@name = "executable-#{filename}"
|
10
|
+
@opts = opts
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
if executable_exists?
|
15
|
+
{ status: :okay, msg: "#{filename} executable found", name: name }
|
16
|
+
else
|
17
|
+
{ status: :fail, msg: "#{filename} executable not found", resolution: opts[:resolution], name: name }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def executable_exists?
|
23
|
+
files = %x(/usr/bin/env which #{filename}).split
|
24
|
+
return files.any? && File.executable?(files.first)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Battlestation
|
2
|
+
module Operations
|
3
|
+
class FileExistsCheck < Base
|
4
|
+
attr_accessor :filename
|
5
|
+
|
6
|
+
def initialize(filename, opts = {})
|
7
|
+
@filename = filename
|
8
|
+
@type = :file
|
9
|
+
@name = "file-#{filename}"
|
10
|
+
@opts = opts
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
if file_exists?
|
15
|
+
{ status: :okay, msg: "#{filename} found", name: name }
|
16
|
+
else
|
17
|
+
{ status: :fail, msg: "#{filename} not found", resolution: opts[:resolution], name: name }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def file_exists?
|
23
|
+
File.exists?(filename)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Battlestation
|
2
|
+
module Operations
|
3
|
+
class ProcessCheck < Base
|
4
|
+
attr_accessor :identifier
|
5
|
+
|
6
|
+
def initialize(identifier, opts = {})
|
7
|
+
@identifier = identifier
|
8
|
+
@type = :process
|
9
|
+
@name = "process-#{identifier}"
|
10
|
+
@opts = opts
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
if process_running?
|
15
|
+
{ status: :okay, msg: "#{identifier} up and running", name: name }
|
16
|
+
else
|
17
|
+
{ status: opts[:force_failure] ? :fail : :warn, msg: "#{identifier} not running", resolution: opts[:resolution], name: name }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def process_running?
|
23
|
+
processes = %x(ps aux | grep -i #{identifier} | grep -v grep).split
|
24
|
+
return processes.any?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Battlestation
|
2
|
+
module Operations
|
3
|
+
class Runner < Base
|
4
|
+
attr_accessor :cmd
|
5
|
+
|
6
|
+
def initialize(cmd, opts = {})
|
7
|
+
@cmd = cmd
|
8
|
+
@type = :runner
|
9
|
+
@name = "runner-#{cmd.split(" ").first}"
|
10
|
+
@opts = opts
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
Battlestation.ui.notice "Executing `#{cmd}`"
|
15
|
+
|
16
|
+
if system("#{cmd} &> /dev/null")
|
17
|
+
{ status: :okay, msg: "`#{cmd}` executed successfully", name: name }
|
18
|
+
else
|
19
|
+
{ status: :fail, msg: "`#{cmd}` failed to execute", name: name }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/battlestation/plan.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
module Battlestation
|
2
|
+
# This represents a complete Battlestation Plan,
|
3
|
+
# it may include checks and tasks.
|
2
4
|
class Plan
|
3
|
-
|
5
|
+
# Tasks to perform
|
6
|
+
attr_accessor :tasks
|
4
7
|
|
8
|
+
# Create a new plan.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# Battlestation.plan do
|
12
|
+
# dependency :mysql do
|
13
|
+
# executable 'mysql'
|
14
|
+
# end
|
15
|
+
# end
|
5
16
|
def initialize(opts = {}, &block)
|
6
|
-
@
|
7
|
-
|
17
|
+
@tasks = {}
|
8
18
|
instance_eval &block if block_given?
|
9
19
|
end
|
10
20
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def execute
|
16
|
-
results = []
|
17
|
-
dependencies.each_pair { |name, dep| results << dep.execute }
|
18
|
-
results.flatten
|
21
|
+
# Adds a new task as a dependency.
|
22
|
+
def task(name, &block)
|
23
|
+
tasks[name] = Battlestation::Task.new(name, &block)
|
19
24
|
end
|
25
|
+
alias_method :dependency, :task
|
20
26
|
end
|
21
27
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Battlestation
|
2
|
+
class Task
|
3
|
+
attr_accessor :name
|
4
|
+
attr_accessor :operations
|
5
|
+
|
6
|
+
def initialize(name, &block)
|
7
|
+
@name = name
|
8
|
+
@operations = []
|
9
|
+
|
10
|
+
instance_eval &block if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
def title
|
14
|
+
"Manning #{name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Check if an executable exists
|
18
|
+
def executable(filename, opts = {})
|
19
|
+
operations << Battlestation::Operations::ExecutableCheck.new(filename, opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Check if a file exists
|
23
|
+
def file_exists(filename, opts = {})
|
24
|
+
operations << Battlestation::Operations::FileExistsCheck.new(filename, opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Check if a process is running
|
28
|
+
def process(identifier, opts = {})
|
29
|
+
operations << Battlestation::Operations::ProcessCheck.new(identifier, opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Run the specified command, fail if unsucessful
|
33
|
+
def run(cmd, opts = {})
|
34
|
+
operations << Battlestation::Operations::Runner.new(cmd, opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Execute this dependency
|
38
|
+
def execute
|
39
|
+
Battlestation.ui.notice("Nothing defined for #{task.name}") and return if operations.empty?
|
40
|
+
|
41
|
+
statuses = []
|
42
|
+
# Report successes and failures
|
43
|
+
operations.each do |operation|
|
44
|
+
status = operation.status
|
45
|
+
statuses << status
|
46
|
+
|
47
|
+
Battlestation.ui.send(status[:status], status[:msg])
|
48
|
+
|
49
|
+
if status[:resolution]
|
50
|
+
Battlestation.ui.todo(">> " + status[:resolution])
|
51
|
+
end
|
52
|
+
|
53
|
+
# Exit if this task failed. No point continuing
|
54
|
+
if status[:status] == :fail
|
55
|
+
Battlestation.ui.fail(">> Please resolve the failures above and re-run `battlestation`")
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/battlestation/ui.rb
CHANGED
@@ -2,9 +2,19 @@ require 'rubygems/user_interaction'
|
|
2
2
|
|
3
3
|
module Battlestation
|
4
4
|
class UI
|
5
|
+
|
6
|
+
def fail(message, newline = nil)
|
7
|
+
end
|
8
|
+
|
9
|
+
def okay(message, newline = nil)
|
10
|
+
end
|
11
|
+
|
5
12
|
def warn(message, newline = nil)
|
6
13
|
end
|
7
14
|
|
15
|
+
def notice(message, newline = nil)
|
16
|
+
end
|
17
|
+
|
8
18
|
def debug(message, newline = nil)
|
9
19
|
end
|
10
20
|
|
@@ -17,6 +27,12 @@ module Battlestation
|
|
17
27
|
def confirm(message, newline = nil)
|
18
28
|
end
|
19
29
|
|
30
|
+
def todo(message, newline = nil)
|
31
|
+
end
|
32
|
+
|
33
|
+
def group(title, &block)
|
34
|
+
end
|
35
|
+
|
20
36
|
class Shell < UI
|
21
37
|
attr_writer :shell
|
22
38
|
|
@@ -25,8 +41,31 @@ module Battlestation
|
|
25
41
|
@quiet = false
|
26
42
|
end
|
27
43
|
|
44
|
+
def group(title, &block)
|
45
|
+
tell_me("> #{title}")
|
46
|
+
tell_me("\n")
|
47
|
+
yield
|
48
|
+
tell_me("\n")
|
49
|
+
end
|
50
|
+
|
51
|
+
def todo(message, newline = nil)
|
52
|
+
tell_me(" [TODO] #{message}", :cyan, newline)
|
53
|
+
end
|
54
|
+
|
55
|
+
def fail(message, newline = nil)
|
56
|
+
tell_me(" [FAIL] #{message}", :red, newline)
|
57
|
+
end
|
58
|
+
|
59
|
+
def notice(message, newline = nil)
|
60
|
+
tell_me(" [INFO] #{message}", :blue, newline)
|
61
|
+
end
|
62
|
+
|
63
|
+
def okay(message, newline = nil)
|
64
|
+
tell_me(" [OKAY] #{message}", :green, newline)
|
65
|
+
end
|
66
|
+
|
28
67
|
def warn(message, newline = nil)
|
29
|
-
tell_me(message, :yellow, newline)
|
68
|
+
tell_me(" [WARN] #{message}", :yellow, newline)
|
30
69
|
end
|
31
70
|
|
32
71
|
def debug(message, newline = nil)
|
data/spec/battle_station_spec.rb
CHANGED
@@ -5,4 +5,25 @@ describe Battlestation do
|
|
5
5
|
plan = Battlestation::plan {}
|
6
6
|
plan.should be_a(Battlestation::Plan)
|
7
7
|
end
|
8
|
+
|
9
|
+
context "loading a Battlestation file" do
|
10
|
+
before { remove_battlefiles }
|
11
|
+
|
12
|
+
it "loads a Battlestation file" do
|
13
|
+
filename = battlefile <<-B
|
14
|
+
Battlestation.plan do
|
15
|
+
end
|
16
|
+
B
|
17
|
+
|
18
|
+
Battlestation.load(filename).should be_a(Battlestation::Plan)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns nil on error" do
|
22
|
+
filename = battlefile <<-B
|
23
|
+
Mumbo Jumbo Syntax Dumbo.
|
24
|
+
B
|
25
|
+
|
26
|
+
Battlestation.load(filename).should be_nil
|
27
|
+
end
|
28
|
+
end
|
8
29
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -1,18 +1,66 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe Battlestation::CLI do
|
4
|
-
context "
|
4
|
+
context "Battlestation files" do
|
5
5
|
before do
|
6
6
|
remove_battlefile
|
7
7
|
end
|
8
8
|
|
9
|
-
it "
|
10
|
-
|
11
|
-
|
9
|
+
it "uses a Battlestation file" do
|
10
|
+
battlefile <<-B
|
11
|
+
Battlestation.plan do
|
12
|
+
end
|
13
|
+
B
|
14
|
+
battlestation(:check)
|
15
|
+
|
16
|
+
out.should_not =~ /Could not read your Battlestation file/
|
12
17
|
end
|
13
18
|
|
14
|
-
it "
|
15
|
-
|
19
|
+
it "checks for a Battlestation.rb file" do
|
20
|
+
battlefilerb <<-B
|
21
|
+
Battlestation.plan do
|
22
|
+
end
|
23
|
+
B
|
24
|
+
battlestation(:check)
|
25
|
+
|
26
|
+
out.should_not =~ /Could not read your Battlestation file/
|
27
|
+
end
|
28
|
+
|
29
|
+
it "complains when both Battlestation and Battlestation.rb exist" do
|
30
|
+
battlefile <<-B
|
31
|
+
Battlestation.plan do
|
32
|
+
end
|
33
|
+
B
|
34
|
+
|
35
|
+
battlefilerb <<-B
|
36
|
+
Battlestation.plan do
|
37
|
+
end
|
38
|
+
B
|
39
|
+
|
40
|
+
battlestation(:check)
|
41
|
+
|
42
|
+
out.should =~ /You cannot have both Battlestation and Battlestation.rb files. Choose one, remove the other./
|
43
|
+
end
|
44
|
+
|
45
|
+
context "without a valid Battlestation file" do
|
46
|
+
it "write an error" do
|
47
|
+
battlestation :check
|
48
|
+
out.should =~ /Could not read your Battlestation file/
|
49
|
+
end
|
50
|
+
|
51
|
+
it "exits with status 1" do
|
52
|
+
battlestation(:check, exitstatus: true).should == 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with a Battlestation file with syntax errors" do
|
57
|
+
it "reports syntax errors in your Battlestation" do
|
58
|
+
check_battlefile <<-B
|
59
|
+
Syntactic Mumbo Jumbo
|
60
|
+
B
|
61
|
+
|
62
|
+
out.should =~ /Your Battlestation has syntax errors/
|
63
|
+
end
|
16
64
|
end
|
17
65
|
end
|
18
66
|
|
@@ -26,7 +74,7 @@ describe Battlestation::CLI do
|
|
26
74
|
end
|
27
75
|
B
|
28
76
|
|
29
|
-
out.should =~ /ls found/i
|
77
|
+
out.should =~ / \[OKAY\] ls executable found/i
|
30
78
|
end
|
31
79
|
|
32
80
|
it "reports an error" do
|
@@ -38,7 +86,31 @@ describe Battlestation::CLI do
|
|
38
86
|
end
|
39
87
|
B
|
40
88
|
|
41
|
-
out.should =~ /unknown-executable-name not found/i
|
89
|
+
out.should =~ / \[FAIL\] unknown-executable-name executable not found/i
|
90
|
+
end
|
91
|
+
|
92
|
+
it "exists with error status 1 on failure" do
|
93
|
+
battlefile <<-B
|
94
|
+
Battlestation.plan do
|
95
|
+
dependency :some_dep do
|
96
|
+
executable 'unknown-executable-name'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
B
|
100
|
+
|
101
|
+
battlestation(:check, exitstatus: true).should == 1
|
102
|
+
end
|
103
|
+
|
104
|
+
it "reports resolutions on failure" do
|
105
|
+
check_battlefile <<-B
|
106
|
+
Battlestation.plan do
|
107
|
+
dependency :some_dep do
|
108
|
+
executable 'unknown-executable-name', resolution: "Install some app"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
B
|
112
|
+
|
113
|
+
out.should =~ /Install some app/i
|
42
114
|
end
|
43
115
|
end
|
44
116
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Battlestation::Operations::ExecutableCheck do
|
4
|
+
context "with a valid executable" do
|
5
|
+
subject { Battlestation::Operations::ExecutableCheck.new('ls') }
|
6
|
+
|
7
|
+
it { subject.status.should include(status: :okay) }
|
8
|
+
it { subject.status.should include(msg: "ls executable found") }
|
9
|
+
it { subject.status.should include(name: "executable-ls") }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with an invalid executable" do
|
13
|
+
subject { Battlestation::Operations::ExecutableCheck.new('does-not-exist') }
|
14
|
+
|
15
|
+
it { subject.status.should include(status: :fail) }
|
16
|
+
it { subject.status.should include(msg: "does-not-exist executable not found") }
|
17
|
+
it { subject.status.should include(name: "executable-does-not-exist") }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with an invalid executable and resolution" do
|
21
|
+
subject { Battlestation::Operations::ExecutableCheck.new('does-not-exist', resolution: "install some package") }
|
22
|
+
|
23
|
+
it { subject.status.should include(status: :fail) }
|
24
|
+
it { subject.status.should include(msg: "does-not-exist executable not found") }
|
25
|
+
it { subject.status.should include(name: "executable-does-not-exist") }
|
26
|
+
it { subject.status.should include(resolution: "install some package") }
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Battlestation::Operations::FileExistsCheck do
|
4
|
+
context "with a file that exists" do
|
5
|
+
subject { Battlestation::Operations::FileExistsCheck.new('battlestation.gemspec') }
|
6
|
+
|
7
|
+
before { subject.stub(file_exists?: true) }
|
8
|
+
|
9
|
+
it { subject.status.should include(status: :okay) }
|
10
|
+
it { subject.status.should include(msg: "battlestation.gemspec found") }
|
11
|
+
it { subject.status.should include(name: "file-battlestation.gemspec") }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "with an invalid executable" do
|
15
|
+
subject { Battlestation::Operations::FileExistsCheck.new('does-not-exist') }
|
16
|
+
|
17
|
+
it { subject.status.should include(status: :fail) }
|
18
|
+
it { subject.status.should include(msg: "does-not-exist not found") }
|
19
|
+
it { subject.status.should include(name: "file-does-not-exist") }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with an invalid executable and resolution" do
|
23
|
+
subject { Battlestation::Operations::FileExistsCheck.new('does-not-exist', resolution: "copy file") }
|
24
|
+
|
25
|
+
it { subject.status.should include(status: :fail) }
|
26
|
+
it { subject.status.should include(msg: "does-not-exist not found") }
|
27
|
+
it { subject.status.should include(name: "file-does-not-exist") }
|
28
|
+
it { subject.status.should include(resolution: "copy file") }
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Battlestation::Operations::ProcessCheck do
|
4
|
+
context "with a valid process" do
|
5
|
+
subject { Battlestation::Operations::ProcessCheck.new('ruby') }
|
6
|
+
|
7
|
+
it { subject.status.should include(status: :okay) }
|
8
|
+
it { subject.status.should include(msg: "ruby up and running") }
|
9
|
+
it { subject.status.should include(name: "process-ruby") }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with an invalid process" do
|
13
|
+
subject { Battlestation::Operations::ProcessCheck.new('does-not-exist') }
|
14
|
+
|
15
|
+
it { subject.status.should include(status: :warn) }
|
16
|
+
it { subject.status.should include(msg: "does-not-exist not running") }
|
17
|
+
it { subject.status.should include(name: "process-does-not-exist") }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with an invalid process and forced failure" do
|
21
|
+
subject { Battlestation::Operations::ProcessCheck.new('does-not-exist', force_failure: true) }
|
22
|
+
|
23
|
+
it { subject.status.should include(status: :fail) }
|
24
|
+
it { subject.status.should include(msg: "does-not-exist not running") }
|
25
|
+
it { subject.status.should include(name: "process-does-not-exist") }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with an invalid process and resolution" do
|
29
|
+
subject { Battlestation::Operations::ProcessCheck.new('does-not-exist', resolution: "install some package") }
|
30
|
+
|
31
|
+
it { subject.status.should include(status: :warn) }
|
32
|
+
it { subject.status.should include(msg: "does-not-exist not running") }
|
33
|
+
it { subject.status.should include(name: "process-does-not-exist") }
|
34
|
+
it { subject.status.should include(resolution: "install some package") }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Battlestation::Operations::Runner do
|
4
|
+
context "with a successfully ran command" do
|
5
|
+
subject { Battlestation::Operations::Runner.new('ls') }
|
6
|
+
|
7
|
+
before { subject.stub(:system).and_return(true) }
|
8
|
+
|
9
|
+
it { subject.status.should include(status: :okay) }
|
10
|
+
it { subject.status.should include(msg: "`ls` executed successfully") }
|
11
|
+
it { subject.status.should include(name: "runner-ls") }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "with an invalid executable" do
|
15
|
+
subject { Battlestation::Operations::Runner.new('does-not-exist') }
|
16
|
+
|
17
|
+
before { subject.stub(:system).and_return(false) }
|
18
|
+
|
19
|
+
it { subject.status.should include(status: :fail) }
|
20
|
+
it { subject.status.should include(msg: "`does-not-exist` failed to execute") }
|
21
|
+
it { subject.status.should include(name: "runner-does-not-exist") }
|
22
|
+
end
|
23
|
+
end
|
data/spec/plan_spec.rb
CHANGED
@@ -5,14 +5,8 @@ describe Battlestation::Plan do
|
|
5
5
|
subject { Battlestation.plan { dependency :postgres } }
|
6
6
|
|
7
7
|
it "are added" do
|
8
|
-
subject.
|
9
|
-
subject.
|
10
|
-
end
|
11
|
-
|
12
|
-
it "are executed" do
|
13
|
-
subject.dependencies[:postgres].should_receive(:execute).once
|
14
|
-
subject.execute
|
8
|
+
subject.tasks.should be_an(Hash)
|
9
|
+
subject.tasks[:postgres].should be_a(Battlestation::Task)
|
15
10
|
end
|
16
11
|
end
|
17
12
|
end
|
18
|
-
|
data/spec/support/helpers.rb
CHANGED
@@ -38,8 +38,8 @@ module Spec
|
|
38
38
|
yield @in_p if block_given?
|
39
39
|
@in_p.close
|
40
40
|
|
41
|
-
@out = @out_p.read_available_bytes
|
42
|
-
@err = @err_p.read_available_bytes
|
41
|
+
@out = @out_p.read_available_bytes #.strip
|
42
|
+
@err = @err_p.read_available_bytes #.strip
|
43
43
|
end
|
44
44
|
|
45
45
|
puts @err unless expect_err || @err.empty?
|
@@ -56,14 +56,21 @@ module Spec
|
|
56
56
|
def remove_battlefile
|
57
57
|
path = app("Battlestation")
|
58
58
|
FileUtils.rm_rf(path)
|
59
|
+
path = app("Battlestation.rb")
|
60
|
+
FileUtils.rm_rf(path)
|
59
61
|
end
|
62
|
+
alias_method :remove_battlefiles, :remove_battlefile
|
60
63
|
|
61
64
|
def battlefile(str)
|
62
65
|
path = app("Battlestation")
|
63
|
-
path
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
write_battlefile(path, str)
|
67
|
+
path
|
68
|
+
end
|
69
|
+
|
70
|
+
def battlefilerb(str)
|
71
|
+
path = app("Battlestation.rb")
|
72
|
+
write_battlefile(path, str)
|
73
|
+
path
|
67
74
|
end
|
68
75
|
|
69
76
|
def check_battlefile(str)
|
@@ -74,5 +81,13 @@ module Spec
|
|
74
81
|
def in_app_root(&block)
|
75
82
|
Dir.chdir(app, &block)
|
76
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def write_battlefile(path, str)
|
87
|
+
path.dirname.mkpath
|
88
|
+
File.open(path.to_s, "w") do |f|
|
89
|
+
f.puts str
|
90
|
+
end
|
91
|
+
end
|
77
92
|
end
|
78
93
|
end
|
data/spec/task_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Battlestation::Task do
|
4
|
+
subject {
|
5
|
+
Battlestation::Task.new :test_dep do
|
6
|
+
executable 'meh'
|
7
|
+
process 'some-server'
|
8
|
+
run 'some command'
|
9
|
+
file_exists 'some-file'
|
10
|
+
end
|
11
|
+
}
|
12
|
+
|
13
|
+
it { subject.operations.should be_an(Array) }
|
14
|
+
it { subject.operations.should have(4).elements }
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: battlestation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70191472055060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70191472055060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70191472067960 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70191472067960
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: guard-rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70191472089200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70191472089200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: thor
|
49
|
-
requirement: &
|
49
|
+
requirement: &70191472094880 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70191472094880
|
58
58
|
description: Get your battle station up and running fast
|
59
59
|
email:
|
60
60
|
- ariejan@ariejan.net
|
@@ -72,21 +72,30 @@ files:
|
|
72
72
|
- Rakefile
|
73
73
|
- battlestation.gemspec
|
74
74
|
- bin/battlestation
|
75
|
-
- examples/
|
75
|
+
- examples/Battlestation
|
76
76
|
- lib/battlestation.rb
|
77
77
|
- lib/battlestation/cli.rb
|
78
|
-
- lib/battlestation/
|
78
|
+
- lib/battlestation/operations.rb
|
79
|
+
- lib/battlestation/operations/executable_check.rb
|
80
|
+
- lib/battlestation/operations/file_exists_check.rb
|
81
|
+
- lib/battlestation/operations/process_check.rb
|
82
|
+
- lib/battlestation/operations/runner.rb
|
79
83
|
- lib/battlestation/plan.rb
|
84
|
+
- lib/battlestation/task.rb
|
80
85
|
- lib/battlestation/ui.rb
|
81
86
|
- lib/battlestation/version.rb
|
82
87
|
- spec/battle_station_spec.rb
|
83
88
|
- spec/cli_spec.rb
|
84
|
-
- spec/
|
89
|
+
- spec/operations/executable_spec.rb
|
90
|
+
- spec/operations/file_exists_spec.rb
|
91
|
+
- spec/operations/process_spec.rb
|
92
|
+
- spec/operations/runner_spec.rb
|
85
93
|
- spec/plan_spec.rb
|
86
94
|
- spec/spec_helper.rb
|
87
95
|
- spec/support/helpers.rb
|
88
96
|
- spec/support/path.rb
|
89
97
|
- spec/support/ruby_ext.rb
|
98
|
+
- spec/task_spec.rb
|
90
99
|
homepage: ''
|
91
100
|
licenses: []
|
92
101
|
post_install_message:
|
@@ -101,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
110
|
version: '0'
|
102
111
|
segments:
|
103
112
|
- 0
|
104
|
-
hash: -
|
113
|
+
hash: -390528445491031614
|
105
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
115
|
none: false
|
107
116
|
requirements:
|
@@ -110,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
119
|
version: '0'
|
111
120
|
segments:
|
112
121
|
- 0
|
113
|
-
hash: -
|
122
|
+
hash: -390528445491031614
|
114
123
|
requirements: []
|
115
124
|
rubyforge_project: battlestation
|
116
125
|
rubygems_version: 1.8.11
|
@@ -120,9 +129,13 @@ summary: Get your battle station up and running fast
|
|
120
129
|
test_files:
|
121
130
|
- spec/battle_station_spec.rb
|
122
131
|
- spec/cli_spec.rb
|
123
|
-
- spec/
|
132
|
+
- spec/operations/executable_spec.rb
|
133
|
+
- spec/operations/file_exists_spec.rb
|
134
|
+
- spec/operations/process_spec.rb
|
135
|
+
- spec/operations/runner_spec.rb
|
124
136
|
- spec/plan_spec.rb
|
125
137
|
- spec/spec_helper.rb
|
126
138
|
- spec/support/helpers.rb
|
127
139
|
- spec/support/path.rb
|
128
140
|
- spec/support/ruby_ext.rb
|
141
|
+
- spec/task_spec.rb
|
data/examples/redis_plan.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Battlestation
|
2
|
-
class Dependency
|
3
|
-
attr_accessor :name
|
4
|
-
attr_accessor :executables
|
5
|
-
|
6
|
-
def initialize(name, &block)
|
7
|
-
@name = name
|
8
|
-
@executables = []
|
9
|
-
|
10
|
-
instance_eval &block if block_given?
|
11
|
-
end
|
12
|
-
|
13
|
-
def executable(filename)
|
14
|
-
executables << filename
|
15
|
-
end
|
16
|
-
|
17
|
-
def execute
|
18
|
-
result = []
|
19
|
-
|
20
|
-
executables.each do |executable|
|
21
|
-
if system("/usr/bin/env which #{executable}")
|
22
|
-
result << "#{executable} found"
|
23
|
-
else
|
24
|
-
result << "#{executable} not found"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
result
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/spec/dependency_spec.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe Battlestation::Dependency do
|
4
|
-
context "executables" do
|
5
|
-
subject {
|
6
|
-
Battlestation::Dependency.new :test_dep do
|
7
|
-
executable 'autoexec.bat'
|
8
|
-
end
|
9
|
-
}
|
10
|
-
|
11
|
-
it "can be added" do
|
12
|
-
subject.executables.should be_an(Array)
|
13
|
-
subject.executables.should have(1).element
|
14
|
-
subject.executables.should include('autoexec.bat')
|
15
|
-
end
|
16
|
-
|
17
|
-
it "can be executed" do
|
18
|
-
subject.should_receive(:system).with('/usr/bin/env which autoexec.bat')
|
19
|
-
subject.execute
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns a result when succesful" do
|
23
|
-
subject.should_receive(:system).with('/usr/bin/env which autoexec.bat').and_return(true)
|
24
|
-
result = subject.execute
|
25
|
-
|
26
|
-
result.should be_an(Array)
|
27
|
-
result.should have(1).element
|
28
|
-
result.should include("autoexec.bat found")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "returns a result when not succesful" do
|
32
|
-
subject.should_receive(:system).with('/usr/bin/env which autoexec.bat').and_return(false)
|
33
|
-
result = subject.execute
|
34
|
-
|
35
|
-
result.should be_an(Array)
|
36
|
-
result.should have(1).elements
|
37
|
-
result.should include("autoexec.bat not found")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|