screwcap 0.3.4 → 0.3.5

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/Manifest.txt CHANGED
@@ -15,6 +15,7 @@ lib/screwcap/sequence.rb
15
15
  lib/screwcap/server.rb
16
16
  lib/screwcap/task.rb
17
17
  lib/trollop.rb
18
+ recipes/setup_rails.rb
18
19
  screwcap.gemspec
19
20
  spec/command_set_spec.rb
20
21
  spec/deployer_spec.rb
@@ -27,6 +28,7 @@ tasks/rspec.rake
27
28
  test/config/command_sets.rb
28
29
  test/config/expect.rb
29
30
  test/config/gateway.rb
31
+ test/config/local_task.rb
30
32
  test/config/no_server.rb
31
33
  test/config/rails_tasks.rb
32
34
  test/config/simple_recipe.rb
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ Hoe.plugin :newgem
11
11
  # Generate all the Rake tasks
12
12
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
13
  $hoe = Hoe.spec 'screwcap' do
14
- self.version = '0.3.4'
14
+ self.version = '0.3.5'
15
15
  self.developer 'Grant Ammons', 'grant@pipelinedeals.com'
16
16
  self.rubyforge_name = self.name # TODO this is default value
17
17
  self.extra_deps = [['net-ssh','>= 2.0.23'],['net-ssh-gateway','>=1.0.1'], ['net-scp','>=1.0.4']]
data/bin/screwcap CHANGED
@@ -11,6 +11,7 @@ p = Trollop::Parser.new do
11
11
  opt :debug, "Turn on debugger. Will print full stacktrace if an exeception was raised"
12
12
  opt :help, "Show this message"
13
13
  opt :tasks, "Display available tasks in recipe file"
14
+ opt :setup_rails, "Setup a rails app to use screwcap"
14
15
  version <<-EOF
15
16
  Screwcap #{Screwcap::VERSION} by Grant Ammons (grant@pipelinedeals.com)
16
17
  More info at http://gammons.github.com/screwcap
@@ -38,6 +39,15 @@ opts = Trollop::with_standard_exception_handling p do
38
39
  exit
39
40
  end
40
41
 
42
+ if opts[:setup_rails] == true
43
+ Deployer.new(:recipe_file => File.expand_path(File.dirname(__FILE__) + "/../recipes/setup_rails.rb")).run! :setup_rails
44
+ $stdout << "\nYour rails app now has a sample recipe, ready for the editing, in config/screwcap/recipe.rb\n"
45
+ $stdout << "Your recipes will be automatically available in rake. Screwcap uses the :remote namespace.\n"
46
+ $stdout << "To see what recipes you can run, type 'rake -T remote'.\n"
47
+ $stdout << "Please visit http://gammons.github.com/screwcap for help.\n"
48
+ exit
49
+ end
50
+
41
51
  raise Trollop::HelpNeeded if ARGV.size < 2
42
52
  recipe_file = ARGV.shift
43
53
  begin
@@ -88,12 +88,13 @@ class Deployer < Screwcap::Base
88
88
  #
89
89
  # ====Any command sets that are nested within another command set will inerit all the variables from the parent command set.
90
90
  #
91
- def task_for name, options = {}, &block
91
+ def task name, options = {}, &block
92
92
  t = Task.new(options.merge(:name => name, :nocolor => self.__options[:nocolor], :silent => self.__options[:silent], :deployment_servers => self.__servers, :command_sets => self.__command_sets), &block)
93
93
  clone_table_for(t)
94
94
  t.instance_eval(&block)
95
95
  self.__tasks << t
96
96
  end
97
+ alias :task_for :task
97
98
 
98
99
  # ====A *command set* is like a generic set of tasks that you intend to use in multiple tasks.
99
100
  #
@@ -4,12 +4,28 @@ class Runner
4
4
  def self.execute! task, options
5
5
  @task = task; @options = options
6
6
  threads = []
7
- @task.__servers.each do |_server|
8
- _server.__addresses.each do |_address|
9
- if task.__options[:parallel] == false
10
- execute_on(_server, _address)
7
+ if @task.__options[:local] == true
8
+ log "\n*** BEGIN executing local task #{@task.__name}\n", :color => :blue
9
+ @task.__commands.each do |command|
10
+ ret = `#{command[:command]}`
11
+ if $?.to_i == 0
12
+ log " I: (local): #{command[:command]}\n", :color => :blue
13
+ log(" O: (local): #{ret}\n", :color => :blue) unless ret.nil? or ret == ""
11
14
  else
12
- threads << Thread.new(_server, _address) { |server, address| execute_on(server, address) }
15
+ log " I: (local): #{command[:command]}\n", :color => :blue
16
+ errorlog(" O: (local): #{ret}\n", :color => :red) unless ret.nil? or ret == ""
17
+ errorlog(" E: (local): #{command[:command]} return exit code: #{$?}\n", :color => :red) if $? != 0
18
+ end
19
+ end
20
+ log "\n*** END executing local task #{@task.__name}\n", :color => :blue
21
+ else
22
+ @task.__servers.each do |_server|
23
+ _server.__addresses.each do |_address|
24
+ if task.__options[:parallel] == false
25
+ execute_on(_server, _address)
26
+ else
27
+ threads << Thread.new(_server, _address) { |server, address| execute_on(server, address) }
28
+ end
13
29
  end
14
30
  end
15
31
  end
@@ -38,10 +54,10 @@ class Runner
38
54
  end
39
55
  rescue Net::SSH::AuthenticationFailed => e
40
56
  raise Net::SSH::AuthenticationFailed, "Authentication failed for server named #{server.name}. Please check your authentication credentials."
41
- #rescue Exception => e
42
- # errorlog " F: (#{address}): #{e}", :color => :red
43
- #ensure
44
- # log "*** END executing task #{@task.__name} on #{server.name} with address #{address}\n\n", :color => :blue
57
+ rescue Exception => e
58
+ errorlog " F: (#{address}): #{e}", :color => :red
59
+ ensure
60
+ log "*** END executing task #{@task.__name} on #{server.name} with address #{address}\n\n", :color => :blue
45
61
  end
46
62
  end
47
63
 
data/lib/screwcap/task.rb CHANGED
@@ -17,7 +17,7 @@ class Task < Screwcap::Base
17
17
  self.__server_names = opts[:servers]
18
18
  end
19
19
 
20
- validate(opts[:deployment_servers]) unless opts[:validate] == false
20
+ validate(opts[:deployment_servers]) unless opts[:validate] == false or opts[:local] == true
21
21
  end
22
22
 
23
23
  # Run a command. This can either be a string, or a symbol that is the name of a command set to run.
data/lib/screwcap.rb CHANGED
@@ -16,7 +16,7 @@ require 'screwcap/sequence'
16
16
  require 'screwcap/deployer'
17
17
 
18
18
  module Screwcap
19
- VERSION='0.3.4'
19
+ VERSION='0.3.5'
20
20
 
21
21
  class TaskNotFound < RuntimeError; end
22
22
  class NoServersDefined < Exception; end
@@ -0,0 +1,32 @@
1
+ server :local, :address => "127.0.0.1", :user => "root", :password => "none"
2
+ task :setup_rails, :local => true do
3
+ local "mkdir -p config/screwcap"
4
+ local "mkdir -p lib/tasks"
5
+
6
+ local <<-EOF
7
+ if [ -f config/screwcap/rails_tasks.rb ]
8
+ then
9
+ echo "config/screwcap/rails_tasks.rb already exists!"; exit 1
10
+ else
11
+ curl -s http://github.com/gammons/screwcap_recipes/raw/master/rails/rails_tasks.rb > config/screwcap/rails_tasks.rb
12
+ fi
13
+ EOF
14
+
15
+ local <<-EOF
16
+ if [ -f lib/tasks/screwcap.rake ]
17
+ then
18
+ echo "lib/tasks/screwcap.rake already exists!"; exit 1
19
+ else
20
+ curl -s http://github.com/gammons/screwcap_recipes/raw/master/rails/screwcap.rake > lib/tasks/screwcap.rake
21
+ fi
22
+ EOF
23
+
24
+ local <<-EOF
25
+ if [ -f config/screwcap/recipe.rb ]
26
+ then
27
+ echo "config/screwcap/recipe.rb already exists!"; exit 1
28
+ else
29
+ curl -s http://github.com/gammons/screwcap_recipes/raw/master/rails/recipe.rb > config/screwcap/recipe.rb
30
+ fi
31
+ EOF
32
+ end
data/screwcap.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'bundler/version'
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "screwcap"
9
- s.version = "0.3.4"
9
+ s.version = "0.3.5"
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.author = "Grant Ammons"
12
12
  s.email = ["grant@pipelinedealsco.com"]
data/spec/task_spec.rb CHANGED
@@ -29,7 +29,7 @@ describe "Tasks" do
29
29
  task = @deployer.__tasks.find {|t| t.name == :task1 }
30
30
  Runner.execute! task, @deployer.__options
31
31
  @stderr.size.should == 0
32
- @stdout.size.should == 26
32
+ @stdout.size.should == 28
33
33
  end
34
34
 
35
35
  it "should be able to use variables in the run statement" do
@@ -79,4 +79,9 @@ describe "Tasks" do
79
79
  Runner.execute! t, deployer.__options
80
80
  t.__commands.map {|c| [c[:command], c[:from]] }.first.should == ["echo 'we failed'", :failover]
81
81
  end
82
+
83
+ it "should be able to create local tasks" do
84
+ # TODO better testing on this
85
+ lambda { Deployer.new(:recipe_file => "./test/config/local_task.rb", :silent => true).run! :local }.should_not raise_error
86
+ end
82
87
  end
@@ -0,0 +1,3 @@
1
+ task :local, :local => true do
2
+ run "ls"
3
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screwcap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Grant Ammons
@@ -126,6 +126,7 @@ files:
126
126
  - lib/screwcap/server.rb
127
127
  - lib/screwcap/task.rb
128
128
  - lib/trollop.rb
129
+ - recipes/setup_rails.rb
129
130
  - screwcap.gemspec
130
131
  - spec/command_set_spec.rb
131
132
  - spec/deployer_spec.rb
@@ -138,6 +139,7 @@ files:
138
139
  - test/config/command_sets.rb
139
140
  - test/config/expect.rb
140
141
  - test/config/gateway.rb
142
+ - test/config/local_task.rb
141
143
  - test/config/no_server.rb
142
144
  - test/config/rails_tasks.rb
143
145
  - test/config/simple_recipe.rb