colorful-mina 0.3.1

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.
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,95 @@
1
+ # # Helpers: Output helpers
2
+ # Protip! make a module that overrides these settings, then use `extend YourModule`
3
+ # to make your own pretty printing thing.
4
+ module Mina
5
+ module OutputHelpers
6
+
7
+ # ### print_str
8
+ # Prints a string by delegating it to the proper output helper.
9
+ #
10
+ # It takes an input with text and prints them nicely. The text block can
11
+ # have statuses (prefixed with `-----> `), errors (prefixed with `! `),
12
+ # commands (prefixed with `$ `) or anything else. Depending on the type of
13
+ # the message, they will be delegated to the proper print_* helper.
14
+ #
15
+ # -----> Unlocking
16
+ # $ unlock foo
17
+ # Unlocked.
18
+ # ! ERROR: Failed
19
+ #
20
+ # Returns nothing.
21
+ #
22
+ def print_str(line)
23
+ if line =~ /^\-+> (.*?)$/
24
+ print_status $1
25
+ elsif line =~ /^! (.*?)$/
26
+ print_error $1
27
+ elsif line =~ /^\$ (.*?)$/
28
+ print_command $1
29
+ else
30
+ print_stdout line
31
+ end
32
+ end
33
+
34
+ # ### print_char
35
+ # Prints a single character.
36
+ def print_char(ch)
37
+ $last ||= ''
38
+
39
+ if ch == "\n"
40
+ print_clear
41
+ print_str $last
42
+ $last = ''
43
+ else
44
+ print ' ' if $last == ''
45
+ print ch
46
+ $last += ch
47
+ end
48
+ end
49
+
50
+ def print_clear
51
+ print "\033[1K\r"
52
+ end
53
+
54
+ # ### print_status
55
+ # Prints a status message. (`----->`)
56
+ def print_status(msg)
57
+ puts color(("-----> " + msg), 32)
58
+ end
59
+
60
+ # ### print_error
61
+ # Prints an error message (header).
62
+ def print_error(msg)
63
+ puts " #{color("!", 33)} #{color(msg, 31)}"
64
+ end
65
+
66
+ # ### print_stderr
67
+ # Prints an error message (body), or prints stderr output.
68
+ def print_stderr(msg)
69
+ puts " #{color(msg, 31)}"
70
+ end
71
+
72
+ # ### print_command
73
+ # Prints a command.
74
+ def print_command(msg)
75
+ puts " #{color("$", 32)} #{color(msg, 32)}"
76
+ end
77
+
78
+ # ### print_stdout
79
+ # Prints a normal message.
80
+ def print_stdout(msg)
81
+ puts " #{msg}"
82
+ end
83
+
84
+ # ### color
85
+ # Colorizes a string.
86
+ # Returns the string `str` with the color `c`.
87
+ def color(str, c)
88
+ ENV['NO_COLOR'] ? str : "\033[#{c}m#{str}\033[0m"
89
+ end
90
+
91
+ def puts(msg)
92
+ %[echo "#{msg}"]
93
+ end
94
+ end
95
+ end
data/lib/mina/rails.rb ADDED
@@ -0,0 +1,206 @@
1
+ # # Modules: Rails
2
+ # Adds settings and tasks for managing Rails projects.
3
+ #
4
+ # require 'mina/rails'
5
+
6
+ require 'mina/bundler'
7
+
8
+ # ## Settings
9
+ # Any and all of these settings can be overriden in your `deploy.rb`.
10
+
11
+ # ### rails_env
12
+ # Sets the Rails environment for `rake` and `rails` commands.
13
+ #
14
+ # Note that changing this will NOT change the environment that your application
15
+ # is run in.
16
+
17
+ set_default :rails_env, 'production'
18
+
19
+ # ### bundle_prefix
20
+ # Prefix for Bundler commands. Often to something like `RAILS_ENV=production
21
+ # bundle exec`.
22
+ #
23
+ # queue! "#{bundle_prefix} annotate -r"
24
+
25
+ set_default :bundle_prefix, lambda { %{RAILS_ENV="#{rails_env}" #{bundle_bin} exec} }
26
+
27
+ # ### rake
28
+ # The prefix for `rake` commands. Use like so:
29
+ #
30
+ # queue! "#{rake} db:migrate"
31
+
32
+ set_default :rake, lambda { %{#{bundle_prefix} rake} }
33
+
34
+ # ### rails
35
+ # The prefix for `rails` commands. Use like so:
36
+ #
37
+ # queue! "#{rails} console"
38
+
39
+ set_default :rails, lambda { %{#{bundle_prefix} rails} }
40
+
41
+ # ### asset_paths
42
+ # The paths to be checked.
43
+ #
44
+ # Whenever assets are compiled, the asset files are checked if they have
45
+ # changed from the previous release.
46
+ #
47
+ # If they're unchanged, compiled assets will simply be copied over to the new
48
+ # release.
49
+ #
50
+ # Override this if you have custom asset paths declared in your Rails's
51
+ # `config.assets.paths` setting.
52
+
53
+ set_default :asset_paths, ['vendor/assets/', 'app/assets/']
54
+
55
+ # ### rake_assets_precompile
56
+ # The command to invoke when precompiling assets.
57
+ # Override me if you like.
58
+
59
+ settings.rake_assets_precompile ||= lambda { "#{rake} assets:precompile RAILS_GROUPS=assets" }
60
+
61
+ # ----
62
+
63
+ # Macro used later by :rails, :rake, etc
64
+ make_run_task = lambda { |name, sample_args|
65
+ task name, [:arguments] => :environment do |t, args|
66
+ arguments = args[:arguments]
67
+ command = send name
68
+ unless arguments
69
+ puts %{You need to provide arguments. Try: mina "#{name}[#{sample_args}]"}
70
+ exit 1
71
+ end
72
+ queue echo_cmd %[cd "#{deploy_to!}/#{current_path!}" && #{command} #{arguments}]
73
+ end
74
+ }
75
+
76
+ def check_for_changes_script(options={})
77
+ diffs = options[:at].map { |path|
78
+ %[diff -r "#{deploy_to}/#{current_path}/#{path}" "./#{path}" 2>/dev/null]
79
+ }.join("\n")
80
+
81
+ unindent %[
82
+ if [ -e "#{deploy_to}/#{current_path}/#{options[:check]}" ]; then
83
+ count=`(
84
+ #{reindent 4, diffs}
85
+ ) | wc -l`
86
+
87
+ if [ "$((count))" = "0" ]; then
88
+ #{reindent 4, options[:skip]} &&
89
+ exit
90
+ else
91
+ #{reindent 4, options[:changed]}
92
+ fi
93
+ else
94
+ #{reindent 2, options[:default]}
95
+ fi
96
+ ]
97
+ end
98
+
99
+ # ## Command-line tasks
100
+ # These tasks can be invoked in the command line.
101
+
102
+ # ### rails[]
103
+ # Invokes a rails command.
104
+ #
105
+ # $ mina rails[console]
106
+
107
+ desc "Execute a Rails command in the current deploy."
108
+ make_run_task[:rails, 'console']
109
+
110
+ # ### rake[]
111
+ # Invokes a rake command.
112
+ #
113
+ # $ mina rake db:cleanup
114
+
115
+ desc "Execute a Rake command in the current deploy."
116
+ make_run_task[:rake, 'db:migrate']
117
+
118
+ # ### console
119
+ # Opens the Ruby console for the currently-deployed version.
120
+ #
121
+ # $ mina console
122
+
123
+ desc "Starts an interactive console."
124
+ task :console do
125
+ queue echo_cmd %[cd "#{deploy_to!}/#{current_path!}" && #{rails} console && exit]
126
+ end
127
+
128
+ # ## Deploy tasks
129
+ # These tasks are meant to be invoked inside deploy scripts, not invoked on
130
+ # their own.
131
+
132
+ namespace :rails do
133
+ # ### rails:db_migrate
134
+ desc "Migrates the Rails database (skips if nothing has changed since the last release)."
135
+ task :db_migrate do
136
+ if ENV['force_migrate']
137
+ invoke :'rails:db_migrate:force'
138
+ else
139
+ message = verbose_mode? ?
140
+ '$((count)) changes found, migrating database' :
141
+ 'Migrating database'
142
+
143
+ queue check_for_changes_script \
144
+ :check => 'db/migrate/',
145
+ :at => ['db/migrate/'],
146
+ :skip => %[
147
+ echo "-----> DB migrations unchanged; skipping DB migration"
148
+ ],
149
+ :changed => %[
150
+ #{print_str("-> " + message)}
151
+ #{echo_cmd %[#{rake} db:migrate]}
152
+ ],
153
+ :default => %[
154
+ #{print_str '-> Migrating database'}
155
+ #{echo_cmd %[#{rake} db:migrate]}
156
+ ]
157
+ end
158
+ end
159
+
160
+ # ### rails:db_migrate:force
161
+ desc "Migrates the Rails database."
162
+ task :'db_migrate:force' do
163
+ queue %{
164
+ #{print_str '-> Migrating database'}
165
+ #{echo_cmd %[#{rake} db:migrate]}
166
+ }
167
+ end
168
+
169
+ # ### rails:assets_precompile:force
170
+ desc "Precompiles assets."
171
+ task :'assets_precompile:force' do
172
+ queue %{
173
+ echo "-----> Precompiling asset files"
174
+ #{echo_cmd %[#{rake_assets_precompile}]}
175
+ }
176
+ end
177
+
178
+ # ### rails:assets_precompile
179
+ desc "Precompiles assets (skips if nothing has changed since the last release)."
180
+ task :'assets_precompile' do
181
+ if ENV['force_assets']
182
+ invoke :'rails:assets_precompile:force'
183
+ else
184
+ message = verbose_mode? ?
185
+ '$((count)) changes found, precompiling asset files' :
186
+ 'Precompiling asset files'
187
+
188
+ queue check_for_changes_script \
189
+ :check => 'public/assets/',
190
+ :at => [*asset_paths],
191
+ :skip => %[
192
+ echo "-----> Skipping asset precompilation"
193
+ #{echo_cmd %[cp -R "#{deploy_to}/#{current_path}/public/assets" "./public"]}
194
+ ],
195
+ :changed => %[
196
+ echo "-----> #{message}"
197
+ #{echo_cmd %[#{rake_assets_precompile}]}
198
+ ],
199
+ :default => %[
200
+ echo "-----> Precompiling asset files"
201
+ #{echo_cmd %[#{rake_assets_precompile}]}
202
+ ]
203
+ end
204
+ end
205
+
206
+ end
data/lib/mina/rake.rb ADDED
@@ -0,0 +1,9 @@
1
+ # This file is invoked from Rake.
2
+ extend Mina::Helpers
3
+ extend Mina::DeployHelpers
4
+ extend Mina::SshHelpers
5
+ extend Mina::OutputHelpers
6
+ extend Mina::ExecHelpers
7
+
8
+ require 'mina/default'
9
+ require 'mina/deploy' if Rake.application.have_rakefile
data/lib/mina/rbenv.rb ADDED
@@ -0,0 +1,47 @@
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 ADDED
@@ -0,0 +1,88 @@
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