Permalink
Browse files

Rewrote whole mina

  • Loading branch information...
1 parent b448807 commit dbdb31b3b99de3205d55296e4a38c3bcb2c0c2e1 @d4be4st d4be4st committed May 22, 2016
Showing with 1,378 additions and 1,565 deletions.
  1. +0 −3 .travis.yml
  2. +2 −8 Gemfile
  3. +1 −6 Rakefile
  4. +1 −62 bin/mina
  5. +21 −22 data/deploy.sh.erb
  6. +3 −0 lib/Minafile
  7. +33 −18 lib/mina.rb
  8. +74 −0 lib/mina/application.rb
  9. +22 −0 lib/mina/backend/local.rb
  10. +42 −0 lib/mina/backend/remote.rb
  11. +36 −0 lib/mina/commands.rb
  12. +33 −0 lib/mina/commands/element.rb
  13. +34 −0 lib/mina/commands/params.rb
  14. +35 −0 lib/mina/commands/queue.rb
  15. +28 −0 lib/mina/configuration.rb
  16. +0 −34 lib/mina/deploy_helpers.rb
  17. +52 −0 lib/mina/dsl.rb
  18. +0 −111 lib/mina/exec_helpers.rb
  19. +358 −402 lib/mina/helpers.rb
  20. +53 −0 lib/mina/helpers/internal.rb
  21. +73 −0 lib/mina/helpers/output.rb
  22. +0 −97 lib/mina/local_helpers.rb
  23. +0 −92 lib/mina/output_helpers.rb
  24. +0 −10 lib/mina/rake.rb
  25. +39 −0 lib/mina/runner.rb
  26. +15 −0 lib/mina/runner/exec.rb
  27. +80 −0 lib/mina/runner/pretty.rb
  28. +17 −0 lib/mina/runner/printer.rb
  29. +15 −0 lib/mina/runner/system.rb
  30. +0 −32 lib/mina/settings.rb
  31. +0 −125 lib/mina/ssh_helpers.rb
  32. +0 −20 lib/mina/tools.rb
  33. +1 −3 lib/mina/version.rb
  34. +24 −16 mina.gemspec
  35. +0 −158 modules/mina/default.rb
  36. +0 −160 modules/mina/deploy.rb
  37. +0 −69 modules/mina/git.rb
  38. +8 −30 spec/dsl/invoke_spec.rb
  39. +1 −1 spec/dsl/settings_in_rake_spec.rb
  40. +2 −2 spec/dsl/settings_spec.rb
  41. +1 −1 spec/spec_helper.rb
  42. +4 −1 {modules → tasks}/mina/bundler.rb
  43. +1 −1 {modules → tasks}/mina/chruby.rb
  44. +35 −0 tasks/mina/default.rb
  45. +75 −0 tasks/mina/deploy.rb
  46. +1 −1 {modules → tasks}/mina/foreman.rb
  47. +48 −0 tasks/mina/git.rb
  48. +18 −0 tasks/mina/install.rb
  49. +1 −1 {modules → tasks}/mina/npm.rb
  50. +1 −1 {modules → tasks}/mina/rails.rb
  51. +1 −1 {modules → tasks}/mina/rbenv.rb
  52. +1 −1 {modules → tasks}/mina/rvm.rb
  53. +1 −1 {modules → tasks}/mina/ry.rb
  54. +1 −1 {modules → tasks}/mina/whenever.rb
  55. +86 −74 test_env/config/deploy.rb
View
@@ -9,9 +9,6 @@ env:
- "rake=0.8"
- "rake=0.9"
- "rake=10"
-# before_script:
-# - cat ~/.ssh/*.pub >> ~/.ssh/authorized_keys
-# - ssh -o StrictHostKeyChecking=no localhost "exit"
script: "bundle exec rspec"
notifications:
email:
View
@@ -1,10 +1,4 @@
-# Why use bundler?
-# Well, not all development dependencies install on all rubies. Moreover, `gem
-# install mina --development` doesn't work, as it will also try to install
-# development dependencies of our dependencies, and those are not conflict free.
-# So, here we are, `bundle install`.
+source 'https://rubygems.org'
-source "https://rubygems.org"
+# Specify your gem's dependencies in capistrano.gemspec
gemspec
-
-gem 'rake', "~> #{ENV['rake'] || "0.9"}.0"
View
@@ -1,9 +1,4 @@
-require 'bundler'
require 'bundler/gem_tasks'
-
-task :spec do
- system "rm Gemfile.lock; sh -c 'rake=0.8 bundle exec rspec'"
- system "rm Gemfile.lock; sh -c 'rake=0.9 bundle exec rspec'"
-end
+require 'rspec/core/rake_task'
task default: :spec
View
@@ -1,65 +1,4 @@
#!/usr/bin/env ruby
-$:.unshift File.expand_path('../../lib', __FILE__)
-
-require 'rubygems' unless Object.const_defined?(:Gem)
require 'mina'
-require 'rake'
-
-# Intercept: if invoked as 'mina --help', don't let it pass through Rake, or else
-# we'll see the Rake help screen. Redirect it to 'mina help'.
-if ARGV.delete('--help') || ARGV.delete('-h')
- ARGV << 'help'
-end
-
-if ARGV.delete('--version') || ARGV.delete('-V')
- puts "Mina, version v#{Mina.version}"
- exit
-end
-
-if ARGV.delete('--simulate') || ARGV.delete('-S')
- ENV['simulate'] = '1'
-end
-
-scope = self
-
-Rake.application.instance_eval do
- standard_exception_handling do
- begin
- # Initialize Rake and make it think it's Mina.
- init 'mina'
-
- # (The only way @rakefiles has only 1 value is if -f is specified.)
- custom_rakefile = (@rakefiles.size == 1)
- @rakefiles = ['Minafile', 'config/deploy.rb'] unless custom_rakefile
-
- # Workaround: Rake 0.9+ doesn't record task descriptions unless it's needed.
- # Need it for 'mina help'
- if Rake::TaskManager.respond_to?(:record_task_metadata)
- Rake::TaskManager.record_task_metadata = true
- end
-
- # Load the Mina Rake DSL.
- require 'mina/rake'
-
- # Allow running without a Rakefile
- begin
- load_rakefile if have_rakefile || custom_rakefile
- rescue Exception
- puts "Error loading Rakefile!"
- raise "There may be a problem with config/deploy.rb and/or Rakefile"
- end
-
- # Run tasks
- top_level
-
- scope.mina_cleanup! if top_level_tasks.any?
-
- rescue Mina::Failed => e
- puts ""
- scope.print_error "Command failed."
- scope.print_stderr "#{e.message}"
- exit(e.exitstatus > 255 ? e.exitstatus >> 8 : e.exitstatus)
- end
- end
-end
+Mina::Application.new.run
View
@@ -1,40 +1,40 @@
<%
- prepare = commands(:default).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
- build = commands(:build).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
- launch = commands(:launch).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
- clean = commands(:clean).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
+ default = commands.fetch(Commands::Params.new(:remote, :default)).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
+ build = commands.fetch(Commands::Params.new(:remote, :build)).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
+ launch = commands.fetch(Commands::Params.new(:remote, :launch)).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
+ clean = commands.fetch(Commands::Params.new(:remote, :clean)).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
%>
#!/usr/bin/env bash
# Go to the deploy path
-cd "<%= deploy_to %>" || (
+cd "<%= fetch(:deploy_to) %>" || (
echo "! ERROR: not set up."
- echo "The path '<%= deploy_to %>' is not accessible on the server."
+ echo "The path '<%= fetch(:deploy_to) %>' is not accessible on the server."
echo "You may need to run 'mina setup' first."
false
) || exit 15
# Check releases path
-if [ ! -d "<%= releases_path %>" ]; then
+if [ ! -d "<%= fetch(:releases_path) %>" ]; then
echo "! ERROR: not set up."
- echo "The directory '<%= releases_path %>' does not exist on the server."
+ echo "The directory '<%= fetch(:releases_path) %>' does not exist on the server."
echo "You may need to run 'mina setup' first."
exit 16
fi
# Check lockfile
-if [ -e "<%= lock_file %>" ]; then
+if [ -e "<%= fetch(:lock_file) %>" ]; then
echo "! ERROR: another deployment is ongoing."
- echo "The file '<%= lock_file %>' was found."
+ echo "The file '<%= fetch(:lock_file) %>' was found."
echo "If no other deployment is ongoing, run 'mina deploy:force_unlock' to delete the file."
exit 17
fi
# Determine $previous_path and other variables
-[ -h "<%= current_path %>" ] && [ -d "<%= current_path %>" ] && previous_path=$(cd "<%= current_path %>" >/dev/null && pwd -LP)
+[ -h "<%= fetch(:current_path) %>" ] && [ -d "<%= fetch(:current_path) %>" ] && previous_path=$(cd "<%= fetch(:current_path) %>" >/dev/null && pwd -LP)
build_path="./tmp/build-`date +%s`$RANDOM"
-version=$((`cat "<%= deploy_to %>/last_version" 2>/dev/null`+1))
-release_path="<%= releases_path %>/$version"
+version=$((`cat "<%= fetch(:deploy_to) %>/last_version" 2>/dev/null`+1))
+release_path="<%= fetch(:releases_path) %>/$version"
# Sanity check
if [ -e "$build_path" ]; then
@@ -45,11 +45,11 @@ fi
# Bootstrap script (in deployer)
(
echo "-----> Creating a temporary build path"
- <%= echo_cmd %[touch "#{lock_file}"] %> &&
+ <%= echo_cmd %[touch "#{fetch(:lock_file)}"] %> &&
<%= echo_cmd %[mkdir -p "$build_path"] %> &&
<%= echo_cmd %[cd "$build_path"] %> &&
(
-<%= indent 4, (prepare.empty? ? "true" : prepare) %>
+<%= indent 4, (default.empty? ? "true" : default) %>
) &&
echo "-----> Deploy finished"
) &&
@@ -73,22 +73,21 @@ fi
# Rename to the real release path, then symlink 'current'
(
echo "-----> Launching"
- echo "-----> Updating the <%= current_path %> symlink" &&
- <%= echo_cmd %[ln -nfs "$release_path" "#{current_path}"] %>
+ echo "-----> Updating the <%= fetch(:current_path) %> symlink" &&
+ <%= echo_cmd %[ln -nfs "$release_path" "#{fetch(:current_path)}"] %>
) &&
# ============================
# === Start up server => (in deployer)
(
- echo "-----> Launching"
- <%= echo_cmd %[cd "#{current_path}"] %>
+ <%= echo_cmd %[cd "#{fetch(:current_path)}"] %>
<%= indent 2, (launch.empty? ? "true" : launch) %>
) &&
# ============================
# === Complete & unlock
(
- rm -f "<%= lock_file %>"
+ rm -f "<%= fetch(:lock_file) %>"
echo "$version" > "./last_version"
echo "-----> Done. Deployed v$version"
) ||
@@ -110,11 +109,11 @@ fi
)
(
echo "Unlinking current"
- [ -n "$previous_path" ] && <%= echo_cmd %[ln -nfs "$previous_path" "#{current_path}"] %>
+ [ -n "$previous_path" ] && <%= echo_cmd %[ln -nfs "$previous_path" "#{fetch(:current_path)}"] %>
)
# Unlock
- <%= echo_cmd %[rm -f "#{lock_file}"] %>
+ <%= echo_cmd %[rm -f "#{fetch(:lock_file)}"] %>
echo "OK"
exit 19
)
View
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+require 'mina/install'
View
@@ -1,24 +1,39 @@
-module Mina
- PREFIX = File.dirname(__FILE__)
- ROOT = File.expand_path('../../', __FILE__)
+require 'rake'
+Rake.application.options.trace = true
- require 'mina/version'
+require 'pry'
+require 'awesome_print'
- autoload :DeployHelpers, 'mina/deploy_helpers'
- autoload :OutputHelpers, 'mina/output_helpers'
- autoload :SshHelpers, 'mina/ssh_helpers'
- autoload :LocalHelpers, 'mina/local_helpers'
- autoload :ExecHelpers, 'mina/exec_helpers'
- autoload :Helpers, 'mina/helpers'
- autoload :Settings, 'mina/settings'
- autoload :Tools, 'mina/tools'
+require 'forwardable'
+require 'shellwords'
+require 'singleton'
+require 'open4'
- Error = Class.new(Exception)
- class Failed < Error
- attr_accessor :exitstatus
- end
+require 'mina/version'
+require 'mina/configuration'
+require 'mina/dsl'
+require 'mina/helpers/output'
+require 'mina/helpers/internal'
+require 'mina/commands'
+require 'mina/commands/params'
+require 'mina/commands/element'
+require 'mina/commands/queue'
+require 'mina/runner'
+require 'mina/runner/pretty'
+require 'mina/runner/system'
+require 'mina/runner/exec'
+require 'mina/runner/printer'
+require 'mina/backend/local'
+require 'mina/backend/remote'
+require 'mina/application'
- def self.root_path(*a)
- File.join ROOT, *a
+module Mina
+ # Error = Class.new(Exception)
+ # class Failed < Error
+ # attr_accessor :exitstatus
+ # end
+ #
+ def self.root_path(*args)
+ File.join File.expand_path('../../', __FILE__), *args
end
end
@@ -0,0 +1,74 @@
+module Mina
+ class Application < Rake::Application
+ def initialize
+ super
+ @rakefiles = ['config/deploy.rb', minafile]
+ end
+
+ def name
+ 'mina'
+ end
+
+ def run
+ Rake.application = self
+ super
+ end
+
+ def sort_options(options)
+ not_applicable_to_mina = %w(quiet silent verbose dry-run)
+ options.reject! do |(switch, *)|
+ switch =~ /--#{Regexp.union(not_applicable_to_mina)}/
+ end
+
+ super.push(version, verbose, simulate, debug_configuration_variables)
+ end
+
+ def top_level_tasks
+ @top_level_tasks << :debug_configuration_variables
+ @top_level_tasks << :run_commands
+ end
+
+ private
+
+ def minafile
+ File.expand_path(File.join(File.dirname(__FILE__), '..', 'Minafile'))
+ end
+
+ def version
+ ['--version', '-V',
+ 'Display the program version.',
+ lambda do |_value|
+ puts "Mina, version v#{Mina::VERSION}"
+ exit
+ end
+ ]
+ end
+
+ def verbose
+ ['--verbose', '-v',
+ 'Print more info',
+ lambda do |_value|
+ Mina::Configuration.instance.set(:verbose, true)
+ end
+ ]
+ end
+
+ def simulate
+ ['--simulate', '-s',
+ 'Do a simulate run without executing actions',
+ lambda do |_value|
+ Mina::Configuration.instance.set(:simulate, true)
+ end
+ ]
+ end
+
+ def debug_configuration_variables
+ ['--debug-configuration-variables', '-d',
+ 'Display the defined config variables before starting the deployment tasks.',
+ lambda do |_value|
+ Mina::Configuration.instance.set(:debug_configuration_variables, true)
+ end
+ ]
+ end
+ end
+end
@@ -0,0 +1,22 @@
+module Mina
+ module Backend
+ class Local
+ attr_reader :commands, :configuration
+ extend Forwardable
+ def_delegators :configuration, :fetch, :set?
+
+ def initialize(commands)
+ @configuration = Mina::Configuration.instance
+ @commands = commands
+ end
+
+ def prepare
+ if fetch(:simulate)
+ ['#!/usr/bin/env bash', '# Executing the following:', '#', commands, ' '].join("\n")
+ else
+ Shellwords.escape(commands)
+ end
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit dbdb31b

Please sign in to comment.