nuex-vlad 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_vlad.rb ADDED
@@ -0,0 +1,210 @@
1
+ require 'test/vlad_test_case'
2
+ require 'vlad'
3
+
4
+ $TESTING = true
5
+
6
+ class TestVlad < VladTestCase
7
+ def test_all_hosts
8
+ util_set_hosts
9
+ assert_equal %w[app.example.com db.example.com], @vlad.all_hosts
10
+ end
11
+
12
+ def test_fetch
13
+ set :foo, 5
14
+ assert_equal 5, @vlad.fetch(:foo)
15
+ end
16
+
17
+ def test_fetch_with_default
18
+ assert_equal 5, @vlad.fetch(:not_here, 5)
19
+ end
20
+
21
+ def test_host
22
+ @vlad.host "test.example.com", :app, :db
23
+ expected = {"test.example.com" => {}}
24
+ assert_equal expected, @vlad.roles[:app]
25
+ assert_equal expected, @vlad.roles[:db]
26
+ end
27
+
28
+ def test_host_invalid
29
+ assert_raises(ArgumentError) { @vlad.host nil, :web }
30
+ end
31
+
32
+ def test_host_multiple_hosts
33
+ @vlad.host "test.example.com", :app, :db
34
+ @vlad.host "yarr.example.com", :app, :db, :no_release => true
35
+
36
+ expected = {
37
+ "test.example.com" => {},
38
+ "yarr.example.com" => {:no_release => true}
39
+ }
40
+
41
+ assert_equal expected, @vlad.roles[:app]
42
+ assert_equal expected, @vlad.roles[:db]
43
+ refute_equal(@vlad.roles[:db]["test.example.com"].object_id,
44
+ @vlad.roles[:app]["test.example.com"].object_id)
45
+ end
46
+
47
+ def test_hosts_for_array_of_roles
48
+ util_set_hosts
49
+ assert_equal %w[app.example.com db.example.com], @vlad.hosts_for([:app, :db])
50
+ end
51
+
52
+ def test_hosts_for_one_role
53
+ util_set_hosts
54
+ @vlad.host "app2.example.com", :app
55
+ assert_equal %w[app.example.com app2.example.com], @vlad.hosts_for(:app)
56
+ end
57
+
58
+ def test_hosts_for_multiple_roles
59
+ util_set_hosts
60
+ assert_equal %w[app.example.com db.example.com], @vlad.hosts_for(:app, :db)
61
+ end
62
+
63
+ def test_hosts_for_unique
64
+ util_set_hosts
65
+ @vlad.host "app.example.com", :web
66
+ assert_equal %w[app.example.com db.example.com], @vlad.hosts_for(:app, :db, :web)
67
+ end
68
+
69
+ def test_initialize
70
+ @vlad.set_defaults # ensure these three are virginal
71
+ assert_raises(Vlad::ConfigurationError) { @vlad.repository }
72
+ assert_raises(Vlad::ConfigurationError) { @vlad.deploy_to }
73
+ assert_raises(Vlad::ConfigurationError) { @vlad.domain }
74
+ end
75
+
76
+ def test_role
77
+ @vlad.role :app, "test.example.com"
78
+ expected = {"test.example.com" => {}}
79
+ assert_equal expected, @vlad.roles[:app]
80
+ end
81
+
82
+ def test_role_multiple_hosts
83
+ @vlad.role :app, "test.example.com"
84
+ @vlad.role :app, "yarr.example.com", :no_release => true
85
+ expected = {
86
+ "test.example.com" => {},
87
+ "yarr.example.com" => {:no_release => true}
88
+ }
89
+ assert_equal expected, @vlad.roles[:app]
90
+ end
91
+
92
+ def test_role_multiple_roles
93
+ @vlad.role :app, "test.example.com", :primary => true
94
+ @vlad.role :db, "yarr.example.com", :no_release => true
95
+ expected_db = { "yarr.example.com" => {:no_release => true} }
96
+ assert_equal expected_db, @vlad.roles[:db]
97
+ expected_app = { "test.example.com" => {:primary => true} }
98
+ assert_equal expected_app, @vlad.roles[:app]
99
+ end
100
+
101
+ def test_remote_task
102
+ t = @vlad.remote_task(:test_task) { 5 }
103
+ assert_equal @task_count + 1, Rake.application.tasks.size
104
+ assert_equal({ :roles => [] }, t.options)
105
+ end
106
+
107
+ def test_remote_task_all_hosts_by_default
108
+ util_set_hosts
109
+ t = @vlad.remote_task(:test_task) { 5 }
110
+ assert_equal %w[app.example.com db.example.com], t.target_hosts
111
+ end
112
+
113
+ def test_remote_task_environment_override
114
+ old_env_hosts = ENV["HOSTS"]
115
+ ENV["HOSTS"] = 'other1.example.com, other2.example.com'
116
+ util_set_hosts
117
+ t = @vlad.remote_task(:test_task) { 5 }
118
+ assert_equal %w[other1.example.com other2.example.com], t.target_hosts
119
+ ensure
120
+ ENV["HOSTS"] = old_env_hosts
121
+ end
122
+
123
+ def test_remote_task_body_set
124
+ set(:some_variable, 5)
125
+ @vlad.host 'www.example.com', :app
126
+ @vlad.remote_task(:some_task) do $some_task_result = some_variable end
127
+
128
+ Rake::Task['some_task'].execute nil
129
+ assert_equal @vlad.fetch(:some_variable), $some_task_result
130
+ end
131
+
132
+ def test_remote_task_with_options
133
+ t = @vlad.remote_task :test_task, :roles => [:app, :db] do
134
+ fail "should not run"
135
+ end
136
+ assert_equal({:roles => [:app, :db]}, t.options)
137
+ end
138
+
139
+ def test_remote_task_before_host_declaration
140
+ t = @vlad.remote_task :test_task, :roles => :web do 5 end
141
+ @vlad.host 'www.example.com', :web
142
+ assert_equal %w[www.example.com], t.target_hosts
143
+ end
144
+
145
+ def test_remote_task_role_override
146
+ host "db1", :db
147
+ host "db2", :db
148
+ host "db3", :db
149
+ host "master", :master_db
150
+
151
+ remote_task(:migrate_the_db, :roles => [:db]) { flunk "bad!" }
152
+ task = Rake::Task["migrate_the_db"]
153
+ assert_equal %w[db1 db2 db3], task.target_hosts
154
+
155
+ task.options[:roles] = :master_db
156
+ assert_equal %w[master], task.target_hosts
157
+
158
+ task.options[:roles] = [:master_db]
159
+ assert_equal %w[master], task.target_hosts
160
+ end
161
+
162
+ def test_set
163
+ set :win, 5
164
+ assert_equal 5, @vlad.win
165
+ end
166
+
167
+ def test_set_lazy_block_evaluation
168
+ set(:lose) { raise "lose" }
169
+ assert_raises(RuntimeError) { @vlad.lose }
170
+ end
171
+
172
+ def test_set_with_block
173
+ x = 1
174
+ set(:win) { x += 2 }
175
+
176
+ assert_equal 3, @vlad.win
177
+ assert_equal 3, @vlad.win
178
+ end
179
+
180
+ def test_set_with_reference
181
+ @vlad.instance_eval do
182
+ set(:var_one) { var_two }
183
+ set(:var_two) { var_three }
184
+ set(:var_three) { 5 }
185
+ end
186
+
187
+ assert_equal 5, @vlad.var_one
188
+ end
189
+
190
+ def test_set_with_block_and_value
191
+ e = assert_raises(ArgumentError) do
192
+ set(:loser, 5) { 6 }
193
+ end
194
+ assert_equal "cannot provide both a value and a block", e.message
195
+ end
196
+
197
+ def test_set_with_nil
198
+ set(:win, nil)
199
+ assert_equal nil, @vlad.win
200
+ end
201
+
202
+ def test_set_with_reserved_name
203
+ $TESTING = false
204
+ e = assert_raises(ArgumentError) { set(:all_hosts, []) }
205
+ assert_equal "cannot set reserved name: 'all_hosts'", e.message
206
+ ensure
207
+ $TESTING = true
208
+ end
209
+ end
210
+
@@ -0,0 +1,41 @@
1
+ require 'test/vlad_test_case'
2
+ require 'vlad'
3
+ require 'vlad/git'
4
+
5
+ class TestVladGit < VladTestCase
6
+ def setup
7
+ super
8
+ @scm = Vlad::Git.new
9
+ set :repository, "git@myhost:/home/john/project1"
10
+ end
11
+
12
+ # Checkout the way the default :update task invokes the method
13
+ def test_checkout
14
+ cmd = @scm.checkout 'head', '/the/scm/path'
15
+ assert_equal 'rm -rf /the/scm/path/repo && git clone git@myhost:/home/john/project1 /the/scm/path/repo && cd /the/scm/path/repo && git checkout -f -b deployed-HEAD HEAD && cd -', cmd
16
+ end
17
+
18
+ # This is not how the :update task invokes the method
19
+ def test_checkout_revision
20
+ # Checkout to the current directory
21
+ cmd = @scm.checkout 'master', '.'
22
+ assert_equal 'rm -rf ./repo && git clone git@myhost:/home/john/project1 ./repo && cd ./repo && git checkout -f -b deployed-master master && cd -', cmd
23
+
24
+ # Checkout to a relative path
25
+ cmd = @scm.checkout 'master', 'some/relative/path'
26
+ assert_equal 'rm -rf some/relative/path/repo && git clone git@myhost:/home/john/project1 some/relative/path/repo && cd some/relative/path/repo && git checkout -f -b deployed-master master && cd -', cmd
27
+ end
28
+
29
+ def test_export
30
+ cmd = @scm.export 'master', 'the/release/path'
31
+ assert_equal 'mkdir -p the/release/path && cd repo && git archive --format=tar deployed-master | (cd the/release/path && tar xf -) && cd - && cd ..', cmd
32
+ end
33
+
34
+ def test_revision
35
+ ['head', 'HEAD'].each do |head|
36
+ cmd = @scm.revision(head)
37
+ expected = "`git rev-parse HEAD`"
38
+ assert_equal expected, cmd
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,31 @@
1
+ require 'test/vlad_test_case'
2
+ require 'vlad'
3
+ require 'vlad/mercurial'
4
+
5
+ class TestVladMercurial < MiniTest::Unit::TestCase
6
+ def setup
7
+ @scm = Vlad::Mercurial.new
8
+ set :repository, "http://repo/project"
9
+ end
10
+
11
+ def test_checkout
12
+ cmd = @scm.checkout 'head', '/the/place'
13
+
14
+ expected = "if [ ! -d /the/place/.hg ]; then hg init -R /the/place; fi " \
15
+ "&& hg pull -r tip -R /the/place http://repo/project"
16
+
17
+ assert_equal expected, cmd
18
+ end
19
+
20
+ def test_export
21
+ cmd = @scm.export 'head', '/the/place'
22
+ assert_equal 'hg archive -r tip -R http://repo/project /the/place', cmd
23
+ end
24
+
25
+ def test_revision
26
+ cmd = @scm.revision('tip')
27
+ expected = "`hg identify -R http://repo/project | cut -f1 -d\\ `"
28
+ assert_equal expected, cmd
29
+ end
30
+ end
31
+
@@ -0,0 +1,37 @@
1
+ require 'test/vlad_test_case'
2
+ require 'vlad'
3
+ require 'vlad/perforce'
4
+
5
+ class TestVladPerforce < VladTestCase
6
+ def setup
7
+ super
8
+ @scm = Vlad::Perforce.new
9
+ end
10
+
11
+ def test_checkout
12
+ cmd = @scm.checkout 'head', '/the/place'
13
+ assert_equal 'p4 sync ...#head', cmd
14
+ end
15
+
16
+ def test_checkout_revision
17
+ cmd = @scm.checkout 555, '/the/place'
18
+ assert_equal 'p4 sync ...@555', cmd
19
+ end
20
+
21
+ def test_export
22
+ cmd = @scm.export 'head', '/the/place'
23
+ assert_equal '(cd /the/place && p4 sync ...#head)', cmd
24
+ end
25
+
26
+ def test_revision
27
+ cmd = @scm.revision('head')
28
+ assert_equal '`p4 changes -s submitted -m 1 ...#head | cut -f 2 -d\\ `', cmd
29
+ end
30
+
31
+ def test_rev_no
32
+ assert_equal "@555", @scm.rev_no(555)
33
+ assert_equal "#head", @scm.rev_no('head')
34
+ assert_equal "#head", @scm.rev_no('HEAD')
35
+ assert_equal "@666", @scm.rev_no("@666")
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ require 'test/vlad_test_case'
2
+ require 'vlad'
3
+ require 'vlad/subversion'
4
+
5
+ class TestVladSubversion < VladTestCase
6
+ def setup
7
+ super
8
+ @scm = Vlad::Subversion.new
9
+ set :repository, "svn+ssh://repo/myproject"
10
+ end
11
+
12
+ def test_checkout
13
+ cmd = @scm.checkout 'HEAD', '/the/place'
14
+ assert_equal 'svn co -r HEAD svn+ssh://repo/myproject /the/place', cmd
15
+ end
16
+
17
+ def test_export
18
+ cmd = @scm.export 'HEAD', '/the/place'
19
+ assert_equal 'svn export -r HEAD svn+ssh://repo/myproject /the/place', cmd
20
+ end
21
+
22
+ def test_revision
23
+ cmd = @scm.revision('HEAD')
24
+ expected = "`svn info svn+ssh://repo/myproject | grep 'Revision:' | cut -f2 -d\\ `"
25
+ assert_equal expected, cmd
26
+ end
27
+ end
@@ -0,0 +1,72 @@
1
+ require 'minitest/autorun'
2
+ require 'stringio'
3
+ require 'vlad'
4
+
5
+ class StringIO
6
+ def readpartial(size) read end # suck!
7
+ end
8
+
9
+ module Process
10
+ def self.expected status
11
+ @@expected ||= []
12
+ @@expected << status
13
+ end
14
+
15
+ class << self
16
+ alias :waitpid2_old :waitpid2
17
+
18
+ def waitpid2(pid)
19
+ [ @@expected.shift ]
20
+ end
21
+ end
22
+ end
23
+
24
+ class Rake::RemoteTask
25
+ attr_accessor :commands, :action, :input, :output, :error
26
+
27
+ Status = Struct.new :exitstatus
28
+
29
+ class Status
30
+ def success?() exitstatus == 0 end
31
+ end
32
+
33
+ def system *command
34
+ @commands << command
35
+ self.action ? self.action[command.join(' ')] : true
36
+ end
37
+
38
+ def popen4 *command
39
+ @commands << command
40
+
41
+ @input = StringIO.new
42
+ out = StringIO.new @output.shift.to_s
43
+ err = StringIO.new @error.shift.to_s
44
+
45
+ raise if block_given?
46
+
47
+ status = self.action ? self.action[command.join(' ')] : 0
48
+ Process.expected Status.new(status)
49
+
50
+ return 42, @input, out, err
51
+ end
52
+
53
+ def select reads, writes, errs, timeout
54
+ [reads, writes, errs]
55
+ end
56
+
57
+ end
58
+
59
+ class VladTestCase < MiniTest::Unit::TestCase
60
+ def setup
61
+ @vlad = Rake::RemoteTask
62
+ @vlad.reset
63
+ Rake.application.clear
64
+ @task_count = Rake.application.tasks.size
65
+ @vlad.set :domain, "example.com"
66
+ end
67
+
68
+ def util_set_hosts
69
+ @vlad.host "app.example.com", :app
70
+ @vlad.host "db.example.com", :db
71
+ end
72
+ end
data/vladdemo.sh ADDED
@@ -0,0 +1,97 @@
1
+ #!/bin/bash
2
+
3
+ N=$1; shift
4
+
5
+ killall mongrel svnserve 2> /dev/null
6
+
7
+ rm -rf ~/demo
8
+ mkdir ~/demo
9
+ cd ~/demo
10
+
11
+ pause() {
12
+ echo -n "waiting... hit return... "
13
+ read
14
+ echo
15
+ }
16
+
17
+ echo "Starting demo from scratch"
18
+ echo " This step creates a subversion repository and imports a new rails app"
19
+ echo " It modifies the Rakefile to load Vlad and creates config/deploy.rb"
20
+ echo
21
+ pause
22
+
23
+ svnadmin create svnrepo
24
+ echo "anon-access = write" >> svnrepo/conf/svnserve.conf
25
+
26
+ svnserve -d --foreground -r svnrepo --listen-host localhost &
27
+
28
+ echo "cd ~/demo
29
+ rm -rf website_*
30
+ svnserve -d --foreground -r svnrepo --listen-host localhost &
31
+
32
+ cd mydemoapp
33
+ ruby -I ~/Work/p4/zss/src/vlad/dev/lib -S rake -t vlad:setup vlad:update
34
+
35
+ kill %1" > go.sh
36
+ chmod u+x go.sh
37
+
38
+ rails mydemoapp
39
+
40
+ cd mydemoapp
41
+
42
+ echo "require 'rubygems'
43
+ require 'vlad'
44
+ Vlad.load" >> Rakefile
45
+
46
+ echo "set :repository, 'svn://localhost/blah'
47
+ set :domain, 'localhost'
48
+ set :web_command, 'sudo apachectl'" > config/deploy.rb
49
+
50
+ # TODO: add a knob
51
+ if [ -n "$N" ]; then
52
+ echo "set(:deploy_to, :per_thread) {
53
+ File.expand_path(\"~/demo/website_#{target_host}\")
54
+ }
55
+
56
+ %w(current_path current_release latest_release
57
+ previous_release releases_path release_path
58
+ scm_path shared_path).each do |name|
59
+ Rake::RemoteTask.per_thread[name] = true
60
+ end
61
+
62
+ (1..$N).each do |n|
63
+ host 'localhost%02d' % n, :web, :app
64
+ end" >> config/deploy.rb
65
+ else
66
+ echo "set :deploy_to, File.expand_path('~/demo/website')" >> config/deploy.rb
67
+ fi
68
+
69
+ svn import -m Added . svn://localhost/blah
70
+
71
+ echo
72
+ echo "Here is your config:"
73
+ cat config/deploy.rb
74
+ echo
75
+ echo "Here are the tasks available:"
76
+ echo
77
+
78
+ ruby -I ~/Work/p4/zss/src/vlad/dev/lib -S rake -T vlad
79
+
80
+ echo
81
+ echo "The next step deploys and fires up the application"
82
+ echo
83
+ pause
84
+
85
+ ruby -I ~/Work/p4/zss/src/vlad/dev/lib -S rake -t vlad:setup vlad:update vlad:start
86
+
87
+ open http://localhost:8000/
88
+
89
+ echo
90
+ echo "done! check it out"
91
+ echo
92
+ pause
93
+
94
+ ruby -I ~/Work/p4/zss/src/vlad/dev/lib -S rake vlad:stop
95
+
96
+ kill %1
97
+
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nuex-vlad
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Davis
8
+ - Eric Hodel
9
+ - Wilson Bilkovich
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-06-30 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rake
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.8.1
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: open4
29
+ type: :runtime
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ version:
37
+ - !ruby/object:Gem::Dependency
38
+ name: hoe
39
+ type: :development
40
+ version_requirement:
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.1
46
+ version:
47
+ description: Vlad the Deployer is pragmatic application deployment automation, without mercy. Much like Capistrano, but with 1/10th the complexity. Vlad integrates seamlessly with Rake, and uses familiar and standard tools like ssh and rsync. Impale your application on the heartless spike of the Deployer.
48
+ email:
49
+ - ryand-ruby@zenspider.com
50
+ - drbrain@segment7.net
51
+ - wilson@supremetyrant.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ - README.txt
60
+ - considerations.txt
61
+ - doco/deploying-merb-with-vlad.txt
62
+ - doco/deploying-sinatra-with-vlad.txt
63
+ - doco/faq.txt
64
+ - doco/getting_started.txt
65
+ - doco/migration.txt
66
+ - doco/perforce.txt
67
+ - doco/variables.txt
68
+ files:
69
+ - History.txt
70
+ - Manifest.txt
71
+ - README.txt
72
+ - Rakefile
73
+ - considerations.txt
74
+ - doco/deploying-merb-with-vlad.txt
75
+ - doco/deploying-sinatra-with-vlad.txt
76
+ - doco/faq.txt
77
+ - doco/getting_started.txt
78
+ - doco/migration.txt
79
+ - doco/perforce.txt
80
+ - doco/variables.txt
81
+ - lib/rake_remote_task.rb
82
+ - lib/vlad.rb
83
+ - lib/vlad/apache.rb
84
+ - lib/vlad/core.rb
85
+ - lib/vlad/darcs.rb
86
+ - lib/vlad/git.rb
87
+ - lib/vlad/god.rb
88
+ - lib/vlad/lighttpd.rb
89
+ - lib/vlad/maintenance.rb
90
+ - lib/vlad/merb.rb
91
+ - lib/vlad/mercurial.rb
92
+ - lib/vlad/mongrel.rb
93
+ - lib/vlad/nginx.rb
94
+ - lib/vlad/passenger.rb
95
+ - lib/vlad/perforce.rb
96
+ - lib/vlad/subversion.rb
97
+ - lib/vlad/thin.rb
98
+ - test/test_rake_remote_task.rb
99
+ - test/test_vlad.rb
100
+ - test/test_vlad_git.rb
101
+ - test/test_vlad_mercurial.rb
102
+ - test/test_vlad_perforce.rb
103
+ - test/test_vlad_subversion.rb
104
+ - test/vlad_test_case.rb
105
+ - vladdemo.sh
106
+ has_rdoc: false
107
+ homepage: http://rubyhitsquad.com/
108
+ post_install_message:
109
+ rdoc_options:
110
+ - --main
111
+ - README.txt
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: "0"
119
+ version:
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: "0"
125
+ version:
126
+ requirements: []
127
+
128
+ rubyforge_project: hitsquad
129
+ rubygems_version: 1.2.0
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Vlad the Deployer is pragmatic application deployment automation, without mercy
133
+ test_files:
134
+ - test/test_rake_remote_task.rb
135
+ - test/test_vlad.rb
136
+ - test/test_vlad_git.rb
137
+ - test/test_vlad_mercurial.rb
138
+ - test/test_vlad_perforce.rb
139
+ - test/test_vlad_subversion.rb