mina 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +14 -5
  3. data/HISTORY.md +45 -1
  4. data/LICENSE +1 -1
  5. data/Makefile +29 -0
  6. data/Notes.md +70 -0
  7. data/Readme.md +1009 -0
  8. data/bin/mina +1 -1
  9. data/data/deploy.rb +13 -7
  10. data/lib/mina/bundler.rb +6 -1
  11. data/lib/mina/chruby.rb +49 -0
  12. data/lib/mina/default.rb +1 -0
  13. data/lib/mina/deploy.rb +17 -1
  14. data/lib/mina/deploy_helpers.rb +4 -4
  15. data/lib/mina/exec_helpers.rb +26 -19
  16. data/lib/mina/foreman.rb +5 -1
  17. data/lib/mina/git.rb +1 -1
  18. data/lib/mina/helpers.rb +22 -13
  19. data/lib/mina/rails.rb +6 -6
  20. data/lib/mina/rbenv.rb +1 -0
  21. data/lib/mina/rvm.rb +2 -4
  22. data/lib/mina/ssh_helpers.rb +2 -1
  23. data/lib/mina/version.rb +1 -1
  24. data/lib/mina/whenever.rb +6 -6
  25. data/mina.gemspec +2 -2
  26. data/spec/command_helper.rb +1 -1
  27. data/spec/commands/cleanup_spec.rb +16 -0
  28. data/spec/commands/command_spec.rb +18 -18
  29. data/spec/commands/custom_config_spec.rb +2 -2
  30. data/spec/commands/deploy_spec.rb +7 -7
  31. data/spec/commands/outside_project_spec.rb +7 -7
  32. data/spec/commands/real_deploy_spec.rb +21 -21
  33. data/spec/commands/verbose_spec.rb +2 -2
  34. data/spec/dsl/invoke_spec.rb +17 -2
  35. data/spec/dsl/queue_spec.rb +4 -4
  36. data/spec/dsl/settings_in_rake_spec.rb +6 -6
  37. data/spec/dsl/settings_spec.rb +16 -10
  38. data/spec/dsl/to_spec.rb +2 -2
  39. data/spec/helpers/exec_helper_spec.rb +19 -0
  40. data/spec/spec_helper.rb +6 -0
  41. data/support/Readme-footer.md +32 -0
  42. data/support/Readme-header.md +16 -0
  43. data/support/guide.md +297 -0
  44. data/support/index.html +53 -0
  45. data/support/to_md.rb +11 -0
  46. data/test_env/config/deploy.rb +2 -0
  47. metadata +96 -61
  48. checksums.yaml +0 -7
  49. data/README.md +0 -114
data/bin/mina CHANGED
@@ -58,7 +58,7 @@ Rake.application.instance_eval do
58
58
  puts ""
59
59
  scope.print_error "Command failed."
60
60
  scope.print_stderr "#{e.message}"
61
- exit e.exitstatus
61
+ exit(e.exitstatus > 255 ? e.exitstatus >> 8 : e.exitstatus)
62
62
  end
63
63
  end
64
64
  end
data/data/deploy.rb CHANGED
@@ -15,6 +15,9 @@ set :deploy_to, '/var/www/foobar.com'
15
15
  set :repository, 'git://...'
16
16
  set :branch, 'master'
17
17
 
18
+ # For system-wide RVM install.
19
+ # set :rvm_path, '/usr/local/rvm/bin/rvm'
20
+
18
21
  # Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
19
22
  # They will be linked in the 'deploy:link_shared_paths' step.
20
23
  set :shared_paths, ['config/database.yml', 'log']
@@ -22,6 +25,7 @@ set :shared_paths, ['config/database.yml', 'log']
22
25
  # Optional settings:
23
26
  # set :user, 'foobar' # Username in the server to SSH to.
24
27
  # set :port, '30000' # SSH port number.
28
+ # set :forward_agent, true # SSH forward_agent.
25
29
 
26
30
  # This task is the environment that is loaded for most commands, such as
27
31
  # `mina deploy` or `mina rake`.
@@ -38,14 +42,14 @@ end
38
42
  # For Rails apps, we'll make some of the shared paths that are shared between
39
43
  # all releases.
40
44
  task :setup => :environment do
41
- queue! %[mkdir -p "#{deploy_to}/shared/log"]
42
- queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
45
+ queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
46
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]
43
47
 
44
- queue! %[mkdir -p "#{deploy_to}/shared/config"]
45
- queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
48
+ queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
49
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]
46
50
 
47
- queue! %[touch "#{deploy_to}/shared/config/database.yml"]
48
- queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."]
51
+ queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
52
+ queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml'."]
49
53
  end
50
54
 
51
55
  desc "Deploys the current version to the server."
@@ -58,9 +62,11 @@ task :deploy => :environment do
58
62
  invoke :'bundle:install'
59
63
  invoke :'rails:db_migrate'
60
64
  invoke :'rails:assets_precompile'
65
+ invoke :'deploy:cleanup'
61
66
 
62
67
  to :launch do
63
- queue "touch #{deploy_to}/tmp/restart.txt"
68
+ queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
69
+ queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
64
70
  end
65
71
  end
66
72
  end
data/lib/mina/bundler.rb CHANGED
@@ -19,10 +19,15 @@ set_default :bundle_bin, 'bundle'
19
19
 
20
20
  set_default :bundle_path, './vendor/bundle'
21
21
 
22
+ # ### bundle_withouts
23
+ # Sets the colon-separated list of groups to be skipped from installation.
24
+
25
+ set_default :bundle_withouts, 'development:test'
26
+
22
27
  # ### bundle_options
23
28
  # Sets the options for installing gems via Bundler.
24
29
 
25
- set_default :bundle_options, lambda { %{--without development:test --path "#{bundle_path}" --binstubs bin/ --deployment} }
30
+ set_default :bundle_options, lambda { %{--without #{bundle_withouts} --path "#{bundle_path}" --deployment} }
26
31
 
27
32
  # ## Deploy tasks
28
33
  # These tasks are meant to be invoked inside deploy scripts, not invoked on
@@ -0,0 +1,49 @@
1
+ # # Modules: chruby
2
+ # Adds settings and tasks for managing [chruby] installations.
3
+ #
4
+ # [chruby]: https://github.com/postmodern/chruby
5
+ #
6
+ # require 'mina/chruby'
7
+ #
8
+ # ## Common usage
9
+ #
10
+ # task :environment do
11
+ # invoke :'chruby[ruby-1.9.3-p392]'
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
+ # ### chruby_path
22
+ # Path where *chruby* init scripts are installed.
23
+ #
24
+ set_default :chruby_path, "/etc/profile.d/chruby.sh"
25
+
26
+ # ## Tasks
27
+
28
+ # ### chruby[version]
29
+ # Switch to given Ruby version
30
+
31
+ task :chruby, :env do |t, args|
32
+ unless args[:env]
33
+ print_error "Task 'chruby' needs a Ruby version as an argument."
34
+ print_error "Example: invoke :'chruby[ruby-1.9.3-p392]'"
35
+ die
36
+ end
37
+
38
+ queue %{
39
+ echo "-----> chruby to version: '#{args[:env]}'"
40
+
41
+ if [[ ! -s "#{chruby_path}" ]]; then
42
+ echo "! chruby.sh init file not found"
43
+ exit 1
44
+ fi
45
+
46
+ source #{chruby_path}
47
+ #{echo_cmd %{chruby "#{args[:env]}"}} || exit 1
48
+ }
49
+ end
data/lib/mina/default.rb CHANGED
@@ -131,6 +131,7 @@ task :help do
131
131
  puts ""
132
132
  puts "All of Rake's options are also available as '#{name}' options. See 'rake --help'"
133
133
  puts "for more information."
134
+ exit
134
135
  end
135
136
 
136
137
  # ### tasks
data/lib/mina/deploy.rb CHANGED
@@ -4,10 +4,26 @@
4
4
  # ## Settings
5
5
  # Any and all of these settings can be overriden in your `deploy.rb`.
6
6
 
7
+ # ### releases_path
8
+ # (default: 'releases')
7
9
  set_default :releases_path, "releases"
10
+
11
+ # ### shared_path
12
+ # (default: 'shared')
8
13
  set_default :shared_path, "shared"
14
+
15
+ # ### current_path
16
+ # (default: 'current_path')
9
17
  set_default :current_path, "current"
18
+
19
+ # ### lock_file
20
+ # Name of the file to generate while a deploy is currently ongoing.
21
+ # (default: 'deploy.lock')
10
22
  set_default :lock_file, "deploy.lock"
23
+
24
+ # ### keep_releases
25
+ # Number of releases to keep when doing the `deploy:cleanup` task.
26
+ # (default: 5)
11
27
  set_default :keep_releases, 5
12
28
 
13
29
  namespace :deploy do
@@ -65,7 +81,7 @@ namespace :deploy do
65
81
  echo "-----> Cleaning up old releases (keeping #{keep_releases!})"
66
82
  #{echo_cmd %{cd "#{deploy_to!}/#{releases_path!}" || exit 15}}
67
83
  #{echo_cmd %{count=`ls -1d [0-9]* | sort -rn | wc -l`}}
68
- #{echo_cmd %{remove=$((count > 5 ? count - #{keep_releases} : 0))}}
84
+ #{echo_cmd %{remove=$((count > #{keep_releases} ? count - #{keep_releases} : 0))}}
69
85
  #{echo_cmd %{ls -1d [0-9]* | sort -rn | tail -n $remove | xargs rm -rf {}}}
70
86
  }
71
87
  end
@@ -15,11 +15,11 @@ module Mina
15
15
  # ### deploy_script
16
16
  # Wraps the things inside it in a deploy script.
17
17
  #
18
- # script = deploy_script do
19
- # invoke :'git:checkout'
20
- # end
18
+ # script = deploy_script do
19
+ # invoke :'git:checkout'
20
+ # end
21
21
  #
22
- # queue script
22
+ # queue script
23
23
  #
24
24
  # Returns the deploy script as a string, ready for `queue`ing.
25
25
  #
@@ -22,14 +22,14 @@ module Mina
22
22
  trap("INT") { Sys.handle_sigint(coathooks += 1, pid, self) }
23
23
 
24
24
  # __In the background,__ make stdin passthru, and stream stderr.
25
- pid_err = Sys.stream_stderr!(e) { |str| print_stderr str }
26
- pid_in = Sys.stream_stdin! { |chr| i.putc chr }
25
+ th_err = Sys.stream_stderr!(e) { |str| print_stderr str }
26
+ th_in = Sys.stream_stdin! { |chr| i.putc chr }
27
27
 
28
28
  # __In the foreground,__ stream stdout to the output helper.
29
29
  Sys.stream_stdout(o) { |ch| print_char ch }
30
30
 
31
- Process.waitpid pid_err
32
- Process.kill 'TERM', pid_in
31
+ th_err.join
32
+ th_in.terminate
33
33
  end
34
34
 
35
35
  status.exitstatus
@@ -59,31 +59,35 @@ module Mina
59
59
 
60
60
  # ### Sys.stream_stderr!
61
61
  # __Internal:__ Read from stderr stream `err` *[0]*, supress expected
62
- # errors *[1]*, and yield. Returns the PID.
62
+ # errors *[1]*, and yield. Returns the thread.
63
63
 
64
64
  def stream_stderr!(err, &blk)
65
- fork do
66
- trap("INT") {}
67
-
68
- while str = err.gets #[0]
69
- next if str.include? "bash: no job control in this shell" #[1]
70
- next if str.include? "stdin is not a terminal"
71
-
72
- yield str.strip #[2]
65
+ Thread.new do
66
+ begin
67
+ while str = err.gets #[0]
68
+ next if str.include? "bash: no job control in this shell" #[1]
69
+ next if str.include? "stdin is not a terminal"
70
+
71
+ yield str.strip #[2]
72
+ end
73
+ rescue Interrupt
73
74
  end
74
75
  end
75
76
  end
76
77
 
77
78
  # ### Sys.stream_stdin!
78
79
  # __Internal:__ Read from the real stdin stream and pass it onto the given
79
- # stdin stream `i`. Returns the PID.
80
+ # stdin stream `i`. Returns the thread.
80
81
 
81
82
  def stream_stdin!(&blk)
82
- fork do
83
- trap("INT") {}
84
-
85
- while (char = STDIN.getbyte rescue nil)
86
- yield char if char
83
+ Thread.new do
84
+ begin
85
+ while (char = STDIN.getbyte rescue nil)
86
+ yield char if char
87
+ end
88
+ rescue Interrupt
89
+ # rubinius
90
+ rescue SignalException
87
91
  end
88
92
  end
89
93
  end
@@ -94,6 +98,9 @@ module Mina
94
98
 
95
99
  def stream_stdout(o, &blk)
96
100
  while str = o.getc
101
+ # Ruby 1.8.7 fix
102
+ str = str.chr if str.is_a? Fixnum
103
+
97
104
  yield str
98
105
  end
99
106
  end
data/lib/mina/foreman.rb CHANGED
@@ -40,11 +40,15 @@
40
40
  set_default :foreman_app, lambda { application }
41
41
  set_default :foreman_user, lambda { user }
42
42
  set_default :foreman_log, lambda { "#{deploy_to!}/#{shared_path}/log" }
43
+ set_default :foreman_sudo, true
44
+ set_default :foreman_format, 'upstart'
45
+ set_default :foreman_location, '/etc/init'
43
46
 
44
47
  namespace :foreman do
45
48
  desc 'Export the Procfile to Ubuntu upstart scripts'
46
49
  task :export do
47
- export_cmd = "sudo bundle exec foreman export upstart /etc/init -a #{foreman_app} -u #{foreman_user} -l #{foreman_log}"
50
+ sudo_cmd = "sudo" if foreman_sudo
51
+ export_cmd = "#{sudo_cmd} bundle exec foreman export #{foreman_format} #{foreman_location} -a #{foreman_app} -u #{foreman_user} -d #{deploy_to!}/#{current_path!} -l #{foreman_log}"
48
52
 
49
53
  queue %{
50
54
  echo "-----> Exporting foreman procfile for #{foreman_app}"
data/lib/mina/git.rb CHANGED
@@ -52,7 +52,7 @@ namespace :git do
52
52
  status = %[
53
53
  echo "-----> Using this git commit" &&
54
54
  echo &&
55
- #{echo_cmd %[git --no-pager log --format="%aN (%h):%n> %s" -n 1]} &&
55
+ #{echo_cmd %[git --no-pager log --format='%aN (%h):%n> %s' -n 1]} &&
56
56
  #{echo_cmd %[rm -rf .git]} &&
57
57
  echo
58
58
  ]
data/lib/mina/helpers.rb CHANGED
@@ -1,4 +1,4 @@
1
- # # Helpers: Default helpers
1
+ # # Helpers
2
2
 
3
3
  module Mina
4
4
  module Helpers
@@ -17,7 +17,10 @@ module Mina
17
17
 
18
18
  def invoke(task, options = {})
19
19
  Rake.application.invoke_task task
20
- Rake::Task[task].reenable if options[:reenable]
20
+ if options[:reenable]
21
+ name = Rake.application.parse_task_string(task).first
22
+ Rake::Task[name].reenable
23
+ end
21
24
  end
22
25
 
23
26
  # ### erb
@@ -64,7 +67,7 @@ module Mina
64
67
  # end
65
68
  #
66
69
  # # Output:
67
- # # Elapsed time: 2.0 seconds
70
+ # # Elapsed time: 2.00 seconds
68
71
 
69
72
  def report_time(&blk)
70
73
  time, output = measure &blk
@@ -73,13 +76,13 @@ module Mina
73
76
  end
74
77
 
75
78
  # ### measure
76
- # Measures the time (in ms) a block takes.
79
+ # Measures the time (in seconds) a block takes.
77
80
  # Returns a [time, output] tuple.
78
81
 
79
82
  def measure(&blk)
80
83
  t = Time.now
81
84
  output = yield
82
- [(Time.now - t).to_i, output]
85
+ [Time.now - t, output]
83
86
  end
84
87
 
85
88
  # ### mina_cleanup
@@ -119,9 +122,9 @@ module Mina
119
122
  # ## Queueing
120
123
 
121
124
  # ### queue
122
- # Queues code to be ran.
125
+ # Queues code to be run.
123
126
  #
124
- # This queues code to be ran to the current code bucket (defaults to `:default`).
127
+ # This queues code to be run to the current code bucket (defaults to `:default`).
125
128
  # To get the things that have been queued, use commands[:default]
126
129
  #
127
130
  # Returns nothing.
@@ -217,17 +220,18 @@ module Mina
217
220
  #
218
221
  # Returns nothing.
219
222
  #
220
- # in_directory './webapp' do
221
- # queue "./reload"
222
- # end
223
+ # in_directory './webapp' do
224
+ # queue "./reload"
225
+ # end
223
226
  #
224
- # commands.should == ['cd ./webapp && (./reload && true)']
227
+ # commands.should == ['cd ./webapp && (./reload && true)']
225
228
 
226
229
  def in_directory(path, &blk)
227
230
  isolated_commands = isolate { yield; commands }
228
231
  isolated_commands.each { |cmd| queue "(cd #{path} && (#{cmd}))" }
229
232
  end
230
233
 
234
+ # ### to
231
235
  # Defines instructions on how to do a certain thing.
232
236
  # This makes the commands that are `queue`d go into a different bucket in commands.
233
237
  #
@@ -310,13 +314,17 @@ module Mina
310
314
  # Checks if Rake was invoked with --verbose.
311
315
  #
312
316
  # Returns true or false.
317
+ #
318
+ # if verbose_mode?
319
+ # queue %[echo "-----> Starting a new process"]
320
+ # end
313
321
 
314
322
  def verbose_mode?
315
323
  if Rake.respond_to?(:verbose)
316
- # Rake 0.9.x
324
+ #- Rake 0.9.x
317
325
  Rake.verbose == true
318
326
  else
319
- # Rake 0.8.x
327
+ #- Rake 0.8.x
320
328
  RakeFileUtils.verbose_flag != :default
321
329
  end
322
330
  end
@@ -369,6 +377,7 @@ module Mina
369
377
 
370
378
  # ### capture
371
379
  # Returns the output of command via SSH.
380
+
372
381
  def capture(cmd, options={})
373
382
  ssh cmd, options.merge(:return => true)
374
383
  end
data/lib/mina/rails.rb CHANGED
@@ -12,7 +12,7 @@ require 'mina/bundler'
12
12
  # Sets the Rails environment for `rake` and `rails` commands.
13
13
  #
14
14
  # Note that changing this will NOT change the environment that your application
15
- # is ran in.
15
+ # is run in.
16
16
 
17
17
  set_default :rails_env, 'production'
18
18
 
@@ -118,7 +118,7 @@ make_run_task[:rake, 'db:migrate']
118
118
  # ### console
119
119
  # Opens the Ruby console for the currently-deployed version.
120
120
  #
121
- # $ mina console
121
+ # $ mina console
122
122
 
123
123
  desc "Starts an interactive console."
124
124
  task :console do
@@ -141,10 +141,10 @@ namespace :rails do
141
141
  'Migrating database'
142
142
 
143
143
  queue check_for_changes_script \
144
- :check => 'db/schema.rb',
145
- :at => ['db/schema.rb'],
144
+ :check => 'db/migrate/',
145
+ :at => ['db/migrate/'],
146
146
  :skip => %[
147
- echo "-----> DB schema unchanged; skipping DB migration"
147
+ echo "-----> DB migrations unchanged; skipping DB migration"
148
148
  ],
149
149
  :changed => %[
150
150
  echo "-----> #{message}"
@@ -190,7 +190,7 @@ namespace :rails do
190
190
  :at => [*asset_paths],
191
191
  :skip => %[
192
192
  echo "-----> Skipping asset precompilation"
193
- #{echo_cmd %[cp -R "#{deploy_to}/#{current_path}/public/assets" "./public/assets"]}
193
+ #{echo_cmd %[cp -R "#{deploy_to}/#{current_path}/public/assets" "./public"]}
194
194
  ],
195
195
  :changed => %[
196
196
  echo "-----> #{message}"
data/lib/mina/rbenv.rb CHANGED
@@ -33,6 +33,7 @@ set_default :rbenv_path, "$HOME/.rbenv"
33
33
  task :'rbenv:load' do
34
34
  queue %{
35
35
  echo "-----> Loading rbenv"
36
+ #{echo_cmd %{export RBENV_ROOT="#{rbenv_path}"}}
36
37
  #{echo_cmd %{export PATH="#{rbenv_path}/bin:$PATH"}}
37
38
 
38
39
  if ! which rbenv >/dev/null; then
data/lib/mina/rvm.rb CHANGED
@@ -57,9 +57,8 @@ task :'rvm:use', :env do |t, args|
57
57
  }
58
58
  end
59
59
 
60
-
61
60
  # ### rvm:wrapper[]
62
- # Creates a rvm wrapper for a given executable
61
+ # Creates a rvm wrapper for a given executable.
63
62
  #
64
63
  # This is usually placed in the `:setup` task.
65
64
  #
@@ -71,7 +70,7 @@ end
71
70
  task :'rvm:wrapper', :env, :name, :bin do |t,args|
72
71
  unless args[:env] && args[:name] && args[:bin]
73
72
  print_error "Task 'rvm:wrapper' needs an RVM environment name, an wrapper name and the binary name as arguments"
74
- print_error "Example: invoke :'rvm:use[ruby-1.9.2@myapp,myapp,unicorn_rails]'"
73
+ print_error "Example: invoke :'rvm:wrapper[ruby-1.9.2@myapp,myapp,unicorn_rails]'"
75
74
  die
76
75
  end
77
76
 
@@ -86,5 +85,4 @@ task :'rvm:wrapper', :env, :name, :bin do |t,args|
86
85
  source #{rvm_path}
87
86
  #{echo_cmd %{rvm wrapper #{args[:env]} #{args[:name]} #{args[:bin]} }} || exit 1
88
87
  }
89
-
90
88
  end
@@ -83,7 +83,8 @@ module Mina
83
83
  # `term_mode`. Called by `ssh`.
84
84
 
85
85
  def invoke(script, this)
86
- term_mode = :"#{this.settings.term_mode}"
86
+ # Ruby 1.8.7 doesn't let you have empty symbols
87
+ term_mode = :"#{this.settings.term_mode}" if this.settings.term_mode
87
88
  code = "#{this.ssh_command} -- #{script}"
88
89
 
89
90
  # Certain environments can't do :pretty mode.
data/lib/mina/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  def self.version
3
- "0.3.0"
3
+ "0.3.1"
4
4
  end
5
5
  end
data/lib/mina/whenever.rb CHANGED
@@ -6,22 +6,22 @@ namespace :whenever do
6
6
  desc "Clear crontab"
7
7
  task :clear do
8
8
  queue %{
9
- echo "-----> Clear crontab for #{domain}"
10
- #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --clear-crontab #{domain} --set 'environment=production&path=#{deploy_to!}/#{current_path!}']}
9
+ echo "-----> Clear crontab for #{domain}_#{rails_env}"
10
+ #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --clear-crontab #{domain}_#{rails_env} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']}
11
11
  }
12
12
  end
13
13
  desc "Update crontab"
14
14
  task :update do
15
15
  queue %{
16
- echo "-----> Update crontab for #{domain}"
17
- #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --update-crontab #{domain} --set 'environment=production&path=#{deploy_to!}/#{current_path!}']}
16
+ echo "-----> Update crontab for #{domain}_#{rails_env}"
17
+ #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --update-crontab #{domain}_#{rails_env} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']}
18
18
  }
19
19
  end
20
20
  desc "Write crontab"
21
21
  task :write do
22
22
  queue %{
23
- echo "-----> Update crontab for #{domain}"
24
- #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --write-crontab #{domain} --set 'environment=production&path=#{deploy_to!}/#{current_path!}']}
23
+ echo "-----> Update crontab for #{domain}_#{rails_env}"
24
+ #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; #{bundle_bin} exec whenever --write-crontab #{domain}_#{rails_env} --set 'environment=#{rails_env}&path=#{deploy_to!}/#{current_path!}']}
25
25
  }
26
26
  end
27
27
  end
data/mina.gemspec CHANGED
@@ -12,6 +12,6 @@ Gem::Specification.new do |s|
12
12
  s.executables = Dir["bin/*"].map { |f| File.basename(f) }
13
13
 
14
14
  s.add_dependency "rake"
15
- s.add_dependency "open4"
16
- s.add_development_dependency "rspec"
15
+ s.add_dependency "open4", "~> 1.3.4"
16
+ s.add_development_dependency "rspec", "~> 3.0.0"
17
17
  end
@@ -36,7 +36,7 @@ def mina(*args)
36
36
  puts stderr
37
37
  end
38
38
 
39
- exitstatus.should == 0
39
+ expect(exitstatus).to eq(0)
40
40
  end
41
41
 
42
42
  def stdout
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'command_helper'
3
+
4
+ describe "Invoking the 'mina deploy:cleanup' command" do
5
+ before :each do
6
+ Dir.chdir root('test_env')
7
+ end
8
+
9
+ it "should cleanup old deployments", :ssh => true do
10
+ 3.times { mina 'deploy' }
11
+
12
+ mina 'deploy:cleanup'
13
+
14
+ expect(Dir["deploy/releases/*"].length).to eq(2)
15
+ end
16
+ end
@@ -8,24 +8,24 @@ describe "Invoking the 'mina' command in a project" do
8
8
 
9
9
  it "should think it's 'mina', not 'rake' (1)" do
10
10
  run_command 'pinkledills'
11
- exitstatus.should_not == 0
12
- stderr.should include 'mina aborted'
11
+ expect(exitstatus).not_to eq(0)
12
+ expect(stderr).to include 'mina aborted'
13
13
  end
14
14
 
15
15
  it "should think it's 'mina', not 'rake' (1)" do
16
16
  mina '-T'
17
- stdout.should include 'mina help'
18
- stdout.should include 'mina git:clone'
17
+ expect(stdout).to include 'mina help'
18
+ expect(stdout).to include 'mina git:clone'
19
19
  end
20
20
 
21
21
  it 'with --version should print the version' do
22
22
  mina '--version'
23
- stdout.should include Mina.version
23
+ expect(stdout).to include Mina.version
24
24
  end
25
25
 
26
26
  it 'with -V should print the version' do
27
27
  mina '-V'
28
- stdout.should include Mina.version
28
+ expect(stdout).to include Mina.version
29
29
  end
30
30
 
31
31
  describe 'without arguments' do
@@ -35,37 +35,37 @@ describe "Invoking the 'mina' command in a project" do
35
35
 
36
36
  it 'should print standard help tasks' do
37
37
  mina
38
- stdout.should include 'mina help'
39
- stdout.should include 'mina init'
40
- stdout.should include 'mina tasks'
38
+ expect(stdout).to include 'mina help'
39
+ expect(stdout).to include 'mina init'
40
+ expect(stdout).to include 'mina tasks'
41
41
  end
42
42
 
43
43
  it 'should print project-specific tasks' do
44
44
  mina
45
- stdout.should include 'mina deploy'
46
- stdout.should include 'mina restart'
47
- stdout.should include 'mina setup'
45
+ expect(stdout).to include 'mina deploy'
46
+ expect(stdout).to include 'mina restart'
47
+ expect(stdout).to include 'mina setup'
48
48
  end
49
49
 
50
50
  it "should be the same as running 'help'" do
51
51
  previous_out = stdout
52
52
 
53
53
  mina 'help'
54
- stdout.should == previous_out
54
+ expect(stdout).to eq(previous_out)
55
55
  end
56
56
  end
57
57
 
58
58
  it "with 'mina -f' on a non-existing file should fail" do
59
59
  run_command '-f', 'foobar'
60
- stderr.should include 'mina aborted'
61
- stderr.should include 'No Rakefile found'
60
+ expect(stderr).to include 'mina aborted'
61
+ expect(stderr).to include 'No Rakefile found'
62
62
  end
63
63
 
64
64
  it "with 'mina tasks' should print tasks" do
65
65
  mina 'tasks'
66
66
 
67
- stdout.should include('bundle:install')
68
- stdout.should include('Install gem dependencies using Bundler')
69
- stdout.should include('passenger:restart')
67
+ expect(stdout).to include('bundle:install')
68
+ expect(stdout).to include('Install gem dependencies using Bundler')
69
+ expect(stdout).to include('passenger:restart')
70
70
  end
71
71
  end
@@ -9,12 +9,12 @@ describe "Invoking the 'mina' command in a project without a deploy.rb" do
9
9
 
10
10
  it 'should fail' do
11
11
  run_command 'deploy', '--simulate'
12
- exitstatus.should be > 0
12
+ expect(exitstatus).to be > 0
13
13
  end
14
14
 
15
15
  it 'should pass if you provide a new rakefile' do
16
16
  mina 'deploy', '--simulate', '-f', 'custom_deploy.rb'
17
- stdout.should include 'Creating a temporary build path'
17
+ expect(stdout).to include 'Creating a temporary build path'
18
18
  end
19
19
  end
20
20