colorful-mina 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +21 -0
  5. data/CONTRIBUTING.md +124 -0
  6. data/Gemfile +10 -0
  7. data/HISTORY.md +348 -0
  8. data/LICENSE +23 -0
  9. data/Makefile +29 -0
  10. data/Notes.md +70 -0
  11. data/README.md +1015 -0
  12. data/Rakefile +20 -0
  13. data/bin/mina +65 -0
  14. data/data/deploy.rb +80 -0
  15. data/data/deploy.sh.erb +106 -0
  16. data/lib/mina.rb +23 -0
  17. data/lib/mina/bundler.rb +49 -0
  18. data/lib/mina/chruby.rb +49 -0
  19. data/lib/mina/default.rb +145 -0
  20. data/lib/mina/deploy.rb +138 -0
  21. data/lib/mina/deploy_helpers.rb +34 -0
  22. data/lib/mina/exec_helpers.rb +111 -0
  23. data/lib/mina/foreman.rb +82 -0
  24. data/lib/mina/git.rb +62 -0
  25. data/lib/mina/helpers.rb +386 -0
  26. data/lib/mina/output_helpers.rb +95 -0
  27. data/lib/mina/rails.rb +206 -0
  28. data/lib/mina/rake.rb +9 -0
  29. data/lib/mina/rbenv.rb +47 -0
  30. data/lib/mina/rvm.rb +88 -0
  31. data/lib/mina/settings.rb +32 -0
  32. data/lib/mina/ssh_helpers.rb +123 -0
  33. data/lib/mina/tools.rb +20 -0
  34. data/lib/mina/version.rb +5 -0
  35. data/lib/mina/whenever.rb +27 -0
  36. data/manual/index.md +15 -0
  37. data/manual/modules.md +2 -0
  38. data/mina.gemspec +17 -0
  39. data/spec/command_helper.rb +52 -0
  40. data/spec/commands/cleanup_spec.rb +16 -0
  41. data/spec/commands/command_spec.rb +71 -0
  42. data/spec/commands/custom_config_spec.rb +20 -0
  43. data/spec/commands/deploy_spec.rb +36 -0
  44. data/spec/commands/outside_project_spec.rb +35 -0
  45. data/spec/commands/real_deploy_spec.rb +53 -0
  46. data/spec/commands/ssh_spec.rb +14 -0
  47. data/spec/commands/verbose_spec.rb +21 -0
  48. data/spec/dsl/invoke_spec.rb +48 -0
  49. data/spec/dsl/queue_spec.rb +49 -0
  50. data/spec/dsl/settings_in_rake_spec.rb +39 -0
  51. data/spec/dsl/settings_spec.rb +61 -0
  52. data/spec/dsl/to_spec.rb +20 -0
  53. data/spec/fixtures/custom_file_env/custom_deploy.rb +15 -0
  54. data/spec/fixtures/empty_env/config/deploy.rb +15 -0
  55. data/spec/helpers/exec_helper_spec.rb +19 -0
  56. data/spec/helpers/output_helper_spec.rb +24 -0
  57. data/spec/spec_helper.rb +27 -0
  58. data/support/Readme-footer.md +32 -0
  59. data/support/Readme-header.md +16 -0
  60. data/support/guide.md +297 -0
  61. data/support/index.html +53 -0
  62. data/support/to_md.rb +11 -0
  63. data/test_env/config/deploy.rb +69 -0
  64. metadata +150 -0
@@ -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
+ expect(stdout).to include('mina help')
16
+ expect(stdout).to include('mina init')
17
+ expect(stdout).to include('mina tasks')
18
+ end
19
+
20
+ it "should not print project-specific tasks" do
21
+ expect(stdout).not_to include('mina deploy')
22
+ expect(stdout).not_to include('mina restart')
23
+ expect(stdout).not_to 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
+ expect(stdout).to eq(@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
+ expect(File.directory?('deploy')).to be_truthy
25
+ expect(File.directory?('deploy/releases')).to be_truthy
26
+ expect(File.directory?('deploy/shared')).to be_truthy
27
+ expect(File.exists?('deploy/last_version')).to be_falsey
28
+ expect(File.exists?('deploy/deploy.lock')).to be_falsey
29
+
30
+ print "[deploy 1]" if ENV['verbose']
31
+ mina 'deploy', '--verbose'
32
+ expect(stdout).to include "-----> Creating a temporary build path"
33
+ expect(stdout).to include "rm -rf .git"
34
+ expect(stdout).to include "mkdir -p"
35
+ expect(File.exists?('deploy/last_version')).to be_truthy
36
+ expect(File.exists?('deploy/deploy.lock')).to be_falsey
37
+ expect(File.directory?('deploy/releases')).to be_truthy
38
+ expect(File.directory?('deploy/releases/1')).to be_truthy
39
+ expect(File.exists?('deploy/releases/1/README.md')).to be_truthy
40
+ expect(File.directory?('deploy/releases/2')).to be_falsey
41
+ expect(File.exists?('deploy/current')).to be_truthy
42
+ expect(File.read('deploy/last_version').strip).to eq('1')
43
+ expect(File.exists?('deploy/current/tmp/restart.txt')).to be_truthy
44
+
45
+ # And again, to test out sequential versions and stuff
46
+ print "[deploy 2]" if ENV['verbose']
47
+ mina 'deploy'
48
+ expect(stdout).not_to include "rm -rf .git"
49
+ expect(stdout).not_to include "mkdir -p"
50
+ expect(File.directory?('deploy/releases/2')).to be_truthy
51
+ expect(File.read('deploy/last_version').strip).to eq('2')
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'command_helper'
3
+
4
+ describe "Invoking the 'mina' command in a project" do
5
+
6
+ it "should build ssh command even with frozen String as a domain" do
7
+ ENV['simulate'] = 'true'
8
+ rake {
9
+ set :domain, 'localhost'.freeze
10
+ ssh("ls")
11
+ }
12
+ end
13
+
14
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'command_helper'
3
+ require 'shellwords'
4
+
5
+ describe "Invoking the 'mina' command in a project" do
6
+ before :each do
7
+ Dir.chdir root('test_env')
8
+ end
9
+
10
+ it 'should echo commands in verbose mode' do
11
+ mina 'deploy', '--verbose', '--simulate'
12
+
13
+ expect(stdout).to include %[echo #{Shellwords.escape('$ git')}]
14
+ end
15
+
16
+ it 'should not echo commands when not in verbose mode' do
17
+ mina 'deploy', '--simulate'
18
+
19
+ expect(stdout).not_to include %[echo #{Shellwords.escape('$ git')}]
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mina' do
4
+ it '#invoke should work' do
5
+
6
+ rake {
7
+ task :clone do
8
+ queue 'git clone'
9
+ end
10
+ }
11
+
12
+ 2.times {
13
+ rake { invoke :clone }
14
+ }
15
+
16
+ expect(rake.commands).to eq(['git clone'])
17
+ end
18
+
19
+ it '#invoke should work with :reenable option' do
20
+
21
+ rake {
22
+ task :pull do
23
+ queue 'git pull'
24
+ end
25
+ }
26
+
27
+ 2.times {
28
+ rake { invoke :pull, :reenable => true }
29
+ }
30
+
31
+ expect(rake.commands).to eq(['git pull', 'git pull'])
32
+ end
33
+
34
+ it '#invoke with task arguments should work with :reenable option' do
35
+
36
+ rake {
37
+ task :hello, [:world] do |t, args|
38
+ queue "echo Hello #{args[:world]}"
39
+ end
40
+ }
41
+
42
+ %w(World Pirate).each { |name|
43
+ rake { invoke :"hello[#{name}]", :reenable => true }
44
+ }
45
+
46
+ expect(rake.commands).to eq(['echo Hello World', 'echo Hello Pirate'])
47
+ end
48
+ 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
+ expect(rake.instance_variable_get(:@hello)).to eq('world')
12
+ end
13
+
14
+ it '#queue should work' do
15
+ rake {
16
+ queue 'sudo service nginx restart'
17
+ }
18
+
19
+ expect(rake.commands).to eq(['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
+ expect(rake.commands).to eq(['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
+ expect(rake.commands).to eq(['echo Restarting', 'touch tmp/restart.txt'])
48
+ end
49
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Settings in rake tasks' do
4
+ it '#set should work' do
5
+ rake { set :domain, 'localhost' }
6
+
7
+ expect(rake.domain).to eq('localhost')
8
+ expect(rake.settings.domain).to eq('localhost')
9
+ end
10
+
11
+ it '#settings ||= should work' do
12
+ rake {
13
+ set :version, '2'
14
+ settings.version ||= '3'
15
+ }
16
+
17
+ expect(rake.settings.version).to eq('2')
18
+ expect(rake.version).to eq('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
+ expect(rake.path).to eq("/var/www/42")
28
+ expect(rake.path?).to be_truthy
29
+ end
30
+
31
+ it '#settings with a bang should work' do
32
+ expect {
33
+ rake {
34
+ set :path, lambda { "/var/www/#{version!}" }
35
+ }
36
+ rake.path
37
+ }.to raise_error(Mina::Error, /version/)
38
+ end
39
+ end
@@ -0,0 +1,61 @@
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.domain = '192.168.1.1'
11
+
12
+ expect(@settings.domain).to eq('192.168.1.1')
13
+ end
14
+
15
+ it 'question mark should work' do
16
+ @settings.deploy_to = '/var/www/there'
17
+
18
+ expect(@settings.deploy_to?).to be_truthy
19
+ expect(@settings.foobar?).to be_falsey
20
+ end
21
+
22
+ it 'question mark should work with nils' do
23
+ @settings.deploy_to = nil
24
+
25
+ expect(@settings.deploy_to?).to be_truthy
26
+ expect(@settings.foobar?).to be_falsey
27
+ end
28
+
29
+ it '||= should work (1)' do
30
+ @settings.x = 2
31
+ @settings.x ||= 3
32
+
33
+ expect(@settings.x).to eq(2)
34
+ end
35
+
36
+ it '||= should work (2)' do
37
+ @settings.x ||= 3
38
+
39
+ expect(@settings.x).to eq(3)
40
+ end
41
+
42
+ it 'lambdas should work' do
43
+ @settings.path = lambda { "/var/www/#{@settings.version}" }
44
+ @settings.version = '3'
45
+
46
+ expect(@settings.path?).to be_truthy
47
+ expect(@settings.path).to eq("/var/www/3")
48
+ end
49
+
50
+ it 'bangs should check for settings' do
51
+ expect { @settings.non_existent_setting! }.to raise_error(Mina::Error, /non_existent_setting/)
52
+ end
53
+
54
+ it 'bangs should return settings' do
55
+ @settings.version = 4
56
+
57
+ expect(@settings.version!).to eq(4)
58
+ end
59
+ end
60
+ end
61
+
@@ -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
+ expect(rake.commands).to eq(['git clone'])
18
+ expect(rake.commands(:restart)).to eq(['touch tmp/restart.txt'])
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ FileUtils.mkdir_p "#{Dir.pwd}/deploy"
3
+
4
+ require 'mina/git'
5
+
6
+ set :domain, 'localhost'
7
+ set :deploy_to, "#{Dir.pwd}/deploy"
8
+ set :repository, "#{Dir.pwd}"
9
+
10
+ desc "Deploys."
11
+ task :deploy do
12
+ deploy do
13
+ invoke :'git:clone'
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ FileUtils.mkdir_p "#{Dir.pwd}/deploy"
3
+
4
+ require 'mina/git'
5
+
6
+ set :domain, 'localhost'
7
+ set :deploy_to, "#{Dir.pwd}/deploy"
8
+ set :repository, "#{Dir.pwd}"
9
+
10
+ desc "Deploys."
11
+ task :deploy do
12
+ deploy do
13
+ invoke :'git:clone'
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Exec Helpers' do
4
+ before :each do
5
+ @exec = Object.new
6
+ @exec.send :extend, Mina::ExecHelpers
7
+
8
+ allow(@exec).to receive(:print_char)
9
+ end
10
+
11
+ it 'pretty_system' do
12
+ @exec.pretty_system "echo 'Hello there'"
13
+
14
+ expect(@exec).to have_received(:print_char).
15
+ with("e").with("r").with("e").with("h").with("t").
16
+ with(" ").
17
+ with("o").with("l").with("l").with("e").with("H")
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Output Helpers' do
4
+ before :each do
5
+ @out = Object.new
6
+ @out.send :extend, Mina::OutputHelpers
7
+ end
8
+
9
+ it 'print_str to stdout' do
10
+ expect(@out.print_str "Hello there\n" ).to include ' Hello there'
11
+ end
12
+
13
+ it 'print_str to status' do
14
+ expect(@out.print_str "-----> Getting password" ).to include "[32m-----> Getting password"
15
+ end
16
+
17
+ it 'print_str to status (2)' do
18
+ expect(@out.print_str "-> Getting password" ).to include "[32m-----> Getting password"
19
+ end
20
+
21
+ it 'print_str to error' do
22
+ expect(@out.print_str "! Something went wrong" ).to include "[31mSomething went wrong"
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'mina'
2
+ require 'rake'
3
+
4
+ RSpec.configure do |config|
5
+ config.order = 'random'
6
+ config.seed = '12345'
7
+ end
8
+
9
+ class RakeScope
10
+ include Rake::DSL if Rake.const_defined?(:DSL)
11
+ include Mina::Helpers
12
+ include Mina::SshHelpers
13
+ end
14
+
15
+ def rake(&blk)
16
+ if block_given?
17
+ @scope ||= RakeScope.new
18
+ @scope.instance_eval &blk
19
+ end
20
+
21
+ @scope
22
+ end
23
+
24
+ def root(*a)
25
+ File.join File.expand_path('../../', __FILE__), *a
26
+ end
27
+