mina 1.0.0.beta2 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +384 -0
  3. data/Readme.md +3 -3
  4. data/data/deploy.rb +8 -6
  5. data/data/deploy.sh.erb +1 -1
  6. data/docs/3rd_party_plugins.md +2 -0
  7. data/docs/getting_started.md +22 -0
  8. data/docs/migrating.md +1 -1
  9. data/lib/mina.rb +3 -3
  10. data/lib/mina/application.rb +1 -0
  11. data/lib/mina/backend/remote.rb +6 -6
  12. data/lib/mina/commands.rb +4 -3
  13. data/lib/mina/configuration.rb +2 -1
  14. data/lib/mina/dsl.rb +8 -1
  15. data/lib/mina/helpers/internal.rb +8 -3
  16. data/lib/mina/helpers/output.rb +4 -0
  17. data/lib/mina/runner/pretty.rb +1 -1
  18. data/lib/mina/runner/printer.rb +1 -0
  19. data/lib/mina/version.rb +1 -1
  20. data/mina.gemspec +1 -1
  21. data/spec/lib/mina/application_spec.rb +35 -35
  22. data/spec/lib/mina/backend/local_spec.rb +1 -0
  23. data/spec/lib/mina/backend/remote_spec.rb +2 -0
  24. data/spec/lib/mina/commands_spec.rb +6 -7
  25. data/spec/lib/mina/configuration_spec.rb +1 -1
  26. data/spec/lib/mina/helpers/internal_spec.rb +3 -1
  27. data/spec/lib/mina/helpers/output_spec.rb +5 -20
  28. data/spec/lib/mina/runner_spec.rb +1 -4
  29. data/spec/spec_helper.rb +14 -3
  30. data/spec/support/outputs/bundle_clean.txt +2 -0
  31. data/spec/support/outputs/bundle_install.txt +2 -0
  32. data/spec/support/outputs/chruby.txt +9 -0
  33. data/spec/support/outputs/console.txt +1 -0
  34. data/spec/support/outputs/deploy_cleanup.txt +2 -0
  35. data/spec/support/outputs/deploy_force_unlock.txt +2 -0
  36. data/spec/support/outputs/deploy_link_shared_paths.txt +13 -0
  37. data/spec/support/outputs/git_clone.txt +1 -0
  38. data/spec/support/outputs/git_clone_commit.txt +1 -0
  39. data/spec/support/outputs/git_revision.txt +1 -0
  40. data/spec/support/outputs/log.txt +1 -0
  41. data/spec/support/outputs/rails_assets_precompile.txt +1 -0
  42. data/spec/support/outputs/rails_db_create.txt +2 -0
  43. data/spec/support/outputs/rails_db_migrate.txt +1 -0
  44. data/spec/support/outputs/rails_db_rollback.txt +2 -0
  45. data/spec/support/outputs/rbenv_load.txt +1 -0
  46. data/spec/support/outputs/rollback.txt +2 -0
  47. data/spec/support/outputs/run.txt +1 -0
  48. data/spec/support/outputs/rvm_use.txt +1 -0
  49. data/spec/support/outputs/ry.txt +15 -0
  50. data/spec/support/outputs/setup.txt +14 -0
  51. data/spec/support/outputs/ssh_keyscan.txt +3 -0
  52. data/spec/support/rake_example_group.rb +30 -0
  53. data/spec/tasks/bundler_spec.rb +15 -0
  54. data/spec/tasks/default_spec.rb +35 -0
  55. data/spec/tasks/deploy_spec.rb +33 -0
  56. data/spec/tasks/git_spec.rb +21 -0
  57. data/spec/tasks/init_spec.rb +16 -0
  58. data/spec/tasks/rails_spec.rb +45 -0
  59. data/spec/tasks/ruby_managers_spec.rb +33 -0
  60. data/tasks/mina/bundler.rb +5 -5
  61. data/tasks/mina/chruby.rb +8 -10
  62. data/tasks/mina/default.rb +5 -1
  63. data/tasks/mina/deploy.rb +33 -29
  64. data/tasks/mina/git.rb +20 -8
  65. data/tasks/mina/install.rb +1 -0
  66. data/tasks/mina/rails.rb +15 -15
  67. data/tasks/mina/rbenv.rb +6 -8
  68. data/tasks/mina/rvm.rb +16 -20
  69. data/tasks/mina/ry.rb +10 -14
  70. data/test_env/config/deploy.rb +5 -5
  71. metadata +35 -6
  72. data/spec/lib/mina_spec.rb +0 -7
  73. data/spec/support/run_helper.rb +0 -36
data/data/deploy.sh.erb CHANGED
@@ -32,7 +32,7 @@ fi
32
32
 
33
33
  # Determine $previous_path and other variables
34
34
  [ -h "<%= fetch(:current_path) %>" ] && [ -d "<%= fetch(:current_path) %>" ] && previous_path=$(cd "<%= fetch(:current_path) %>" >/dev/null && pwd -LP)
35
- build_path="./tmp/build-`date +%s`$RANDOM"
35
+ build_path="./tmp/build-$(date +%s)$RANDOM"
36
36
 
37
37
  version="<%= next_version %>"
38
38
  release_path="<%= fetch(:releases_path) %>/$version"
@@ -1,6 +1,8 @@
1
1
  3rd party modules
2
2
  ------
3
3
 
4
+ **Many are not updated to mina 1.x**
5
+
4
6
  * [mina-blue_green](https://github.com/reedlaw/mina-blue_green)
5
7
  * [mina-cakephp](https://github.com/mobvox/mina-cakephp)
6
8
  * [mina-clockwork](https://github.com/907th/mina-clockwork)
@@ -30,6 +30,28 @@ set :domain, 'your.server.com'
30
30
  set :deploy_to, '/var/www/flipstack.com'
31
31
  ...
32
32
  ```
33
+ **Notes:** You may be using a ruby versioning tool (rbenv or RVM) to manage ruby and gems. If you are using one of them, don't forget to uncomment these settings:
34
+ ```
35
+ ...
36
+ require 'mina/bundler'
37
+ require 'mina/rails'
38
+ require 'mina/git'
39
+ # require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
40
+ # require 'mina/rvm' # for rvm support. (http://rvm.io)
41
+ ...
42
+ ```
43
+ ``` ruby
44
+ ...
45
+ task :environment do
46
+ # If you're using rbenv, use this to load the rbenv environment.
47
+ # Be sure to commit your .ruby-version or .rbenv-version to your repository.
48
+ # invoke :'rbenv:load'
49
+
50
+ # For those using RVM, use this to load an RVM version@gemset.
51
+ # invoke :'rvm:use', 'ruby-1.9.3-p125@default'
52
+ end
53
+ ...
54
+ ```
33
55
 
34
56
  ### Step 2: Run 'mina setup'
35
57
 
data/docs/migrating.md CHANGED
@@ -9,7 +9,7 @@ Migrating from 0.3.x to 1.0
9
9
  * `in_directory` -> `in_path` # wraps commands to be run in specified path
10
10
 
11
11
  ## new
12
- * `run` # runs commands on a specified backend
12
+ * `run` # runs commands on a specified backend, this has replaced old before and after hooks
13
13
  * `comment` # adds a 'echo -----> #{command}' to queue
14
14
 
15
15
  **Other commands have been removed!**
data/lib/mina.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rake'
2
2
  Rake.application.options.trace = true
3
3
 
4
- # require 'pry'
4
+ require 'pry'
5
5
  # require 'awesome_print'
6
6
 
7
7
  require 'forwardable'
@@ -10,10 +10,10 @@ require 'singleton'
10
10
  require 'open4'
11
11
 
12
12
  require 'mina/version'
13
- require 'mina/configuration'
14
- require 'mina/dsl'
15
13
  require 'mina/helpers/output'
16
14
  require 'mina/helpers/internal'
15
+ require 'mina/configuration'
16
+ require 'mina/dsl'
17
17
  require 'mina/commands'
18
18
  require 'mina/runner'
19
19
  require 'mina/runner/pretty'
@@ -26,6 +26,7 @@ module Mina
26
26
  end
27
27
 
28
28
  def top_level_tasks
29
+ return @top_level_tasks if @top_level_tasks.include?('init')
29
30
  @top_level_tasks << :debug_configuration_variables
30
31
  @top_level_tasks << :run_commands
31
32
  end
@@ -21,14 +21,14 @@ module Mina
21
21
  end
22
22
 
23
23
  def ssh
24
- fail 'No domain set' unless set?(:domain)
24
+ ensure!(:domain)
25
25
  args = fetch(:domain)
26
26
  args = "#{fetch(:user)}@#{fetch(:domain)}" if set?(:user)
27
- args << " -i #{fetch(:identity_file)}" if set?(:identity_file)
28
- args << " -p #{fetch(:port)}" if set?(:port)
29
- args << ' -A' if set?(:forward_agent)
30
- args << " #{fetch(:ssh_options)}" if set?(:ssh_options)
31
- args << ' -tt'
27
+ args += " -i #{fetch(:identity_file)}" if set?(:identity_file)
28
+ args += " -p #{fetch(:port)}" if set?(:port)
29
+ args += ' -A' if set?(:forward_agent)
30
+ args += " #{fetch(:ssh_options)}" if set?(:ssh_options)
31
+ args += ' -tt'
32
32
  "ssh #{args}"
33
33
  end
34
34
 
data/lib/mina/commands.rb CHANGED
@@ -31,8 +31,8 @@ module Mina
31
31
 
32
32
  def process(path = nil)
33
33
  if path
34
- queue[stage].unshift("echo '$ cd #{path}'") if fetch(:verbose)
35
- "(cd #{path} && #{queue[stage].join(' && ')})"
34
+ queue[stage].unshift(%(echo "$ cd #{path}")) if fetch(:verbose)
35
+ %((cd #{path} && #{queue[stage].join(' && ')}))
36
36
  else
37
37
  queue[stage].join("\n")
38
38
  end
@@ -40,7 +40,8 @@ module Mina
40
40
 
41
41
  def run(backend)
42
42
  report_time do
43
- Mina::Runner.new(process, backend).run
43
+ status = Mina::Runner.new(process, backend).run
44
+ error! 'Run Error' unless status
44
45
  end
45
46
  end
46
47
  end
@@ -1,6 +1,7 @@
1
1
  module Mina
2
2
  class Configuration
3
3
  include Singleton
4
+ include Helpers::Internal
4
5
 
5
6
  module DSL
6
7
  def self.included(base)
@@ -36,7 +37,7 @@ module Mina
36
37
  end
37
38
 
38
39
  def ensure!(key)
39
- fail "#{key} must be defined!" unless set?(key)
40
+ error! "#{key} must be defined!" unless set?(key)
40
41
  end
41
42
 
42
43
  def reset!
data/lib/mina/dsl.rb CHANGED
@@ -19,10 +19,15 @@ module Mina
19
19
  @commands ||= Commands.new
20
20
  end
21
21
 
22
+ def reset!
23
+ @commands = Commands.new
24
+ end
25
+
22
26
  def run(backend)
23
27
  @commands = Commands.new
24
28
  yield
25
29
  commands.run(backend)
30
+ @commands = Commands.new
26
31
  end
27
32
 
28
33
  def on(stage)
@@ -40,7 +45,9 @@ module Mina
40
45
  end
41
46
 
42
47
  def deploy(&block)
43
- command deploy_script(&block), quiet: true
48
+ run :remote do
49
+ command deploy_script(&block), quiet: true
50
+ end
44
51
  end
45
52
  end
46
53
  end
@@ -1,7 +1,7 @@
1
1
  module Mina
2
2
  module Helpers
3
3
  module Internal
4
- extend Configuration::DSL
4
+ include Helpers::Output
5
5
 
6
6
  def deploy_script
7
7
  yield
@@ -29,7 +29,7 @@ module Mina
29
29
  def report_time
30
30
  time_start = Time.now
31
31
  output = yield
32
- puts "Elapsed time: %.2f seconds" % [Time.now - time_start]
32
+ print_info "Elapsed time: %.2f seconds" % [Time.now - time_start]
33
33
  output
34
34
  end
35
35
 
@@ -40,9 +40,14 @@ module Mina
40
40
  when :sequence
41
41
  "$((`ls -1 #{fetch(:releases_path)} | sort -n | tail -n 1`+1))"
42
42
  else
43
- fail 'Unrecognizes version scheme. Use :datetime or :sequence'
43
+ error! 'Unrecognizes version scheme. Use :datetime or :sequence'
44
44
  end
45
45
  end
46
+
47
+ def error!(message)
48
+ print_error message
49
+ exit 1
50
+ end
46
51
  end
47
52
  end
48
53
  end
@@ -30,6 +30,10 @@ module Mina
30
30
  puts " #{color('$', 36)} #{color(msg, 36)}"
31
31
  end
32
32
 
33
+ def print_info(msg)
34
+ puts " #{color(msg, 96)}"
35
+ end
36
+
33
37
  def print_stdout(msg)
34
38
  puts " #{msg}"
35
39
  end
@@ -32,7 +32,7 @@ module Mina
32
32
  stderr_thread.join
33
33
  end
34
34
 
35
- status.exitstatus
35
+ status.exitstatus == 0
36
36
  end
37
37
 
38
38
  private
@@ -11,6 +11,7 @@ module Mina
11
11
 
12
12
  def run
13
13
  puts script
14
+ true
14
15
  end
15
16
  end
16
17
  end
data/lib/mina/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mina
2
- VERSION = '1.0.0.beta2'.freeze
2
+ VERSION = '1.0.0.beta3'.freeze
3
3
  end
data/mina.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency 'rake'
25
25
  spec.add_dependency 'open4', '~> 1.3.4'
26
- spec.add_development_dependency 'rspec', '~> 3.0.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.5.0'
27
27
  spec.add_development_dependency 'pry-byebug'
28
28
  spec.add_development_dependency 'awesome_print'
29
29
  spec.add_development_dependency 'codeclimate-test-reporter'
@@ -1,39 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
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
4
+ # let(:app) { Rake.application }
5
+ #
6
+ # %w(quiet silent dry-run).each do |switch|
7
+ # it "doesn't include --#{switch} in help" do
8
+ # binding.pry
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 = 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
39
  end
@@ -4,6 +4,7 @@ describe Mina::Backend::Local do
4
4
  let(:backend) { Mina::Backend::Local.new ['ls -al'] }
5
5
  describe '#prepare' do
6
6
  it 'escpaces shellwords' do
7
+ Mina::Configuration.instance.remove(:simulate)
7
8
  expect(backend.prepare).to eq("\\[\\\"ls\\ -al\\\"\\]")
8
9
  end
9
10
 
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Mina::Backend::Remote do
4
4
  let(:backend) { Mina::Backend::Remote.new ['ls -al'] }
5
5
  before { Mina::Configuration.instance.set(:domain, 'localhost') }
6
+ after { Mina::Configuration.instance.remove(:domain) }
6
7
 
7
8
  describe '#prepare' do
8
9
  it 'escpaces shellwords' do
@@ -12,6 +13,7 @@ describe Mina::Backend::Remote do
12
13
  it 'adds debug if simualte' do
13
14
  Mina::Configuration.instance.set(:simulate, true)
14
15
  expect(backend.prepare).to eq("#!/usr/bin/env bash\n# Executing the following via 'ssh localhost -tt':\n#\nls -al\n ")
16
+ Mina::Configuration.instance.remove(:simulate)
15
17
  end
16
18
  end
17
19
  end
@@ -18,6 +18,7 @@ describe Mina::Commands do
18
18
 
19
19
  context 'when verbose' do
20
20
  before { Mina::Configuration.instance.set(:verbose, true) }
21
+ after { Mina::Configuration.instance.remove(:verbose) }
21
22
 
22
23
  it 'adds a echo command to the queue' do
23
24
  commands.command('ls -al')
@@ -72,22 +73,20 @@ describe Mina::Commands do
72
73
 
73
74
  context 'when verbose' do
74
75
  before { Mina::Configuration.instance.set(:verbose, true) }
76
+ after { Mina::Configuration.instance.remove(:verbose) }
75
77
 
76
78
  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)")
79
+ expect(commands.process('some/path')).to eq("(cd some/path && echo \"$ cd some/path\" && ls -al && pwd)")
78
80
  end
79
81
  end
80
82
  end
81
83
 
82
84
  describe '#run' do
83
- before do
85
+ it 'calls run on a backend' do
84
86
  runner = double(:runner)
85
87
  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)
88
+ expect(runner).to receive(:run).and_return(true)
89
+ commands.run(:local)
91
90
  end
92
91
  end
93
92
  end
@@ -46,7 +46,7 @@ describe Mina::Configuration do
46
46
  end
47
47
 
48
48
  it 'raises an error if key is not set' do
49
- expect { config.ensure!(:key) }.to raise_error(StandardError)
49
+ expect { config.ensure!(:key) }.to raise_error(SystemExit)
50
50
  end
51
51
  end
52
52
 
@@ -21,7 +21,8 @@ describe Mina::Helpers::Internal do
21
21
 
22
22
  describe '#erb' do
23
23
  before { Mina::Configuration.instance.set(:version_scheme, :sequence) }
24
-
24
+ after { Mina::Configuration.instance.remove(:version_scheme) }
25
+
25
26
  it 'returns whole script' do
26
27
  expect(helper.erb('data/deploy.sh.erb')).to_not be_empty
27
28
  end
@@ -36,6 +37,7 @@ describe Mina::Helpers::Internal do
36
37
 
37
38
  context 'when verbose' do
38
39
  before { Mina::Configuration.instance.set(:verbose, true) }
40
+ after { Mina::Configuration.instance.remove(:verbose) }
39
41
 
40
42
  it 'modifies code' do
41
43
  expect(helper.echo_cmd('ls -al')).to eq("echo \\$\\ ls\\ -al &&\nls -al")
@@ -9,40 +9,25 @@ describe Mina::Helpers::Output do
9
9
 
10
10
  describe '#print_line' do
11
11
  it 'prints normally' do
12
- out, _err = capture_io do
13
- helper.print_line('ls -al')
14
- end
15
- expect(out).to eq(" ls -al\n")
12
+ expect{ helper.print_line('ls -al') }.to output(" ls -al\n").to_stdout
16
13
  end
17
14
 
18
15
  it 'prints comment' do
19
- out, _err = capture_io do
20
- helper.print_line('-> ls -al')
21
- end
22
- expect(out).to eq("\e[32m----->\e[0m ls -al\n")
16
+ expect{ helper.print_line('-> ls -al') }.to output("\e[32m----->\e[0m ls -al\n").to_stdout
23
17
  end
24
18
 
25
19
  it 'prints error' do
26
- out, _err = capture_io do
27
- helper.print_line('! ls -al')
28
- end
29
- expect(out).to eq(" \e[33m!\e[0m \e[31mls -al\e[0m\n")
20
+ expect{ helper.print_line('! ls -al') }.to output(" \e[33m!\e[0m \e[31mls -al\e[0m\n").to_stdout
30
21
  end
31
22
 
32
23
  it 'prints command' do
33
- out, _err = capture_io do
34
- helper.print_line('$ ls -al')
35
- end
36
- expect(out).to eq(" \e[36m$\e[0m \e[36mls -al\e[0m\n")
24
+ expect{ helper.print_line('$ ls -al') }.to output(" \e[36m$\e[0m \e[36mls -al\e[0m\n").to_stdout
37
25
  end
38
26
  end
39
27
 
40
28
  describe '#print_stderr' do
41
29
  it 'prints stderr' do
42
- out, _err = capture_io do
43
- helper.print_stderr('ls -al')
44
- end
45
- expect(out).to eq(" \e[31mls -al\e[0m\n")
30
+ expect{ helper.print_stderr('ls -al') }.to output(" \e[31mls -al\e[0m\n").to_stdout
46
31
  end
47
32
  end
48
33
  end