mina 0.3.8 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +16 -0
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +1156 -0
  5. data/Gemfile +2 -8
  6. data/{CHANGELOG.md → PRE_1_CHANGELOG.md} +0 -0
  7. data/Rakefile +2 -18
  8. data/Readme.md +39 -1116
  9. data/bin/mina +1 -62
  10. data/data/deploy.rb +19 -46
  11. data/data/deploy.sh.erb +22 -23
  12. data/docs/Readme.md +8 -0
  13. data/docs/command_line_options.md +33 -0
  14. data/docs/deploying.md +97 -0
  15. data/docs/faq.md +1 -0
  16. data/docs/getting_started.md +44 -0
  17. data/docs/migrating.md +30 -0
  18. data/docs/writing_your_own_tasks.md +117 -0
  19. data/lib/Minafile +3 -0
  20. data/lib/mina.rb +30 -18
  21. data/lib/mina/application.rb +74 -0
  22. data/lib/mina/backend/local.rb +22 -0
  23. data/lib/mina/backend/remote.rb +42 -0
  24. data/lib/mina/commands.rb +45 -0
  25. data/lib/mina/configuration.rb +36 -0
  26. data/lib/mina/dsl.rb +47 -0
  27. data/lib/mina/helpers/internal.rb +29 -0
  28. data/lib/mina/helpers/output.rb +42 -0
  29. data/lib/mina/runner.rb +39 -0
  30. data/lib/mina/runner/exec.rb +15 -0
  31. data/lib/mina/runner/pretty.rb +53 -0
  32. data/lib/mina/runner/printer.rb +17 -0
  33. data/lib/mina/runner/system.rb +15 -0
  34. data/lib/mina/version.rb +1 -3
  35. data/mina.gemspec +27 -16
  36. data/spec/lib/mina/application_spec.rb +39 -0
  37. data/spec/lib/mina/backend/local_spec.rb +16 -0
  38. data/spec/lib/mina/backend/remote_spec.rb +17 -0
  39. data/spec/lib/mina/commands_spec.rb +93 -0
  40. data/spec/lib/mina/configuration_spec.rb +52 -0
  41. data/spec/lib/mina/helpers/internal_spec.rb +50 -0
  42. data/spec/lib/mina/helpers/output_spec.rb +48 -0
  43. data/spec/lib/mina/runner_spec.rb +36 -0
  44. data/spec/lib/mina_spec.rb +7 -0
  45. data/spec/spec_helper.rb +13 -21
  46. data/spec/support/run_helper.rb +36 -0
  47. data/tasks/mina/bundler.rb +15 -0
  48. data/tasks/mina/chruby.rb +19 -0
  49. data/tasks/mina/default.rb +36 -0
  50. data/tasks/mina/deploy.rb +85 -0
  51. data/tasks/mina/git.rb +36 -0
  52. data/tasks/mina/install.rb +18 -0
  53. data/tasks/mina/rails.rb +108 -0
  54. data/tasks/mina/rbenv.rb +15 -0
  55. data/tasks/mina/rvm.rb +39 -0
  56. data/tasks/mina/ry.rb +26 -0
  57. data/test_env/config/deploy.rb +44 -72
  58. metadata +82 -59
  59. data/.travis.yml +0 -21
  60. data/CONTRIBUTING.md +0 -124
  61. data/HISTORY.md +0 -394
  62. data/Makefile +0 -32
  63. data/Notes.md +0 -70
  64. data/lib/mina/bundler.rb +0 -49
  65. data/lib/mina/chruby.rb +0 -49
  66. data/lib/mina/default.rb +0 -158
  67. data/lib/mina/deploy.rb +0 -160
  68. data/lib/mina/deploy_helpers.rb +0 -34
  69. data/lib/mina/exec_helpers.rb +0 -111
  70. data/lib/mina/foreman.rb +0 -83
  71. data/lib/mina/git.rb +0 -69
  72. data/lib/mina/helpers.rb +0 -408
  73. data/lib/mina/local_helpers.rb +0 -97
  74. data/lib/mina/npm.rb +0 -89
  75. data/lib/mina/output_helpers.rb +0 -92
  76. data/lib/mina/rails.rb +0 -245
  77. data/lib/mina/rake.rb +0 -10
  78. data/lib/mina/rbenv.rb +0 -47
  79. data/lib/mina/rvm.rb +0 -88
  80. data/lib/mina/ry.rb +0 -55
  81. data/lib/mina/settings.rb +0 -32
  82. data/lib/mina/ssh_helpers.rb +0 -125
  83. data/lib/mina/tools.rb +0 -20
  84. data/lib/mina/whenever.rb +0 -51
  85. data/manual/index.md +0 -15
  86. data/manual/modules.md +0 -2
  87. data/spec/command_helper.rb +0 -52
  88. data/spec/commands/cleanup_spec.rb +0 -16
  89. data/spec/commands/command_spec.rb +0 -71
  90. data/spec/commands/custom_config_spec.rb +0 -20
  91. data/spec/commands/deploy_spec.rb +0 -40
  92. data/spec/commands/outside_project_spec.rb +0 -35
  93. data/spec/commands/real_deploy_spec.rb +0 -56
  94. data/spec/commands/ssh_spec.rb +0 -14
  95. data/spec/commands/verbose_spec.rb +0 -21
  96. data/spec/dsl/invoke_spec.rb +0 -49
  97. data/spec/dsl/queue_spec.rb +0 -49
  98. data/spec/dsl/settings_in_rake_spec.rb +0 -39
  99. data/spec/dsl/settings_spec.rb +0 -61
  100. data/spec/dsl/to_spec.rb +0 -20
  101. data/spec/fixtures/custom_file_env/custom_deploy.rb +0 -15
  102. data/spec/fixtures/empty_env/config/deploy.rb +0 -15
  103. data/spec/helpers/exec_helper_spec.rb +0 -19
  104. data/spec/helpers/local_helper_spec.rb +0 -70
  105. data/spec/helpers/output_helper_spec.rb +0 -38
  106. data/support/Readme-footer.md +0 -31
  107. data/support/Readme-header.md +0 -16
  108. data/support/guide.md +0 -297
  109. data/support/index.html +0 -53
  110. data/support/third_party_modules.md +0 -23
  111. data/support/to_md.rb +0 -11
@@ -0,0 +1,29 @@
1
+ module Mina
2
+ module Helpers
3
+ module Internal
4
+ def deploy_script
5
+ yield
6
+ erb Mina.root_path(fetch(:deploy_script))
7
+ end
8
+
9
+ def erb(file, b = binding)
10
+ require 'erb'
11
+ erb = ERB.new(File.read(file))
12
+ erb.result b
13
+ end
14
+
15
+ def echo_cmd(code, ignore_verbose = false)
16
+ if Mina::Configuration.instance.fetch(:verbose) && !ignore_verbose
17
+ "echo #{Shellwords.escape('$ ' + code)} &&\n#{code}"
18
+ else
19
+ code
20
+ end
21
+ end
22
+
23
+ def indent(count, str)
24
+ str.gsub(/^/, ' ' * count)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ extend Mina::Helpers::Internal
@@ -0,0 +1,42 @@
1
+ module Mina
2
+ module Helpers
3
+ module Output
4
+ def print_line(line)
5
+ case line
6
+ when /^\-+> (.*?)$/
7
+ print_status Regexp.last_match[1]
8
+ when /^! (.*?)$/
9
+ print_error Regexp.last_match[1]
10
+ when /^\$ (.*?)$/
11
+ print_command Regexp.last_match[1]
12
+ else
13
+ print_stdout line
14
+ end
15
+ end
16
+
17
+ def print_status(msg)
18
+ puts "#{color('----->', 32)} #{msg}"
19
+ end
20
+
21
+ def print_error(msg)
22
+ puts " #{color('!', 33)} #{color(msg, 31)}"
23
+ end
24
+
25
+ def print_stderr(msg)
26
+ puts " #{color(msg, 31)}"
27
+ end
28
+
29
+ def print_command(msg)
30
+ puts " #{color('$', 36)} #{color(msg, 36)}"
31
+ end
32
+
33
+ def print_stdout(msg)
34
+ puts " #{msg}"
35
+ end
36
+
37
+ def color(str, c)
38
+ ENV['NO_COLOR'] ? str : "\033[#{c}m#{str}\033[0m"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ module Mina
2
+ class Runner
3
+ attr_reader :commands, :backend
4
+
5
+ def initialize(commands, backend)
6
+ fail 'You must specify execution mode' if execution_mode.nil?
7
+ fail 'Unsuported execution mode (pretty on windows)' if unsuported_execution_mode?
8
+ @backend = backend
9
+ @commands = commands
10
+ end
11
+
12
+ def run
13
+ Mina::Runner.const_get(class_name_for(execution_mode)).new(script).run
14
+ end
15
+
16
+ def execution_mode
17
+ @execution_mode ||=
18
+ if Mina::Configuration.instance.fetch(:simulate)
19
+ :printer
20
+ else
21
+ Mina::Configuration.instance.fetch(:execution_mode)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def script
28
+ Mina::Backend.const_get(class_name_for(backend)).new(commands).prepare
29
+ end
30
+
31
+ def unsuported_execution_mode?
32
+ execution_mode == :pretty && Gem::Platform.local.os == :windows
33
+ end
34
+
35
+ def class_name_for(symbol)
36
+ symbol.to_s.split('_').map(&:capitalize).join
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ module Mina
2
+ class Runner
3
+ class Exec
4
+ attr_reader :script
5
+
6
+ def initialize(script)
7
+ @script = script
8
+ end
9
+
10
+ def run
11
+ Kernel.exec(script)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ module Mina
2
+ class Runner
3
+ class Pretty
4
+ include Mina::Helpers::Output
5
+
6
+ attr_reader :script, :coathooks
7
+
8
+ def initialize(script)
9
+ @script = Shellwords.shellsplit(script)
10
+ @coathooks = 0
11
+ end
12
+
13
+ def run
14
+ status =
15
+ Open4.popen4(*script) do |pid, _stdin, stdout, stderr|
16
+ # Handle `^C`.
17
+ trap('INT') { handle_sigint(pid) }
18
+
19
+ stdout_thread = Thread.new do
20
+ while (line = stdout.gets)
21
+ print_line(line)
22
+ end
23
+ end
24
+
25
+ stderr_thread = Thread.new do
26
+ while (line = stderr.gets)
27
+ print_stderr(line)
28
+ end
29
+ end
30
+
31
+ stdout_thread.join
32
+ stderr_thread.join
33
+ end
34
+
35
+ status.exitstatus
36
+ end
37
+
38
+ private
39
+
40
+ def handle_sigint(pid)
41
+ puts ''
42
+ if coathooks > 1
43
+ print_status 'Mina: SIGINT received again. Force quitting...'
44
+ Process.kill 'KILL', pid
45
+ else
46
+ print_status 'Mina: SIGINT received.'
47
+ Process.kill 'TERM', pid
48
+ end
49
+ @coathooks += 1
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ module Mina
2
+ class Runner
3
+ class Printer
4
+ include Mina::Helpers::Output
5
+
6
+ attr_reader :script
7
+
8
+ def initialize(script)
9
+ @script = script
10
+ end
11
+
12
+ def run
13
+ puts script
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module Mina
2
+ class Runner
3
+ class System
4
+ attr_reader :script
5
+
6
+ def initialize(script)
7
+ @script = script
8
+ end
9
+
10
+ def run
11
+ Kernel.system(script)
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/mina/version.rb CHANGED
@@ -1,5 +1,3 @@
1
1
  module Mina
2
- def self.version
3
- '0.3.8'
4
- end
2
+ VERSION = '1.0.0.beta1'.freeze
5
3
  end
data/mina.gemspec CHANGED
@@ -1,19 +1,30 @@
1
- require './lib/mina/version'
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
3
 
3
- Gem::Specification.new do |s|
4
- s.name = "mina"
5
- s.version = Mina.version
6
- s.summary = %{Really fast deployer and server automation tool.}
7
- s.description = %Q{Really fast deployer and server automation tool.}
8
- s.authors = ["Rico Sta. Cruz", "Michael Galero"]
9
- s.email = ["rico@nadarei.co", "mikong@nadarei.co"]
10
- s.homepage = "http://github.com/nadarei/mina"
11
- s.files = `git ls-files`.strip.split("\n")
12
- s.executables = Dir["bin/*"].map { |f| File.basename(f) }
13
- s.licenses = ['MIT']
4
+ tasks = File.expand_path('../tasks', __FILE__)
5
+ $LOAD_PATH.unshift(tasks) unless $LOAD_PATH.include?(tasks)
14
6
 
15
- s.add_dependency "rake"
16
- s.add_dependency "open4", "~> 1.3.4"
17
- s.add_development_dependency "rspec", "~> 3.0.0"
18
- s.add_development_dependency "pry", "~> 0.9.0"
7
+ require 'mina/version'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'mina'
11
+ spec.version = Mina::VERSION
12
+ spec.summary = 'Really fast deployer and server automation tool.'
13
+ spec.description = 'Really fast deployer and server automation tool.'
14
+ spec.authors = ['Stjepan Hadjić', 'Gabrijel Škoro', 'Rico Sta. Cruz', 'Michael Galero']
15
+ spec.email = [
16
+ 'stjepan.hadjic@infinum.co', 'gabrijel.skoro@infinum.co', 'rico@nadarei.co', 'mikong@nadarei.co'
17
+ ]
18
+ spec.homepage = 'https://github.com/mina-deploy/mina'
19
+ spec.files = `git ls-files`.strip.split("\n")
20
+ spec.executables = Dir['bin/*'].map { |f| File.basename(f) }
21
+ spec.licenses = ['MIT']
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'rake'
25
+ spec.add_dependency 'open4', '~> 1.3.4'
26
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
27
+ spec.add_development_dependency 'pry', '~> 0.9.0'
28
+ spec.add_development_dependency 'awesome_print'
29
+ spec.add_development_dependency 'codeclimate-test-reporter'
19
30
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mina::Application do
4
+ %w(quiet silent dry-run).each do |switch|
5
+ it "doesn't include --#{switch} in help" do
6
+ out, _err = capture_io do
7
+ flags '--help', '-h'
8
+ end
9
+ expect(out).not_to match(/--#{switch}/)
10
+ end
11
+ end
12
+
13
+ it 'runs adds two default tasks to the task list' do
14
+ expect(subject.top_level_tasks).to include(:debug_configuration_variables)
15
+ expect(subject.top_level_tasks).to include(:run_commands)
16
+ end
17
+
18
+ it 'overrides the rake method, but still prints the rake version' do
19
+ out, _err = capture_io do
20
+ flags '--version', '-V'
21
+ end
22
+ expect(out).to match(/\bMina, version\b/)
23
+ expect(out).to match(/\bv#{Mina::VERSION}\b/)
24
+ end
25
+
26
+ it 'enables simulation mode, and sets the backend Mina::Runner::Printer' do
27
+ capture_io do
28
+ flags '--simulate', '-s'
29
+ end
30
+ expect(Mina::Configuration.instance.fetch(:simulate)).to be true
31
+ end
32
+
33
+ it 'enables printing all config variables on command line parameter' do
34
+ capture_io do
35
+ flags '--debug-configuration-variables', '-d'
36
+ end
37
+ expect(Mina::Configuration.instance.fetch(:debug_configuration_variables)).to be true
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mina::Backend::Local do
4
+ let(:backend) { Mina::Backend::Local.new ['ls -al'] }
5
+ describe '#prepare' do
6
+ it 'escpaces shellwords' do
7
+ expect(backend.prepare).to eq("\\[\\\"ls\\ -al\\\"\\]")
8
+ end
9
+
10
+ it 'adds debug if simualte' do
11
+ Mina::Configuration.instance.set(:simulate, true)
12
+ expect(backend.prepare).to eq("#!/usr/bin/env bash\n# Executing the following:\n#\nls -al\n ")
13
+ Mina::Configuration.instance.remove(:simulate)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mina::Backend::Remote do
4
+ let(:backend) { Mina::Backend::Remote.new ['ls -al'] }
5
+ before { Mina::Configuration.instance.set(:domain, 'localhost') }
6
+
7
+ describe '#prepare' do
8
+ it 'escpaces shellwords' do
9
+ expect(backend.prepare).to eq("ssh localhost -tt -- \\[\\\"ls\\ -al\\\"\\]")
10
+ end
11
+
12
+ it 'adds debug if simualte' do
13
+ Mina::Configuration.instance.set(:simulate, true)
14
+ expect(backend.prepare).to eq("#!/usr/bin/env bash\n# Executing the following via 'ssh localhost -tt':\n#\nls -al\n ")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mina::Commands do
4
+ let(:commands) { Mina::Commands.new(:default) }
5
+
6
+ describe '#command' do
7
+ it 'adds a command to the queue' do
8
+ commands.command('ls -al')
9
+
10
+ expect(commands.queue[:default]).to include('ls -al')
11
+ end
12
+
13
+ it 'indents a command' do
14
+ commands.command('ls -al', indent: 4)
15
+
16
+ expect(commands.queue[:default]).to include(' ls -al')
17
+ end
18
+
19
+ context 'when verbose' do
20
+ before { Mina::Configuration.instance.set(:verbose, true) }
21
+
22
+ it 'adds a echo command to the queue' do
23
+ commands.command('ls -al')
24
+
25
+ expect(commands.queue[:default]).to include("echo \\$\\ ls\\ -al &&\nls -al")
26
+ end
27
+
28
+ it 'adds a silent command to the queue' do
29
+ commands.command('ls -al', quiet: true)
30
+
31
+ expect(commands.queue[:default]).to include('ls -al')
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#comment' do
37
+ it 'adds a comment to the queue' do
38
+ commands.comment('ls -al')
39
+
40
+ expect(commands.queue[:default]).to include("echo '-----> ls -al'")
41
+ end
42
+
43
+ it 'indents a comment' do
44
+ commands.comment('ls -al', indent: 4)
45
+
46
+ expect(commands.queue[:default]).to include(" echo '-----> ls -al'")
47
+ end
48
+ end
49
+
50
+ describe '#fetch' do
51
+ it 'returns a stage and deletes it from commands' do
52
+ commands.command('ls -al')
53
+
54
+ expect(commands.fetch(:default)).to include('ls -al')
55
+ expect(commands.queue[:default]).to be_empty
56
+ end
57
+ end
58
+
59
+ describe '#process' do
60
+ before do
61
+ commands.command('ls -al')
62
+ commands.command('pwd')
63
+ end
64
+
65
+ it 'joins all the commands' do
66
+ expect(commands.process).to eq("ls -al\npwd")
67
+ end
68
+
69
+ it 'joins all the commands within a path' do
70
+ expect(commands.process('some/path')).to eq('(cd some/path && ls -al && pwd)')
71
+ end
72
+
73
+ context 'when verbose' do
74
+ before { Mina::Configuration.instance.set(:verbose, true) }
75
+
76
+ it 'joins all the commands within a path and echoes it' do
77
+ expect(commands.process('some/path')).to eq("(cd some/path && echo '$ cd some/path' && ls -al && pwd)")
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#run' do
83
+ before do
84
+ runner = double(:runner)
85
+ allow(Mina::Runner).to receive(:new).and_return(runner)
86
+ allow(runner).to receive(:run).and_return(:ran)
87
+ end
88
+
89
+ it 'calls run on a backend' do
90
+ expect(commands.run(:local)).to eq(:ran)
91
+ end
92
+ end
93
+ end