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
data/lib/mina/rake.rb DELETED
@@ -1,10 +0,0 @@
1
- # This file is invoked from Rake.
2
- extend Mina::Helpers
3
- extend Mina::DeployHelpers
4
- extend Mina::SshHelpers
5
- extend Mina::LocalHelpers
6
- extend Mina::OutputHelpers
7
- extend Mina::ExecHelpers
8
-
9
- require 'mina/default'
10
- require 'mina/deploy' if Rake.application.have_rakefile
data/lib/mina/rbenv.rb DELETED
@@ -1,47 +0,0 @@
1
- # # Modules: rbenv
2
- # Adds settings and tasks for managing [rbenv] installations.
3
- #
4
- # [rbenv]: https://github.com/sstephenson/rbenv
5
- #
6
- # require 'mina/rbenv'
7
- #
8
- # ## Common usage
9
- #
10
- # task :environment do
11
- # invoke :'rbenv:load'
12
- # end
13
- #
14
- # task :deploy => :environment do
15
- # ...
16
- # end
17
-
18
- # ## Settings
19
- # Any and all of these settings can be overriden in your `deploy.rb`.
20
-
21
- # ### rbenv_path
22
- # Sets the path where *rbenv* is installed.
23
- #
24
- # You may override this if rbenv is placed elsewhere in your setup.
25
-
26
- set_default :rbenv_path, "$HOME/.rbenv"
27
-
28
- # ## Tasks
29
-
30
- # ### rbenv:load
31
- # Loads the *rbenv* runtime.
32
-
33
- task :'rbenv:load' do
34
- queue %{
35
- echo "-----> Loading rbenv"
36
- #{echo_cmd %{export RBENV_ROOT="#{rbenv_path}"}}
37
- #{echo_cmd %{export PATH="#{rbenv_path}/bin:$PATH"}}
38
-
39
- if ! which rbenv >/dev/null; then
40
- echo "! rbenv not found"
41
- echo "! If rbenv is installed, check your :rbenv_path setting."
42
- exit 1
43
- fi
44
-
45
- #{echo_cmd %{eval "$(rbenv init -)"}}
46
- }
47
- end
data/lib/mina/rvm.rb DELETED
@@ -1,88 +0,0 @@
1
- # # Modules: RVM
2
- # Adds settings and tasks for managing [RVM] installations.
3
- #
4
- # [rvm]: http://rvm.io
5
- #
6
- # require 'mina/rvm'
7
- #
8
- # ## Common usage
9
- #
10
- # task :environment do
11
- # invoke :'rvm:use[ruby-1.9.3-p125@gemset_name]'
12
- # end
13
- #
14
- # task :deploy => :environment do
15
- # ...
16
- # end
17
-
18
- # ## Settings
19
- # Any and all of these settings can be overriden in your `deploy.rb`.
20
-
21
- # ### rvm_path
22
- # Sets the path to RVM.
23
- #
24
- # You can override this in your projects if RVM is installed in a different
25
- # path, say, if you have a system-wide RVM install.
26
-
27
- set_default :rvm_path, "$HOME/.rvm/scripts/rvm"
28
-
29
- # ## Tasks
30
-
31
- # ### rvm:use[]
32
- # Uses a given RVM environment provided as an argument.
33
- #
34
- # This is usually placed in the `:environment` task.
35
- #
36
- # task :environment do
37
- # invoke :'rvm:use[ruby-1.9.3-p125@gemset_name]'
38
- # end
39
- #
40
- task :'rvm:use', :env do |t, args|
41
- unless args[:env]
42
- print_error "Task 'rvm:use' needs an RVM environment name as an argument."
43
- print_error "Example: invoke :'rvm:use[ruby-1.9.2@default]'"
44
- die
45
- end
46
-
47
- queue %{
48
- echo "-----> Using RVM environment '#{args[:env]}'"
49
- if [[ ! -s "#{rvm_path}" ]]; then
50
- echo "! Ruby Version Manager not found"
51
- echo "! If RVM is installed, check your :rvm_path setting."
52
- exit 1
53
- fi
54
-
55
- source #{rvm_path}
56
- #{echo_cmd %{rvm use "#{args[:env]}" --create}} || exit 1
57
- }
58
- end
59
-
60
- # ### rvm:wrapper[]
61
- # Creates a rvm wrapper for a given executable.
62
- #
63
- # This is usually placed in the `:setup` task.
64
- #
65
- # task ::setup => :environment do
66
- # ...
67
- # invoke :'rvm:wrapper[ruby-1.9.3-p125@gemset_name,wrapper_name,binary_name]'
68
- # end
69
- #
70
- task :'rvm:wrapper', :env, :name, :bin do |t,args|
71
- unless args[:env] && args[:name] && args[:bin]
72
- print_error "Task 'rvm:wrapper' needs an RVM environment name, an wrapper name and the binary name as arguments"
73
- print_error "Example: invoke :'rvm:wrapper[ruby-1.9.2@myapp,myapp,unicorn_rails]'"
74
- die
75
- end
76
-
77
- queue %{
78
- echo "-----> creating RVM wrapper '#{args[:name]}_#{args[:bin]}' using '#{args[:env]}'"
79
- if [[ ! -s "#{rvm_path}" ]]; then
80
- echo "! Ruby Version Manager not found"
81
- echo "! If RVM is installed, check your :rvm_path setting."
82
- exit 1
83
- fi
84
-
85
- source #{rvm_path}
86
- #{echo_cmd %{rvm wrapper #{args[:env]} #{args[:name]} #{args[:bin]} }} || exit 1
87
- }
88
- end
data/lib/mina/ry.rb DELETED
@@ -1,55 +0,0 @@
1
- # # Modules: ry
2
- # Adds settings and tasks for managing [ry] installations.
3
- #
4
- # [ry]: https://github.com/jneen/ry
5
- #
6
- # require 'mina/ry'
7
- #
8
- # ## Common usage
9
- #
10
- # task :environment do
11
- # invoke :'ry[ruby-1.9.3-p392]'
12
- # # or without parameter to use default ruby version
13
- # invoke :'ry'
14
- # end
15
- #
16
- # task :deploy => :environment do
17
- # ...
18
- # end
19
-
20
- # ## Settings
21
- # Any and all of these settings can be overriden in your `deploy.rb`.
22
-
23
- # ### ry_path
24
- # Path where *ry* init scripts are installed.
25
- #
26
- set_default :ry_path, "$HOME/.local"
27
-
28
- # ## Tasks
29
-
30
- # ### ry[version]
31
- # Switch to given Ruby version
32
-
33
- task :ry, :env do |t, args|
34
- unless args[:env]
35
- print_status "Task 'ry' without argument will use default Ruby version."
36
- end
37
-
38
- queue %{
39
- echo "-----> ry to version: '#{args[:env] || '**not specified**'}'"
40
-
41
- echo "-----> Loading ry"
42
- if [[ ! -e "#{ry_path}/bin" ]]; then
43
- echo "! ry not found"
44
- echo "! If ry is installed, check your :ry_path setting."
45
- exit 1
46
- fi
47
- #{echo_cmd %{export PATH="#{ry_path}/bin:$PATH"}}
48
- #{echo_cmd %{eval "$(ry setup)"}}
49
-
50
- RY_RUBY="#{args[:env]}"
51
- if [ -n "$RY_RUBY" ]; then
52
- #{echo_cmd %{ry use $RY_RUBY}} || exit 1
53
- fi
54
- }
55
- end
data/lib/mina/settings.rb DELETED
@@ -1,32 +0,0 @@
1
- module Mina
2
- class Settings < Hash
3
- def method_missing(meth, *args, &blk)
4
- name = meth.to_s
5
-
6
- return evaluate(self[meth]) if name.size == 1
7
-
8
- # Ruby 1.8.7 doesn't let you do string[-1]
9
- key, suffix = name[0..-2].to_sym, name[-1..-1]
10
-
11
- case suffix
12
- when '='
13
- self[key] = args.first
14
- when '?'
15
- include? key
16
- when '!'
17
- raise Error, "Setting :#{key} is not set" unless include?(key)
18
- evaluate self[key]
19
- else
20
- evaluate self[meth]
21
- end
22
- end
23
-
24
- def evaluate(value)
25
- if value.is_a?(Proc)
26
- value.call
27
- else
28
- value
29
- end
30
- end
31
- end
32
- end
@@ -1,125 +0,0 @@
1
- # # Helpers: SSH helpers
2
- # You don't need to invoke these helpers, they're already invoked automatically.
3
-
4
- module Mina
5
- module SshHelpers
6
-
7
- # ### ssh
8
- # Executes a command via SSH.
9
- #
10
- # Returns nothing usually, but if `{ return: true }` is given, returns the
11
- # STDOUT output of the SSH session.
12
- #
13
- # `options` is a hash of options:
14
- #
15
- # - `:pretty` - Prettify the output if true.
16
- # - `:return` - If set to true, returns the output.
17
- #
18
- # Example
19
- #
20
- # ssh("ls", return: true)
21
-
22
- def ssh(cmd, options={})
23
- require 'shellwords'
24
-
25
- cmd.unshift("export #{env_vars}") if env_vars?
26
- cmd = cmd.join("\n") if cmd.is_a?(Array)
27
- script = Shellwords.escape(cmd)
28
-
29
- if options[:return] == true
30
- `#{ssh_command} -- #{script}`
31
-
32
- elsif simulate_mode?
33
- Ssh.simulate(cmd, ssh_command)
34
-
35
- else
36
- result = Ssh.invoke(script, self)
37
- Ssh.ensure_successful result, self
38
- end
39
- end
40
-
41
- # ### ssh_command
42
- # Returns the SSH command to be executed.
43
- #
44
- # set :domain, 'foo.com'
45
- # set :user, 'diggity'
46
- #
47
- # puts ssh_command
48
- # #=> 'ssh diggity@foo.com'
49
-
50
- def ssh_command
51
- args = domain!.dup
52
- args = "#{user}@#{args}" if user?
53
- args << " -i #{identity_file}" if identity_file?
54
- args << " -p #{port}" if port?
55
- args << " -A" if forward_agent?
56
- args << " #{ssh_options}" if ssh_options?
57
- args << " -o StrictHostKeyChecking=no"
58
- args << " -t"
59
- "ssh #{args}"
60
- end
61
-
62
- # ## Private methods
63
- # `ssh` delegates to these.
64
-
65
- module Ssh
66
-
67
- extend self
68
-
69
- # ### Ssh.simulate
70
- # __Internal:__ Prints SSH command. Called by `ssh`.
71
-
72
- def simulate(cmd, ssh_command)
73
- str = "Executing the following via '#{ssh_command}':"
74
- puts "#!/usr/bin/env bash"
75
- puts "# #{str}"
76
- puts "#"
77
-
78
- puts cmd
79
-
80
- 0
81
- end
82
-
83
- # ### Ssh.invoke
84
- # __Internal:__ Initiates an SSH session with script `script` with given
85
- # `term_mode`. Called by `ssh`.
86
-
87
- def invoke(script, this)
88
- # Ruby 1.8.7 doesn't let you have empty symbols
89
- term_mode = :"#{this.settings.term_mode}" if this.settings.term_mode
90
- code = "#{this.ssh_command} -- #{script}"
91
-
92
- # Certain environments can't do :pretty mode.
93
- term_mode = :exec if term_mode == :pretty && !pretty_supported?
94
-
95
- case term_mode
96
- when :pretty
97
- this.pretty_system(code)
98
- when :exec
99
- exec code
100
- else
101
- system code
102
- $?.to_i
103
- end
104
- end
105
-
106
- def pretty_supported?
107
- # open4 is not supported under Windows.
108
- # https://github.com/nadarei/mina/issues/58
109
- require 'rbconfig'
110
- ! (RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
111
- end
112
-
113
- # ### Ssh.ensure_successful
114
- # __Internal:__ Halts the execution if the given result code is not
115
- # successful (non-zero).
116
-
117
- def ensure_successful(result, this)
118
- this.die result if result.is_a?(Fixnum) && result > 0
119
- result
120
- end
121
-
122
- end
123
-
124
- end
125
- end
data/lib/mina/tools.rb DELETED
@@ -1,20 +0,0 @@
1
- module Mina
2
- module Tools
3
- if IO.respond_to?(:popen4)
4
- def self.popen4(*cmd, &blk)
5
- IO.popen4 *cmd, &blk
6
- $?
7
- end
8
- else
9
- def self.popen4(*cmd, &blk)
10
- require 'open4'
11
- Open4.popen4 *cmd, &blk
12
- end
13
- end
14
-
15
- def self.pfork4(*cmd, &blk)
16
- require 'open4'
17
- Open4.pfork4 *cmd, &blk
18
- end
19
- end
20
- end
data/lib/mina/whenever.rb DELETED
@@ -1,51 +0,0 @@
1
- # # Modules: Whenever
2
- # Adds settings and tasks for managing projects with [whenever].
3
- #
4
- # [whenever]: http://rubygems.org/gems/whenever
5
- #
6
- #
7
- # ## Common usage
8
- # require 'mina/whenever'
9
- #
10
- # task :deploy => :environment do
11
- # deploy do
12
- # ...
13
- # to :launch do
14
- # invoke :'whenever:update'
15
- # end
16
- # end
17
-
18
- # ## Settings
19
- # Any and all of these settings can be overriden in your `deploy.rb`.
20
-
21
- # ### whenever_name
22
- # Override the default name used by Whenever when clearing,
23
- # updating or writing the crontab file.
24
-
25
- namespace :whenever do
26
- # NOTE: setting this as a lambda to allow the user to override
27
- # the domain variable at any time in their schedule.rb file
28
- name = lambda { whenever_name || "#{domain}_#{rails_env}" }
29
-
30
- desc "Clear crontab"
31
- task :clear => :environment do
32
- queue %{
33
- echo "-----> Clear crontab for #{name.call}"
34
- #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --clear-crontab #{name.call} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']}
35
- }
36
- end
37
- desc "Update crontab"
38
- task :update => :environment do
39
- queue %{
40
- echo "-----> Update crontab for #{name.call}"
41
- #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --update-crontab #{name.call} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']}
42
- }
43
- end
44
- desc "Write crontab"
45
- task :write => :environment do
46
- queue %{
47
- echo "-----> Update crontab for #{name.call}"
48
- #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --write-crontab #{name.call} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']}
49
- }
50
- end
51
- end
data/manual/index.md DELETED
@@ -1,15 +0,0 @@
1
- # Welcome to Mina
2
-
3
- Really fast deployer and server automation tool.
4
-
5
- Mina works really fast because it's a deploy Bash script generator. It
6
- generates an entire procedure as a Bash script and runs it remotely in the
7
- server.
8
-
9
- Compare this to the likes of Vlad or Capistrano, where each command
10
- is ran separately on their own SSH sessions. Mina only creates *one* SSH
11
- session per deploy, minimizing the SSH connection overhead.
12
-
13
- $ gem install mina
14
- $ mina
15
-