mina 0.1.0
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 +4 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +10 -0
- data/HISTORY.md +148 -0
- data/LICENSE +23 -0
- data/README.md +620 -0
- data/Rakefile +33 -0
- data/bin/mina +49 -0
- data/data/deploy.rb +30 -0
- data/data/deploy.sh.erb +98 -0
- data/lib/mina.rb +20 -0
- data/lib/mina/bundler.rb +23 -0
- data/lib/mina/default.rb +97 -0
- data/lib/mina/deploy.rb +57 -0
- data/lib/mina/deploy_helpers.rb +25 -0
- data/lib/mina/git.rb +14 -0
- data/lib/mina/helpers.rb +278 -0
- data/lib/mina/rails.rb +69 -0
- data/lib/mina/rake.rb +6 -0
- data/lib/mina/settings.rb +32 -0
- data/lib/mina/tools.rb +14 -0
- data/lib/mina/version.rb +5 -0
- data/mina.gemspec +17 -0
- data/spec/command_helper.rb +52 -0
- data/spec/commands/command_spec.rb +65 -0
- data/spec/commands/deploy_spec.rb +36 -0
- data/spec/commands/outside_project_spec.rb +35 -0
- data/spec/commands/real_deploy_spec.rb +53 -0
- data/spec/commands/verbose_spec.rb +20 -0
- data/spec/dsl/queue_spec.rb +49 -0
- data/spec/dsl/settings_in_rake_spec.rb +42 -0
- data/spec/dsl/settings_spec.rb +60 -0
- data/spec/dsl/to_spec.rb +20 -0
- data/spec/spec_helper.rb +20 -0
- data/test_env/config/deploy.rb +54 -0
- metadata +117 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'command_helper'
|
3
|
+
|
4
|
+
describe "Invoking the 'mina' command in a project" do
|
5
|
+
before :each do
|
6
|
+
Dir.chdir root('test_env')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should think it's 'mina', not 'rake' (1)" do
|
10
|
+
run_command 'pinkledills'
|
11
|
+
exitstatus.should_not == 0
|
12
|
+
stderr.should include 'mina aborted'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should think it's 'mina', not 'rake' (1)" do
|
16
|
+
mina '-T'
|
17
|
+
stdout.should include 'mina help'
|
18
|
+
stdout.should include 'mina git:clone'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'with --version should print the version' do
|
22
|
+
mina '--version'
|
23
|
+
stdout.should include Mina.version
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'with -V should print the version' do
|
27
|
+
mina '-V'
|
28
|
+
stdout.should include Mina.version
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'without arguments' do
|
32
|
+
before :each do
|
33
|
+
mina
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should print standard help tasks' do
|
37
|
+
mina
|
38
|
+
stdout.should include 'mina help'
|
39
|
+
stdout.should include 'mina init'
|
40
|
+
stdout.should include 'mina tasks'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should print project-specific tasks' do
|
44
|
+
mina
|
45
|
+
stdout.should include 'mina deploy'
|
46
|
+
stdout.should include 'mina restart'
|
47
|
+
stdout.should include 'mina setup'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be the same as running 'help'" do
|
51
|
+
previous_out = stdout
|
52
|
+
|
53
|
+
mina 'help'
|
54
|
+
stdout.should == previous_out
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "with 'mina tasks' should print tasks" do
|
59
|
+
mina 'tasks'
|
60
|
+
|
61
|
+
stdout.should include('bundle:install')
|
62
|
+
stdout.should include('Install gem dependencies using Bundler')
|
63
|
+
stdout.should include('passenger:restart')
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'command_helper'
|
3
|
+
|
4
|
+
describe "Invoking the 'mina' command in a project" do
|
5
|
+
before :each do
|
6
|
+
Dir.chdir root('test_env')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "to do a simulated deploy" do
|
10
|
+
before :each do
|
11
|
+
mina 'deploy', 'simulate=1'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should take care of the lockfile" do
|
15
|
+
stdout.should =~ /ERROR: another deployment is ongoing/
|
16
|
+
stdout.should =~ /touch ".*deploy\.lock"/
|
17
|
+
stdout.should =~ /rm -f ".*deploy\.lock"/
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should honor releases_path" do
|
21
|
+
stdout.should include "releases/"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should symlink the current_path" do
|
25
|
+
stdout.should =~ /ln .*current/
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should include deploy directives" do
|
29
|
+
stdout.should include "bundle exec rake db:migrate"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should include 'to :launch' directives" do
|
33
|
+
stdout.should include "touch tmp/restart.txt"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'command_helper'
|
3
|
+
|
4
|
+
describe "Invoking the 'mina' command outside a project" do
|
5
|
+
before :each do
|
6
|
+
Dir.chdir root
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "without arguments" do
|
10
|
+
before :each do
|
11
|
+
mina
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should print standard help tasks' do
|
15
|
+
stdout.should include('mina help')
|
16
|
+
stdout.should include('mina init')
|
17
|
+
stdout.should include('mina tasks')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not print project-specific tasks" do
|
21
|
+
stdout.should_not include('mina deploy')
|
22
|
+
stdout.should_not include('mina restart')
|
23
|
+
stdout.should_not include('mina setup')
|
24
|
+
end
|
25
|
+
|
26
|
+
%w[-h --help].each do |arg|
|
27
|
+
it "should have the same output as 'mina #{arg}'" do
|
28
|
+
@previous_output = stdout
|
29
|
+
mina arg
|
30
|
+
stdout.should == @previous_output
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'command_helper'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
describe "Invoking the 'mina' command in a project", :ssh => true do
|
7
|
+
before :each do
|
8
|
+
@path = Dir.mktmpdir
|
9
|
+
Dir.chdir @path
|
10
|
+
|
11
|
+
FileUtils.mkdir_p './config'
|
12
|
+
FileUtils.cp root('test_env/config/deploy.rb'), './config/deploy.rb'
|
13
|
+
FileUtils.rm_rf './deploy'
|
14
|
+
FileUtils.mkdir_p './deploy'
|
15
|
+
end
|
16
|
+
|
17
|
+
# after :each do
|
18
|
+
# FileUtils.rm_rf @path
|
19
|
+
# end
|
20
|
+
|
21
|
+
it 'should set up and deploy fine' do
|
22
|
+
print "[setup]" if ENV['verbose']
|
23
|
+
mina 'setup', '--verbose'
|
24
|
+
File.directory?('deploy').should be_true
|
25
|
+
File.directory?('deploy/releases').should be_true
|
26
|
+
File.directory?('deploy/shared').should be_true
|
27
|
+
File.exists?('deploy/last_version').should be_false
|
28
|
+
File.exists?('deploy/deploy.lock').should be_false
|
29
|
+
|
30
|
+
print "[deploy 1]" if ENV['verbose']
|
31
|
+
mina 'deploy', '--verbose'
|
32
|
+
stdout.should include "-----> Creating a temporary build path"
|
33
|
+
stdout.should include "rm -rf .git"
|
34
|
+
stdout.should include "mkdir -p"
|
35
|
+
File.exists?('deploy/last_version').should be_true
|
36
|
+
File.exists?('deploy/deploy.lock').should be_false
|
37
|
+
File.directory?('deploy/releases').should be_true
|
38
|
+
File.directory?('deploy/releases/1').should be_true
|
39
|
+
File.exists?('deploy/releases/1/README.md').should be_true
|
40
|
+
File.directory?('deploy/releases/2').should be_false
|
41
|
+
File.exists?('deploy/current').should be_true
|
42
|
+
File.read('deploy/last_version').strip.should == '1'
|
43
|
+
File.exists?('deploy/current/tmp/restart.txt').should be_true
|
44
|
+
|
45
|
+
# And again, to test out sequential versions and stuff
|
46
|
+
print "[deploy 2]" if ENV['verbose']
|
47
|
+
mina 'deploy'
|
48
|
+
stdout.should_not include "rm -rf .git"
|
49
|
+
stdout.should_not include "mkdir -p"
|
50
|
+
File.directory?('deploy/releases/2').should be_true
|
51
|
+
File.read('deploy/last_version').strip.should == '2'
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'command_helper'
|
3
|
+
|
4
|
+
describe "Invoking the 'mina' command in a project" do
|
5
|
+
before :each do
|
6
|
+
Dir.chdir root('test_env')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should echo commands in verbose mode' do
|
10
|
+
mina 'deploy', '--verbose', '--simulate'
|
11
|
+
|
12
|
+
stdout.should include %[echo "$ git]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should not echo commands when not in verbose mode' do
|
16
|
+
mina 'deploy', '--simulate'
|
17
|
+
|
18
|
+
stdout.should_not include %[echo "$ git]
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mina' do
|
4
|
+
it '#invoke should work' do
|
5
|
+
rake {
|
6
|
+
task :hello do
|
7
|
+
@hello = 'world'
|
8
|
+
end
|
9
|
+
invoke :hello
|
10
|
+
}
|
11
|
+
rake.instance_variable_get(:@hello).should == 'world'
|
12
|
+
end
|
13
|
+
|
14
|
+
it '#queue should work' do
|
15
|
+
rake {
|
16
|
+
queue 'sudo service nginx restart'
|
17
|
+
}
|
18
|
+
|
19
|
+
rake.commands.should == ['sudo service nginx restart']
|
20
|
+
end
|
21
|
+
|
22
|
+
it '#queue should work with multiple commands' do
|
23
|
+
rake {
|
24
|
+
queue 'echo Restarting'
|
25
|
+
queue 'sudo service nginx restart'
|
26
|
+
}
|
27
|
+
|
28
|
+
rake.commands.should == ['echo Restarting', 'sudo service nginx restart']
|
29
|
+
end
|
30
|
+
|
31
|
+
it '#queue should work inside tasks' do
|
32
|
+
rake {
|
33
|
+
task :restart do
|
34
|
+
queue 'echo Restarting'
|
35
|
+
invoke :'passenger:restart'
|
36
|
+
end
|
37
|
+
|
38
|
+
namespace :passenger do
|
39
|
+
task :restart do
|
40
|
+
queue 'touch tmp/restart.txt'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
}
|
44
|
+
|
45
|
+
rake { invoke :restart }
|
46
|
+
|
47
|
+
rake.commands.should == ['echo Restarting', 'touch tmp/restart.txt']
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Settings in rake tasks' do
|
4
|
+
it '#set should work' do
|
5
|
+
rake { set :host, 'localhost' }
|
6
|
+
|
7
|
+
rake.host.should == 'localhost'
|
8
|
+
rake.settings.host.should == 'localhost'
|
9
|
+
end
|
10
|
+
|
11
|
+
it '#settings ||= should work' do
|
12
|
+
rake {
|
13
|
+
set :version, '2'
|
14
|
+
settings.version ||= '3'
|
15
|
+
}
|
16
|
+
|
17
|
+
rake.settings.version.should == '2'
|
18
|
+
rake.version.should == '2'
|
19
|
+
end
|
20
|
+
|
21
|
+
it '#settings with lambdas should work' do
|
22
|
+
rake {
|
23
|
+
set :version, '42'
|
24
|
+
set :path, lambda { "/var/www/#{version}" }
|
25
|
+
}
|
26
|
+
|
27
|
+
rake.path.should == "/var/www/42"
|
28
|
+
rake.path?.should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it '#settings with a bang should work' do
|
32
|
+
begin
|
33
|
+
rake {
|
34
|
+
set :path, lambda { "/var/www/#{version!}" }
|
35
|
+
}
|
36
|
+
rake.path
|
37
|
+
1.should == 2
|
38
|
+
rescue Mina::Error => e
|
39
|
+
e.message.should include "version"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Settings' do
|
4
|
+
describe 'instances' do
|
5
|
+
before :each do
|
6
|
+
@settings = Mina::Settings.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'setting/getting should work' do
|
10
|
+
@settings.host = '192.168.1.1'
|
11
|
+
@settings.host.should == '192.168.1.1'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'question mark should work' do
|
15
|
+
@settings.deploy_to = '/var/www/there'
|
16
|
+
@settings.deploy_to?.should be_true
|
17
|
+
@settings.foobar?.should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'question mark should work with nils' do
|
21
|
+
@settings.deploy_to = nil
|
22
|
+
@settings.deploy_to?.should be_true
|
23
|
+
@settings.foobar?.should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it '||= should work (1)' do
|
27
|
+
@settings.x = 2
|
28
|
+
@settings.x ||= 3
|
29
|
+
@settings.x.should == 2
|
30
|
+
end
|
31
|
+
|
32
|
+
it '||= should work (2)' do
|
33
|
+
@settings.x ||= 3
|
34
|
+
@settings.x.should == 3
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'lambdas should work' do
|
38
|
+
@settings.path = lambda { "/var/www/#{@settings.version}" }
|
39
|
+
@settings.version = '3'
|
40
|
+
|
41
|
+
@settings.path?.should be_true
|
42
|
+
@settings.path.should == "/var/www/3"
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'bangs should check for settings' do
|
46
|
+
begin
|
47
|
+
@settings.non_existent_setting!
|
48
|
+
1.should == 2
|
49
|
+
rescue Mina::Error => e
|
50
|
+
e.message.should include "non_existent_setting"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'bangs should return settings' do
|
55
|
+
@settings.version = 4
|
56
|
+
@settings.version!.should == 4
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/spec/dsl/to_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mina' do
|
4
|
+
it '#to should work' do
|
5
|
+
rake {
|
6
|
+
task :deploy do
|
7
|
+
queue 'git clone'
|
8
|
+
|
9
|
+
to :restart do
|
10
|
+
queue 'touch tmp/restart.txt'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
rake { invoke :deploy }
|
16
|
+
|
17
|
+
rake.commands.should == ['git clone']
|
18
|
+
rake.commands(:restart).should == ['touch tmp/restart.txt']
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mina'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
class RakeScope
|
5
|
+
include Rake::DSL if Rake.const_defined?(:DSL)
|
6
|
+
include Mina::Helpers
|
7
|
+
end
|
8
|
+
|
9
|
+
def rake(&blk)
|
10
|
+
if block_given?
|
11
|
+
@scope ||= RakeScope.new
|
12
|
+
@scope.instance_eval &blk
|
13
|
+
end
|
14
|
+
|
15
|
+
@scope
|
16
|
+
end
|
17
|
+
|
18
|
+
def root(*a)
|
19
|
+
File.join File.expand_path('../../', __FILE__), *a
|
20
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# NOTE:
|
2
|
+
# Yes, you can deploy this project. It will deploy into the ./deploy/
|
3
|
+
# directory. The commands have been stubbed, so it's harmless. No rails or
|
4
|
+
# bundler magic will happen.
|
5
|
+
|
6
|
+
# ASSUMPTIONS:
|
7
|
+
# - You have git installed. (of course you do)
|
8
|
+
# - You have SSH enabled. In OS X, this is "Remote Login" under the Sharing pref pane.
|
9
|
+
# - You have your own SSH key added to your own user so you can SSH to your own machine.
|
10
|
+
|
11
|
+
# In fact, let's make that folder right now.
|
12
|
+
require 'fileutils'
|
13
|
+
FileUtils.mkdir_p "#{Dir.pwd}/deploy"
|
14
|
+
|
15
|
+
# -- Stubs end, deploy script begins! --------------
|
16
|
+
|
17
|
+
require 'mina/rails'
|
18
|
+
require 'mina/bundler'
|
19
|
+
require 'mina/git'
|
20
|
+
|
21
|
+
set :domain, 'localhost'
|
22
|
+
set :deploy_to, "#{Dir.pwd}/deploy"
|
23
|
+
set :repository, "#{Mina.root_path}"
|
24
|
+
set :revision, 'HEAD'
|
25
|
+
|
26
|
+
desc "Deploys."
|
27
|
+
task :deploy do
|
28
|
+
queue "bundle() { true; }" # Stub the bundle command.
|
29
|
+
|
30
|
+
deploy do
|
31
|
+
invoke :'git:clone'
|
32
|
+
invoke :'bundle:install'
|
33
|
+
invoke :'rails:db_migrate'
|
34
|
+
|
35
|
+
to :launch do
|
36
|
+
invoke :'passenger:restart'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Restarts the passenger server."
|
42
|
+
task :restart do
|
43
|
+
invoke :'passenger:restart'
|
44
|
+
end
|
45
|
+
|
46
|
+
namespace :passenger do
|
47
|
+
task :restart do
|
48
|
+
queue %{
|
49
|
+
echo "-----> Restarting passenger"
|
50
|
+
#{echo_cmd %[mkdir -p tmp]}
|
51
|
+
#{echo_cmd %[touch tmp/restart.txt]}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|