mina 0.1.2.pre2 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,30 +1,38 @@
1
- v0.1.2.pre2 - Jul 3, 2012
2
- -------------------------
1
+ v0.1.2 - Jul 06, 2012
2
+ ---------------------
3
+
4
+ ### Fixed:
5
+ * __Show stdout output properly on deploy.__
6
+ * 'mina rake' now works.
7
+
8
+ ### Changed:
9
+ * Refactor pretty printing to be simpler, cleaner, and extensible.
10
+ * Show prettier abort messages when ^C'd.
11
+ * Use the new error message format. (See lib/mina/output_helpers.rb)
12
+
13
+ v0.1.2.pre2 - Jul 03, 2012
14
+ --------------------------
3
15
 
4
16
  ### Added:
5
- * Add bundle_bin option
6
- * Add ssh port option
17
+ * Add `:bundle_bin` option.
18
+ * Add `:ssh` port option.
7
19
 
8
20
  ### Fixed:
9
- * Fix deploy:link_shared_paths to use absolute paths
10
- * Fix console logs for task init
21
+ * __Fix `deploy:link_shared_paths` to use absolute paths.__
22
+ * Fix console logs for task init.
11
23
 
12
24
  v0.1.2.pre1 - Jun 12, 2012
13
25
  --------------------------
14
26
 
15
27
  ### Fixed:
16
- * Fixed JRuby support.
17
- * Respect .bashrc. (#5)
28
+ * __Fixed JRuby support.__
29
+ * __Respect .bashrc.__ (#5)
18
30
 
19
31
  ### Changed:
20
32
  * Implement `ssh("..", return: true)`.
21
- * Rename simulate_mode to simulate_mode?. Same with verbose_mode?.
33
+ * Rename `simulate_mode` to `simulate_mode?`. Same with `verbose_mode?`.
22
34
  * Show the SSH command in the simulation output.
23
35
 
24
- ### Misc:
25
- * Prepare for Tomdoc.
26
- * Stop invoking bash needlessly to prettify things.
27
-
28
36
  v0.1.1 - Jun 07, 2012
29
37
  ---------------------
30
38
 
data/bin/mina CHANGED
@@ -24,29 +24,37 @@ scope = self
24
24
 
25
25
  Rake.application.instance_eval do
26
26
  standard_exception_handling do
27
- # Initialize Rake and make it think it's Mina.
28
- init 'mina'
27
+ begin
28
+ # Initialize Rake and make it think it's Mina.
29
+ init 'mina'
29
30
 
30
- # (The only way @rakefiles has only 1 value is if -f is specified.)
31
- custom_rakefile = (@rakefiles.size == 1)
32
- @rakefiles = ['Minafile', 'config/deploy.rb'] unless custom_rakefile
31
+ # (The only way @rakefiles has only 1 value is if -f is specified.)
32
+ custom_rakefile = (@rakefiles.size == 1)
33
+ @rakefiles = ['Minafile', 'config/deploy.rb'] unless custom_rakefile
33
34
 
34
- # Workaround: Rake 0.9+ doesn't record task descriptions unless it's needed.
35
- # Need it for 'mina help'
36
- if Rake::TaskManager.respond_to?(:record_task_metadata)
37
- Rake::TaskManager.record_task_metadata = true
38
- end
35
+ # Workaround: Rake 0.9+ doesn't record task descriptions unless it's needed.
36
+ # Need it for 'mina help'
37
+ if Rake::TaskManager.respond_to?(:record_task_metadata)
38
+ Rake::TaskManager.record_task_metadata = true
39
+ end
40
+
41
+ # Load the Mina Rake DSL.
42
+ require 'mina/rake'
39
43
 
40
- # Load the Mina Rake DSL.
41
- require 'mina/rake'
44
+ # Allow running without a Rakefile
45
+ load_rakefile if have_rakefile || custom_rakefile
42
46
 
43
- # Allow running without a Rakefile
44
- load_rakefile if have_rakefile || custom_rakefile
47
+ # Run tasks
48
+ top_level
45
49
 
46
- # Run tasks
47
- top_level
50
+ scope.mina_cleanup! if top_level_tasks.any?
48
51
 
49
- scope.mina_cleanup! if top_level_tasks.any?
52
+ rescue Mina::Failed => e
53
+ puts ""
54
+ scope.print_error "Command failed."
55
+ scope.print_stderr "#{e.message}"
56
+ exit e.exitstatus
57
+ end
50
58
  end
51
59
  end
52
60
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  # Go to the deploy path
9
9
  cd "<%= deploy_to %>" || (
10
- echo "=====> ERROR: not set up."
10
+ echo "! ERROR: not set up."
11
11
  echo "The path '<%= deploy_to %>' is not accessible on the server."
12
12
  echo "You may need to run 'mina setup' first."
13
13
  false
@@ -15,7 +15,7 @@ cd "<%= deploy_to %>" || (
15
15
 
16
16
  # Check releases path
17
17
  if [ ! -d "<%= releases_path %>" ]; then
18
- echo "=====> ERROR: not set up."
18
+ echo "! ERROR: not set up."
19
19
  echo "The directory '<%= releases_path %>' does not exist on the server."
20
20
  echo "You may need to run 'mina setup' first."
21
21
  exit 16
@@ -23,7 +23,7 @@ fi
23
23
 
24
24
  # Check lockfile
25
25
  if [ -e "<%= lock_file %>" ]; then
26
- echo "=====> ERROR: another deployment is ongoing."
26
+ echo "! ERROR: another deployment is ongoing."
27
27
  echo "The file '<%= lock_file %>' was found."
28
28
  echo "If no other deployment is ongoing, delete the file to continue."
29
29
  exit 17
@@ -37,7 +37,7 @@ release_path="<%= releases_path %>/$version"
37
37
 
38
38
  # Sanity check
39
39
  if [ -e "$build_path" ]; then
40
- echo "=====> ERROR: Path already exists"
40
+ echo "! ERROR: Path already exists."
41
41
  exit 18
42
42
  fi
43
43
 
@@ -82,7 +82,7 @@ fi
82
82
  # ============================
83
83
  # === Failed deployment
84
84
  (
85
- echo "=====> ERROR: Deploy failed."
85
+ echo "! ERROR: Deploy failed."
86
86
 
87
87
  <%= indent 2, clean %>
88
88
 
@@ -5,6 +5,7 @@ module Mina
5
5
  require 'mina/version'
6
6
 
7
7
  autoload :DeployHelpers, 'mina/deploy_helpers'
8
+ autoload :OutputHelpers, 'mina/output_helpers'
8
9
  autoload :Helpers, 'mina/helpers'
9
10
  autoload :Settings, 'mina/settings'
10
11
  autoload :Tools, 'mina/tools'
@@ -12,7 +12,7 @@ namespace :git do
12
12
  echo "-----> Cloning the Git repository"
13
13
  #{echo_cmd %[git clone "#{repository!}" . -n --recursive]} &&
14
14
  echo "-----> Using revision #{revision}" &&
15
- #{echo_cmd %[git checkout "#{revision}" -b current_release 1>/dev/null]} &&
15
+ #{echo_cmd %[git checkout -q "#{revision}" -b current_release 1>/dev/null]} &&
16
16
  #{echo_cmd %[rm -rf .git]}
17
17
  }
18
18
  end
@@ -80,7 +80,7 @@ module Mina
80
80
 
81
81
  elsif settings.term_mode == :pretty
82
82
  code = "#{ssh_command} -- bash #{bash_options} -c #{script}"
83
- result = pretty_system("#{code} 2>&1")
83
+ result = pretty_system(code)
84
84
 
85
85
  elsif settings.term_mode == :exec
86
86
  code = "#{ssh_command} -t -- bash #{bash_options} -c #{script}"
@@ -118,58 +118,6 @@ module Mina
118
118
  "ssh #{args}"
119
119
  end
120
120
 
121
- # Internal: Works like 'system', but indents and puts color.
122
- #
123
- # Returns the exit code in integer form.
124
- #
125
- def pretty_system(code)
126
- require 'shellwords'
127
- cmds = Shellwords.shellsplit(code)
128
- cmds << "2>&1"
129
-
130
- status =
131
- Tools.popen4(*cmds) do |pid, i, o, e|
132
- i.close
133
-
134
- last = nil
135
- clear_on_nl = false
136
- while c = o.getc
137
- # Because Ruby 1.8.x returns a number on #getc
138
- c = "%c" % [c] if c.is_a?(Fixnum)
139
-
140
- break if o.closed?
141
- if last == "\n"
142
- if clear_on_nl
143
- clear_on_nl = false
144
- print "\033[0m"
145
- end
146
-
147
- # Color the verbose echo commands
148
- if c == "$" && ((c += o.read(1)) == "$ ")
149
- clear_on_nl = true
150
- print " "*7 + "\033[32m#{c}\033[34m"
151
-
152
- # (Don't) color the status messages
153
- elsif c == "-" && ((c += o.read(5)) == "----->")
154
- print c
155
-
156
- # Color errors
157
- elsif c == "=" && ((c += o.read(5)) == "=====>")
158
- print "\033[31m=====>\033[0m"
159
-
160
- else
161
- print " "*7 + c
162
- end
163
- else
164
- print c
165
- end
166
-
167
- last = c
168
- end
169
- end
170
- status.exitstatus
171
- end
172
-
173
121
  # Queues code to be ran.
174
122
  #
175
123
  # This queues code to be ran to the current code bucket (defaults to `:default`).
@@ -0,0 +1,95 @@
1
+ module Mina
2
+ module OutputHelpers
3
+ # Protip! make a module that overrides these settings, then use `extend YourModule`
4
+ # to make your own pretty printing thing.
5
+ def print_status(msg)
6
+ puts "" if verbose_mode?
7
+ puts "#{color('----->', 32)} #{msg}"
8
+ end
9
+
10
+ def print_error(msg)
11
+ puts " #{color("!", 33)} #{color(msg, 31)}"
12
+ end
13
+
14
+ def print_stderr(msg)
15
+ puts " #{color(msg, 31)}"
16
+ end
17
+
18
+ def print_command(msg)
19
+ puts " #{color("$", 32)} #{color(msg, 32)}"
20
+ end
21
+
22
+ def print_stdout(msg)
23
+ puts " #{msg}"
24
+ end
25
+
26
+ # Internal: Colorizes a string.
27
+ # Returns the string `str` with the color `c`.
28
+ def color(str, c)
29
+ ENV['NO_COLOR'] ? str : "\033[#{c}m#{str}\033[0m"
30
+ end
31
+
32
+ # Internal: Prints a string by delegating it to the proper output helper.
33
+ #
34
+ # It takes an input with text and prints them nicely. The text block can
35
+ # have statuses (prefixed with `-----> `), errors (prefixed with `! `),
36
+ # commands (prefixed with `$ `) or anything else. Depending on the type of
37
+ # the message, they will be delegated to the proper print_* helper.
38
+ #
39
+ # -----> Unlocking
40
+ # $ unlock foo
41
+ # Unlocked.
42
+ # ! ERROR: Failed
43
+ #
44
+ # Returns nothing.
45
+ #
46
+ def print_str(str)
47
+ if str =~ /^\-+> (.*?)$/
48
+ print_status $1
49
+ elsif str =~ /^! (.*?)$/
50
+ print_error $1
51
+ elsif str =~ /^\$ (.*?)$/
52
+ print_command $1
53
+ else
54
+ print_stdout str
55
+ end
56
+ end
57
+
58
+ # Internal: Works like `system`, but indents and puts color.
59
+ #
60
+ # Returns the exit code in integer form.
61
+ #
62
+ def pretty_system(code)
63
+ require 'shellwords'
64
+ cmds = Shellwords.shellsplit(code)
65
+
66
+ status =
67
+ Tools.popen4(*cmds) do |pid, i, o, e|
68
+ trap "INT" do
69
+ puts ""
70
+ print_status "Mina: SIGINT received."
71
+ end
72
+
73
+ # Read stderr in the background.
74
+ p1 = fork do
75
+ trap("INT") {}
76
+ while str = e.gets
77
+ # Supress expected errors.
78
+ next if str.include? "bash: no job control in this shell"
79
+ next if str.include? "stdin is not a terminal"
80
+ print_stderr str.strip
81
+ end
82
+ end
83
+
84
+ # Read stdout.
85
+ while str = o.gets
86
+ print_str str
87
+ end
88
+
89
+ Process.waitpid p1
90
+ end
91
+
92
+ status.exitstatus
93
+ end
94
+ end
95
+ end
@@ -7,12 +7,13 @@ settings.rails ||= lambda { %{#{bundle_prefix} rails} }
7
7
  # Macro used later by :rails, :rake, etc
8
8
  make_run_task = lambda { |name, sample_args|
9
9
  task name, :arguments do |t, args|
10
- command = args[:arguments]
10
+ arguments = args[:arguments]
11
+ command = send name
11
12
  unless command
12
13
  puts %{You need to provide arguments. Try: mina "#{name}[#{sample_args}]"}
13
14
  exit 1
14
15
  end
15
- queue %[cd "#{deploy_to!}/#{current_path!}" && #{rails} #{command}]
16
+ queue echo_cmd %[cd "#{deploy_to!}/#{current_path!}" && #{command} #{arguments}]
16
17
  end
17
18
  }
18
19
 
@@ -1,6 +1,7 @@
1
1
  # This file is invoked from Rake.
2
2
  extend Mina::Helpers
3
3
  extend Mina::DeployHelpers
4
+ extend Mina::OutputHelpers
4
5
 
5
6
  require 'mina/default'
6
7
  require 'mina/deploy' if Rake.application.have_rakefile
@@ -11,5 +11,10 @@ module Mina
11
11
  Open4.popen4 *cmd, &blk
12
12
  end
13
13
  end
14
+
15
+ def self.pfork4(*cmd, &blk)
16
+ require 'open4'
17
+ Open4.pfork4 *cmd, &blk
18
+ end
14
19
  end
15
20
  end
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  def self.version
3
- "0.1.2.pre2"
3
+ "0.1.2"
4
4
  end
5
5
  end
@@ -28,6 +28,7 @@ task :deploy do
28
28
  queue "bundle() { true; }" # Stub the bundle command.
29
29
 
30
30
  deploy do
31
+ queue %[ruby -e "\\$stderr.write \\\"This is stdout output\n\\\""]
31
32
  invoke :'git:clone'
32
33
  invoke :'bundle:install'
33
34
  invoke :'rails:db_migrate'
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.pre2
5
- prerelease: 6
4
+ version: 0.1.2
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-03 00:00:00.000000000 Z
13
+ date: 2012-07-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &70278252972060 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70278252972060
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: open4
28
- requirement: &70278252960240 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70278252960240
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rspec
39
- requirement: &70278252958560 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,7 +54,12 @@ dependencies:
44
54
  version: '0'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70278252958560
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  description: Really fast deployer and server automation tool.
49
64
  email:
50
65
  - rico@nadarei.co
@@ -72,6 +87,7 @@ files:
72
87
  - lib/mina/deploy_helpers.rb
73
88
  - lib/mina/git.rb
74
89
  - lib/mina/helpers.rb
90
+ - lib/mina/output_helpers.rb
75
91
  - lib/mina/rails.rb
76
92
  - lib/mina/rake.rb
77
93
  - lib/mina/settings.rb
@@ -109,13 +125,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
125
  required_rubygems_version: !ruby/object:Gem::Requirement
110
126
  none: false
111
127
  requirements:
112
- - - ! '>'
128
+ - - ! '>='
113
129
  - !ruby/object:Gem::Version
114
- version: 1.3.1
130
+ version: '0'
115
131
  requirements: []
116
132
  rubyforge_project:
117
- rubygems_version: 1.8.10
133
+ rubygems_version: 1.8.23
118
134
  signing_key:
119
135
  specification_version: 3
120
136
  summary: Really fast deployer and server automation tool.
121
137
  test_files: []
138
+ has_rdoc: