fezzik 0.7.2 → 0.7.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 CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
2
  Gemfile.lock
3
+ .vagrant
data/Rakefile CHANGED
@@ -1,3 +1,14 @@
1
+ require "rake/testtask"
2
+
3
+ task :test => ["test:integrations"]
4
+
5
+ namespace :test do
6
+ Rake::TestTask.new(:integrations) do |task|
7
+ task.libs << "test"
8
+ task.test_files = FileList["test/integration/**/*_test.rb"]
9
+ end
10
+ end
11
+
1
12
  desc "remove built gems"
2
13
  task :clean do
3
14
  sh "rm fezzik-*" rescue true
@@ -12,4 +23,3 @@ desc "install gem"
12
23
  task :install => [:clean, :build] do
13
24
  sh "gem install `ls fezzik-*`"
14
25
  end
15
-
data/Vagrantfile ADDED
@@ -0,0 +1,99 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant::Config.run do |config|
5
+ # All Vagrant configuration is done here. The most common configuration
6
+ # options are documented and commented below. For a complete reference,
7
+ # please see the online documentation at vagrantup.com.
8
+
9
+ # Every Vagrant virtual environment requires a box to build off of.
10
+ config.vm.box = "lucid32"
11
+
12
+ # The url from where the 'config.vm.box' box will be fetched if it
13
+ # doesn't already exist on the user's system.
14
+ config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
15
+
16
+ # Boot with a GUI so you can see the screen. (Default is headless)
17
+ # config.vm.boot_mode = :gui
18
+
19
+ # Assign this VM to a host-only network IP, allowing you to access it
20
+ # via the IP. Host-only networks can talk to the host machine as well as
21
+ # any other machines on the same network, but cannot be accessed (through this
22
+ # network interface) by any external networks.
23
+ # config.vm.network :hostonly, "192.168.33.10"
24
+
25
+ # Assign this VM to a bridged network, allowing you to connect directly to a
26
+ # network using the host's network device. This makes the VM appear as another
27
+ # physical device on your network.
28
+ # config.vm.network :bridged
29
+
30
+ # Forward a port from the guest to the host, which allows for outside
31
+ # computers to access the VM, whereas host only networking does not.
32
+ # config.vm.forward_port 80, 8080
33
+
34
+ # Share an additional folder to the guest VM. The first argument is
35
+ # an identifier, the second is the path on the guest to mount the
36
+ # folder, and the third is the path on the host to the actual folder.
37
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data"
38
+
39
+ # Enable provisioning with Puppet stand alone. Puppet manifests
40
+ # are contained in a directory path relative to this Vagrantfile.
41
+ # You will need to create the manifests directory and a manifest in
42
+ # the file base.pp in the manifests_path directory.
43
+ #
44
+ # An example Puppet manifest to provision the message of the day:
45
+ #
46
+ # # group { "puppet":
47
+ # # ensure => "present",
48
+ # # }
49
+ # #
50
+ # # File { owner => 0, group => 0, mode => 0644 }
51
+ # #
52
+ # # file { '/etc/motd':
53
+ # # content => "Welcome to your Vagrant-built virtual machine!
54
+ # # Managed by Puppet.\n"
55
+ # # }
56
+ #
57
+ # config.vm.provision :puppet do |puppet|
58
+ # puppet.manifests_path = "manifests"
59
+ # puppet.manifest_file = "base.pp"
60
+ # end
61
+
62
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
63
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
64
+ # some recipes and/or roles.
65
+ #
66
+ # config.vm.provision :chef_solo do |chef|
67
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
68
+ # chef.roles_path = "../my-recipes/roles"
69
+ # chef.data_bags_path = "../my-recipes/data_bags"
70
+ # chef.add_recipe "mysql"
71
+ # chef.add_role "web"
72
+ #
73
+ # # You may also specify custom JSON attributes:
74
+ # chef.json = { :mysql_password => "foo" }
75
+ # end
76
+
77
+ # Enable provisioning with chef server, specifying the chef server URL,
78
+ # and the path to the validation key (relative to this Vagrantfile).
79
+ #
80
+ # The Opscode Platform uses HTTPS. Substitute your organization for
81
+ # ORGNAME in the URL and validation key.
82
+ #
83
+ # If you have your own Chef Server, use the appropriate URL, which may be
84
+ # HTTP instead of HTTPS depending on your configuration. Also change the
85
+ # validation key to validation.pem.
86
+ #
87
+ # config.vm.provision :chef_client do |chef|
88
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
89
+ # chef.validation_key_path = "ORGNAME-validator.pem"
90
+ # end
91
+ #
92
+ # If you're using the Opscode platform, your validator client is
93
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
94
+ #
95
+ # IF you have your own Chef Server, the default validation client name is
96
+ # chef-validator, unless you changed the configuration.
97
+ #
98
+ # chef.validation_client_name = "ORGNAME-validator"
99
+ end
data/bin/fez CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "rubygems"
4
4
  require "rake"
5
- require "colorize"
6
5
  require "fezzik"
7
6
 
8
7
  # Required for using rake/remote-task with rake >= 0.9.x
@@ -10,18 +9,21 @@ include Rake::DSL
10
9
 
11
10
  Fezzik.activated = true
12
11
 
13
- def usage
14
- <<-EOF
12
+ USAGE = <<EOF
15
13
  Version #{Fezzik::VERSION}
16
14
  fez <destination> <tasks> # Run deployment tasks on destination servers
17
15
  fez get <tasks> # Download tasks to use in your project
18
16
  fez -T # Display all tasks
19
- EOF
20
- end
17
+ EOF
21
18
 
22
19
  def print_usage_and_exit
23
- puts usage
24
- exit 1
20
+ puts USAGE
21
+ exit
22
+ end
23
+
24
+ def print_version_and_exit
25
+ puts "Version #{Fezzik::VERSION}"
26
+ exit
25
27
  end
26
28
 
27
29
  def display_tasks_and_exit
@@ -30,7 +32,7 @@ def display_tasks_and_exit
30
32
  Rake.application.options.show_task_pattern = /^fezzik:/
31
33
  output = Fezzik::Util.capture_output { Rake.application.display_tasks_and_comments }
32
34
  output.gsub!(/^rake fezzik:/, "fez <destination> ")
33
- puts output
35
+ puts output.strip.empty? ? "(No Fezzik tasks with descriptions are defined.)" : output
34
36
  exit 0
35
37
  end
36
38
 
@@ -40,9 +42,9 @@ def download_tasks_and_exit
40
42
  task += ".rake" unless task =~ /\.rake$/
41
43
  system("curl -f #{TASKS_URL}/#{task} -o #{task} > /dev/null 2>&1")
42
44
  if $? == 0
43
- puts " [new]".green + " #{task}"
45
+ puts Fezzik.color_string(" [new]", :green) + " #{task}"
44
46
  else
45
- puts " [fail]".red + " #{task}"
47
+ puts Fezzik.color_string(" [fail]", :red) + " #{task}"
46
48
  end
47
49
  end
48
50
  exit 0
@@ -61,7 +63,7 @@ def run_fezzik_tasks
61
63
  rescue Rake::ConfigurationError => e
62
64
  puts "Invalid destination: #{Fezzik.target_destination}"
63
65
  puts "Make sure this destination is configured and includes `set :domain, \"yourdomain.com\"`"
64
- puts "[fail]".red
66
+ puts Fezzik.color_string("[fail]", :red)
65
67
  exit 1
66
68
  end
67
69
  begin
@@ -70,21 +72,23 @@ def run_fezzik_tasks
70
72
  task_name, params = Fezzik::Util.split_task_and_params(task_with_params)
71
73
  Rake::Task["fezzik:#{task_name}"].invoke(params)
72
74
  end
73
- puts "[success]".green
75
+ puts Fezzik.color_string("[success]", :green)
74
76
  rescue SystemExit, Rake::CommandFailedError => e
75
- puts "[fail]".red
77
+ puts Fezzik.color_string("[fail]", :red)
76
78
  exit 1
77
79
  rescue StandardError => e
78
80
  puts e.message
79
81
  puts e.backtrace
80
- puts "[fail]".red
82
+ puts Fezzik.color_string("[fail]", :red)
81
83
  fail
82
84
  end
83
85
  end
84
86
 
85
87
  case ARGV[0]
86
- when nil, "-h" then print_usage_and_exit
87
- when "-T" then display_tasks_and_exit
88
+ when nil then abort USAGE
89
+ when "-h", "--help" then print_usage_and_exit
90
+ when "-v", "--version" then print_version_and_exit
91
+ when "-T", "--tasks" then display_tasks_and_exit
88
92
  when "get" then download_tasks_and_exit
89
93
  else run_fezzik_tasks
90
94
  end
data/fezzik.gemspec CHANGED
@@ -22,5 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.files = `git ls-files`.split("\n")
23
23
 
24
24
  s.add_dependency("rake-remote_task", "~>2.0.2")
25
- s.add_dependency("colorize", ">=0.5.8")
25
+
26
+ s.add_development_dependency("scope", "~>0.2.3")
27
+ s.add_development_dependency("vagrant", "~>1.0.5")
26
28
  end
data/lib/fezzik.rb CHANGED
@@ -2,11 +2,12 @@ require "stringio"
2
2
  require "thread"
3
3
  require "rake"
4
4
  require "rake/remote_task"
5
- require "colorize"
6
5
  require "fezzik/base"
6
+ require "fezzik/colors"
7
7
  require "fezzik/dsl"
8
8
  require "fezzik/environment"
9
9
  require "fezzik/role"
10
10
  require "fezzik/io"
11
+ require "fezzik/thread_local_io"
11
12
  require "fezzik/util"
12
13
  require "fezzik/version"
@@ -0,0 +1,7 @@
1
+ module Fezzik
2
+ COLORS = { :red => 1, :green => 2 }
3
+ def self.color_string(string, color)
4
+ return string unless STDOUT.isatty
5
+ "\e[01;#{COLORS[color]+30}m#{string}\e[m"
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ # Overrides $stdout and allows it to be overridden by the thread-local variable Thread.current[:stdout].
2
+ #
3
+ # If Thread.current[:stdout] is set, the thread will write all output there. Otherwise the thread will
4
+ # use $stdout as normal.
5
+ #
6
+ # Example usage:
7
+ #
8
+ # out = StringIO.new
9
+ #
10
+ # Thread.start do
11
+ # Thread.current[:stdout] = out
12
+ # puts "thread1"
13
+ # end.join
14
+ #
15
+ # Thread.start do
16
+ # puts "thread2"
17
+ # end.join
18
+ #
19
+ # puts out.string
20
+ #
21
+ # Output:
22
+ # thread2
23
+ # thread1
24
+
25
+ class ThreadLocalIO < IO
26
+ @@former_stdout = $stdout
27
+
28
+ def self.write(*args)
29
+ if Thread.current[:stdout]
30
+ Thread.current[:stdout].write(*args)
31
+ else
32
+ @@former_stdout.write(*args)
33
+ end
34
+ end
35
+
36
+ def self.flush
37
+ if Thread.current[:stdout]
38
+ Thread.current[:stdout].flush
39
+ else
40
+ @@former_stdout.flush
41
+ end
42
+ end
43
+ end
44
+
45
+ $stdout = ThreadLocalIO
data/lib/fezzik/util.rb CHANGED
@@ -2,11 +2,11 @@ module Fezzik
2
2
  module Util
3
3
  def self.capture_output(&block)
4
4
  output = StringIO.new
5
- $stdout = output
5
+ Thread.current[:stdout] = output
6
6
  block.call
7
- return output.string
7
+ output.string
8
8
  ensure
9
- $stdout = STDOUT
9
+ Thread.current[:stdout] = STDOUT
10
10
  end
11
11
 
12
12
  def self.split_task_and_params(task_with_params)
@@ -1,3 +1,3 @@
1
1
  module Fezzik
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require File.expand_path("../integration_test_helper", File.dirname(__FILE__))
2
+
3
+ class BaseTest < Scope::TestCase
4
+ context "base" do
5
+
6
+ namespace :fezzik do
7
+ remote_task(:touch, :path) { |t, args| run "touch #{args[:path]}" }
8
+ remote_task(:rm, :path) { |t, args| run "rm #{args[:path]}" }
9
+ end
10
+
11
+ should "create and delete files on the remote host" do
12
+ fez :touch, "/tmp/touch"
13
+ assert_file_exists("/tmp/touch")
14
+
15
+ fez :rm, "/tmp/touch"
16
+ refute_file_exists("/tmp/touch")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("../integration_test_helper", File.dirname(__FILE__))
2
+
3
+ class EnvironmentTest < Scope::TestCase
4
+ context "environment" do
5
+
6
+ destination :vagrant do
7
+ env :hero, "mario"
8
+ env :villain, "bowser", :hosts => [VAGRANT_DOMAIN]
9
+ end
10
+
11
+ should "store environment settings" do
12
+ assert_equal "mario", Fezzik.environments[VAGRANT_DOMAIN][:hero]
13
+ end
14
+
15
+ should "store environment settings for a subset of hosts" do
16
+ # This isn't actually a great test for this, but testing with multiple hosts would require a second
17
+ # vagrant configuration.
18
+ assert_equal "bowser", Fezzik.environments[VAGRANT_DOMAIN][:villain]
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,47 @@
1
+ require "bundler/setup"
2
+ require "scope"
3
+ require "minitest/autorun"
4
+
5
+ require "fezzik"
6
+ include Fezzik::DSL
7
+ include Rake::DSL
8
+
9
+ ENV["fezzik_destination"] = "vagrant"
10
+ Fezzik.init
11
+
12
+ VAGRANT_DOMAIN = "fezzik-vagrant"
13
+
14
+ destination :vagrant do
15
+ set :user, "vagrant"
16
+ set :domain, VAGRANT_DOMAIN
17
+ end
18
+
19
+ def setup_vagrant
20
+ system("mkdir -p ~/.ssh; touch ~/.ssh/config")
21
+ ssh_configured = `grep "fezzik-vagrant" ~/.ssh/config`.size > 0
22
+ unless ssh_configured
23
+ puts "Generating vagrant ssh config in ~/.ssh/config"
24
+ ssh_config = `vagrant ssh-config`.gsub("Host default", "\nHost fezzik-vagrant") << " LogLevel QUIET\n"
25
+ system("echo '#{ssh_config}' >> ~/.ssh/config")
26
+ end
27
+
28
+ vagrant_running = `vagrant status | grep "running"`.size > 0
29
+ unless vagrant_running
30
+ puts "Starting vagrant (run 'vagrant halt' to shutdown)"
31
+ system("vagrant up")
32
+ end
33
+ end
34
+
35
+ def fez(task, params = nil)
36
+ Rake::Task["fezzik:#{task}"].invoke(params)
37
+ end
38
+
39
+ def assert_file_exists(path)
40
+ assert_equal path, `ssh vagrant@fezzik-vagrant ls #{path} 2> /dev/null`.chomp
41
+ end
42
+
43
+ def refute_file_exists(path)
44
+ refute_equal path, `ssh vagrant@fezzik-vagrant ls #{path} 2> /dev/null`.chomp
45
+ end
46
+
47
+ setup_vagrant()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fezzik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-16 00:00:00.000000000 Z
13
+ date: 2012-11-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake-remote_task
@@ -29,21 +29,37 @@ dependencies:
29
29
  - !ruby/object:Gem::Version
30
30
  version: 2.0.2
31
31
  - !ruby/object:Gem::Dependency
32
- name: colorize
32
+ name: scope
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
36
- - - ! '>='
36
+ - - ~>
37
37
  - !ruby/object:Gem::Version
38
- version: 0.5.8
39
- type: :runtime
38
+ version: 0.2.3
39
+ type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - ! '>='
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.3
47
+ - !ruby/object:Gem::Dependency
48
+ name: vagrant
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.5
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
45
61
  - !ruby/object:Gem::Version
46
- version: 0.5.8
62
+ version: 1.0.5
47
63
  description: A light deployment system that gets out of your way
48
64
  email: dmacdougall@gmail.com
49
65
  executables:
@@ -55,20 +71,26 @@ files:
55
71
  - Gemfile
56
72
  - README.md
57
73
  - Rakefile
74
+ - Vagrantfile
58
75
  - bin/fez
59
76
  - fezzik.gemspec
60
77
  - lib/fezzik.rb
61
78
  - lib/fezzik/base.rb
79
+ - lib/fezzik/colors.rb
62
80
  - lib/fezzik/dsl.rb
63
81
  - lib/fezzik/environment.rb
64
82
  - lib/fezzik/io.rb
65
83
  - lib/fezzik/role.rb
84
+ - lib/fezzik/thread_local_io.rb
66
85
  - lib/fezzik/util.rb
67
86
  - lib/fezzik/version.rb
68
87
  - tasks/command.rake
69
88
  - tasks/deploy.rake
70
89
  - tasks/environment.rake
71
90
  - tasks/rollback.rake
91
+ - test/integration/base_test.rb
92
+ - test/integration/environment_test.rb
93
+ - test/integration_test_helper.rb
72
94
  homepage: http://github.com/dmacdougall/fezzik
73
95
  licenses: []
74
96
  post_install_message: