colorful-mina 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
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
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+
4
+ github = ENV['github'] || 'nadarei/mina'
5
+
6
+ task :spec do
7
+ system "rm Gemfile.lock; sh -c 'rake=0.8 bundle exec rspec'"
8
+ system "rm Gemfile.lock; sh -c 'rake=0.9 bundle exec rspec'"
9
+ end
10
+
11
+ task :docs do
12
+ files = ['manual/index.md', 'manual/modules.md', 'HISTORY.md'] + Dir['lib/**/*.rb']
13
+ system "lidoc #{files.join ' '} -o docs --github #{github}"
14
+ end
15
+
16
+ task :'docs:deploy' => :docs do
17
+ system "git-update-ghpages #{github} -i docs -p docs"
18
+ end
19
+
20
+ task :default => :spec
data/bin/mina ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rubygems' unless Object.const_defined?(:Gem)
5
+ require 'mina'
6
+ require 'rake'
7
+
8
+ # Intercept: if invoked as 'mina --help', don't let it pass through Rake, or else
9
+ # we'll see the Rake help screen. Redirect it to 'mina help'.
10
+ if ARGV.delete('--help') || ARGV.delete('-h')
11
+ ARGV << 'help'
12
+ end
13
+
14
+ if ARGV.delete('--version') || ARGV.delete('-V')
15
+ puts "Mina, version v#{Mina.version}"
16
+ exit
17
+ end
18
+
19
+ if ARGV.delete('--simulate') || ARGV.delete('-S')
20
+ ENV['simulate'] = '1'
21
+ end
22
+
23
+ scope = self
24
+
25
+ Rake.application.instance_eval do
26
+ standard_exception_handling do
27
+ begin
28
+ # Initialize Rake and make it think it's Mina.
29
+ init 'mina'
30
+
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
34
+
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'
43
+
44
+ # Allow running without a Rakefile
45
+ begin
46
+ load_rakefile if have_rakefile || custom_rakefile
47
+ rescue Exception
48
+ puts "Error loading Rakefile!"
49
+ raise "There may be a problem with config/deploy.rb and/or Rakefile"
50
+ end
51
+
52
+ # Run tasks
53
+ top_level
54
+
55
+ scope.mina_cleanup! if top_level_tasks.any?
56
+
57
+ rescue Mina::Failed => e
58
+ puts ""
59
+ scope.print_error "Command failed."
60
+ scope.print_stderr "#{e.message}"
61
+ exit(e.exitstatus > 255 ? e.exitstatus >> 8 : e.exitstatus)
62
+ end
63
+ end
64
+ end
65
+
data/data/deploy.rb ADDED
@@ -0,0 +1,80 @@
1
+ require 'mina/bundler'
2
+ require 'mina/rails'
3
+ require 'mina/git'
4
+ # require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
5
+ # require 'mina/rvm' # for rvm support. (http://rvm.io)
6
+
7
+ # Basic settings:
8
+ # domain - The hostname to SSH to.
9
+ # deploy_to - Path to deploy into.
10
+ # repository - Git repo to clone from. (needed by mina/git)
11
+ # branch - Branch name to deploy. (needed by mina/git)
12
+
13
+ set :domain, 'foobar.com'
14
+ set :deploy_to, '/var/www/foobar.com'
15
+ set :repository, 'git://...'
16
+ set :branch, 'master'
17
+
18
+ # For system-wide RVM install.
19
+ # set :rvm_path, '/usr/local/rvm/bin/rvm'
20
+
21
+ # Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
22
+ # They will be linked in the 'deploy:link_shared_paths' step.
23
+ set :shared_paths, ['config/database.yml', 'log']
24
+
25
+ # Optional settings:
26
+ # set :user, 'foobar' # Username in the server to SSH to.
27
+ # set :port, '30000' # SSH port number.
28
+ # set :forward_agent, true # SSH forward_agent.
29
+
30
+ # This task is the environment that is loaded for most commands, such as
31
+ # `mina deploy` or `mina rake`.
32
+ task :environment do
33
+ # If you're using rbenv, use this to load the rbenv environment.
34
+ # Be sure to commit your .ruby-version or .rbenv-version to your repository.
35
+ # invoke :'rbenv:load'
36
+
37
+ # For those using RVM, use this to load an RVM version@gemset.
38
+ # invoke :'rvm:use[ruby-1.9.3-p125@default]'
39
+ end
40
+
41
+ # Put any custom mkdir's in here for when `mina setup` is ran.
42
+ # For Rails apps, we'll make some of the shared paths that are shared between
43
+ # all releases.
44
+ task :setup => :environment do
45
+ queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
46
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]
47
+
48
+ queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
49
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]
50
+
51
+ queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
52
+ queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml'."]
53
+ end
54
+
55
+ desc "Deploys the current version to the server."
56
+ task :deploy => :environment do
57
+ deploy do
58
+ # Put things that will set up an empty directory into a fully set-up
59
+ # instance of your project.
60
+ invoke :'git:clone'
61
+ invoke :'deploy:link_shared_paths'
62
+ invoke :'bundle:install'
63
+ invoke :'rails:db_migrate'
64
+ invoke :'rails:assets_precompile'
65
+ invoke :'deploy:cleanup'
66
+
67
+ to :launch do
68
+ queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
69
+ queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
70
+ end
71
+ end
72
+ end
73
+
74
+ # For help in making your deploy script, see the Mina documentation:
75
+ #
76
+ # - http://nadarei.co/mina
77
+ # - http://nadarei.co/mina/tasks
78
+ # - http://nadarei.co/mina/settings
79
+ # - http://nadarei.co/mina/helpers
80
+
@@ -0,0 +1,106 @@
1
+ <%
2
+ prepare = commands(:default).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
3
+ launch = commands(:launch).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
4
+ clean = commands(:clean).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
5
+ %>
6
+ #!/usr/bin/env bash
7
+
8
+ # Go to the deploy path
9
+ cd "<%= deploy_to %>" || (
10
+ echo "! ERROR: not set up."
11
+ echo "The path '<%= deploy_to %>' is not accessible on the server."
12
+ echo "You may need to run 'mina setup' first."
13
+ false
14
+ ) || exit 15
15
+
16
+ # Check releases path
17
+ if [ ! -d "<%= releases_path %>" ]; then
18
+ echo "! ERROR: not set up."
19
+ echo "The directory '<%= releases_path %>' does not exist on the server."
20
+ echo "You may need to run 'mina setup' first."
21
+ exit 16
22
+ fi
23
+
24
+ # Check lockfile
25
+ if [ -e "<%= lock_file %>" ]; then
26
+ echo "! ERROR: another deployment is ongoing."
27
+ echo "The file '<%= lock_file %>' was found."
28
+ echo "If no other deployment is ongoing, delete the file to continue."
29
+ exit 17
30
+ fi
31
+
32
+ # Determine $previous_path and other variables
33
+ [ -h "<%= current_path %>" ] && [ -d "<%= current_path %>" ] && previous_path=$(cd "<%= current_path %>" >/dev/null && pwd -LP)
34
+ build_path="./tmp/build-`date +%s`$RANDOM"
35
+ version=$((`cat "<%= deploy_to %>/last_version" 2>/dev/null`+1))
36
+ release_path="<%= releases_path %>/$version"
37
+
38
+ # Sanity check
39
+ if [ -e "$build_path" ]; then
40
+ echo "! ERROR: Path already exists."
41
+ exit 18
42
+ fi
43
+
44
+ # Bootstrap script (in deployer)
45
+ (
46
+ <%= print_str '-> Creating a temporary build path' %>
47
+ <%= echo_cmd %[touch "#{lock_file}"] %> &&
48
+ <%= echo_cmd %[mkdir -p "$build_path"] %> &&
49
+ <%= echo_cmd %[cd "$build_path"] %> &&
50
+ (
51
+ <%= indent 4, (prepare.empty? ? "true" : prepare) %>
52
+ )
53
+ ) &&
54
+
55
+ #
56
+ # Rename to the real release path, then symlink 'current'
57
+ (
58
+ <%= print_str '-> Build finished' %>
59
+ <%= print_str '-> Moving build to $release_path' %>
60
+ <%= echo_cmd %[mv "$build_path" "$release_path"] %> &&
61
+
62
+ <%= print_str "-> Updating the " + current_path + " symlink" %> &&
63
+ <%= echo_cmd %[ln -nfs "$release_path" "#{current_path}"] %>
64
+ ) &&
65
+
66
+ # ============================
67
+ # === Start up serve => (in deployer)
68
+ (
69
+ <%= print_str '-> Launching' %>
70
+ <%= echo_cmd %[cd "$release_path"] %>
71
+ <%= indent 2, (launch.empty? ? "true" : launch) %>
72
+ ) &&
73
+
74
+ # ============================
75
+ # === Complete & unlock
76
+ (
77
+ rm -f "<%= lock_file %>"
78
+ echo "$version" > "./last_version"
79
+ <%= print_str "-> Done. Deployed v$version" %>
80
+ ) ||
81
+
82
+ # ============================
83
+ # === Failed deployment
84
+ (
85
+ <%= print_str('! ERROR: Deploy failed.') %>
86
+
87
+ <%= indent 2, clean %>
88
+
89
+ echo "-----> Cleaning up build"
90
+ [ -e "$build_path" ] && (
91
+ <%= echo_cmd %[rm -rf "$build_path"] %>
92
+ )
93
+ [ -e "$release_path" ] && (
94
+ <%= print_str 'Deleting release' %>
95
+ <%= echo_cmd %[rm -rf "$release_path"] %>
96
+ )
97
+ (
98
+ echo "Unlinking current"
99
+ [ -n "$previous_path" ] && <%= echo_cmd %[ln -nfs "$previous_path" "#{current_path}"] %>
100
+ )
101
+
102
+ # Unlock
103
+ <%= echo_cmd %[rm -f "#{lock_file}"] %>
104
+ echo "OK"
105
+ exit 19
106
+ )
data/lib/mina.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Mina
2
+ PREFIX = File.dirname(__FILE__)
3
+ ROOT = File.expand_path('../../', __FILE__)
4
+
5
+ require 'mina/version'
6
+
7
+ autoload :DeployHelpers, 'mina/deploy_helpers'
8
+ autoload :OutputHelpers, 'mina/output_helpers'
9
+ autoload :SshHelpers, 'mina/ssh_helpers'
10
+ autoload :ExecHelpers, 'mina/exec_helpers'
11
+ autoload :Helpers, 'mina/helpers'
12
+ autoload :Settings, 'mina/settings'
13
+ autoload :Tools, 'mina/tools'
14
+
15
+ Error = Class.new(Exception)
16
+ class Failed < Error
17
+ attr_accessor :exitstatus
18
+ end
19
+
20
+ def self.root_path(*a)
21
+ File.join ROOT, *a
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ # # Modules: Bundler
2
+ # Adds settings and tasks for managing Ruby Bundler.
3
+ #
4
+ # require 'mina/bundler'
5
+
6
+ # ## Settings
7
+ # Any and all of these settings can be overriden in your `deploy.rb`.
8
+
9
+ # ### bundle_bin
10
+ # Sets the bundle path.
11
+
12
+ set_default :bundle_bin, 'bundle'
13
+
14
+ # ### bundle_path
15
+ # Sets the path to where the gems are expected to be.
16
+ #
17
+ # This path will be symlinked to `./shared/bundle` so that the gems cache will
18
+ # be shared between all releases.
19
+
20
+ set_default :bundle_path, './vendor/bundle'
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
+
27
+ # ### bundle_options
28
+ # Sets the options for installing gems via Bundler.
29
+
30
+ set_default :bundle_options, lambda { %{--without #{bundle_withouts} --path "#{bundle_path}" --deployment} }
31
+
32
+ # ## Deploy tasks
33
+ # These tasks are meant to be invoked inside deploy scripts, not invoked on
34
+ # their own.
35
+
36
+ namespace :bundle do
37
+ # ### bundle:install
38
+ # Installs gems.
39
+ desc "Install gem dependencies using Bundler."
40
+ task :install do
41
+ queue %{
42
+ #{print_str '-> Installing gem dependencies using Bundler'}
43
+ #{echo_cmd %[mkdir -p "#{deploy_to}/#{shared_path}/bundle"]}
44
+ #{echo_cmd %[mkdir -p "#{File.dirname bundle_path}"]}
45
+ #{echo_cmd %[ln -s "#{deploy_to}/#{shared_path}/bundle" "#{bundle_path}"]}
46
+ #{echo_cmd %[#{bundle_bin} install #{bundle_options}]}
47
+ }
48
+ end
49
+ end
@@ -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
@@ -0,0 +1,145 @@
1
+ # # Modules: Default
2
+ # This module is loaded when invoking `mina` with or without a project.
3
+
4
+ # ## Settings
5
+ # Here are some of the common settings. All settings are optional unless
6
+ # otherwise noted.
7
+ #
8
+ # ### deploy_to
9
+ # (Required) Path to deploy to.
10
+ #
11
+ # ### domain
12
+ # (Required) Host name to deploy to.
13
+ #
14
+ # ### port
15
+ # SSH port number.
16
+ #
17
+ # ### forward_agent
18
+ # If set to `true`, enables SSH agent forwarding.
19
+ #
20
+ # ### identity_file
21
+ # The local path to the SSH private key file.
22
+ #
23
+ # ### ssh_options
24
+ # Switches to be passed to the `ssh` command.
25
+
26
+ # ## Tasks
27
+ # Any and all of these settings can be overriden in your `deploy.rb`.
28
+
29
+ # ### environment
30
+ # Make the `:environment` task exist by default. This is meant to be overridden
31
+ # by users.
32
+
33
+ task :environment do
34
+ end
35
+
36
+ # ### init
37
+ # Initializes a new Mina project.
38
+ #
39
+ # $ mina init
40
+
41
+ desc "Creates a sample config file."
42
+ task :init => :environment do
43
+ name = Rake.application.name
44
+ config_file = Rake.application.rakefile
45
+
46
+ unless config_file.to_s.empty?
47
+ print_str "! You already have #{config_file}."
48
+ exit 8
49
+ end
50
+
51
+ outfile = './config/deploy.rb'
52
+ require 'fileutils'
53
+ FileUtils.mkdir_p './config'
54
+ FileUtils.cp Mina.root_path('data/deploy.rb'), outfile
55
+
56
+ print_str "-----> Created #{outfile}"
57
+ print_str "Edit this file, then run `#{name} setup` after."
58
+ end
59
+
60
+ task :default => :help
61
+
62
+ module HelpHelpers
63
+ def get_tasks(&blk)
64
+ Rake.application.tasks.select &blk
65
+ end
66
+
67
+ def print_tasks(tasks, width=nil)
68
+ name = Rake.application.name
69
+
70
+ width ||= tasks.map { |t| t.name_with_args.length }.max || 10
71
+ tasks.each do |t|
72
+ if t.comment
73
+ puts " #{name} %-#{width}s # %s" % [ t.name_with_args, t.comment ]
74
+ else
75
+ puts " #{name} %s" % [ t.name_with_args ]
76
+ end
77
+ end
78
+ end
79
+
80
+ SYSTEM_TASKS = %w[help tasks init]
81
+ def system_tasks() get_tasks { |t| SYSTEM_TASKS.include? t.name }; end
82
+ def top_tasks() get_tasks { |t| ! t.name.include?(':') && t.comment && !system_tasks.include?(t) }; end
83
+ def sub_tasks() get_tasks { |t| t.name.include?(':') }; end
84
+
85
+ def show_task_help(options={})
86
+ puts "Basic usage:"
87
+ print_tasks system_tasks
88
+
89
+ if top_tasks.any?
90
+ puts "\nServer tasks:"
91
+ print_tasks top_tasks
92
+ end
93
+
94
+ if sub_tasks.any? && options[:full]
95
+ puts "\nMore tasks:"
96
+ print_tasks sub_tasks
97
+ end
98
+ end
99
+ end
100
+
101
+ extend HelpHelpers
102
+
103
+ # ### help
104
+ # Shows the help screen.
105
+
106
+ desc "Show help."
107
+ task :help do
108
+ name = Rake.application.name
109
+
110
+ puts "#{name} - Really fast server deployment and automation tool\n\n"
111
+ puts "Options:"
112
+
113
+ opts = [
114
+ [ "-h, --help", "Show help" ],
115
+ [ "-V, --version", "Show program version" ],
116
+ [ "-v, --verbose", "Show commands as they happen" ],
117
+ [ "-S, --simulate", "Run in simulation mode" ],
118
+ [ "-t, --trace", "Show backtraces when errors occur" ],
119
+ [ "-f FILE", "Use FILE as the deploy configuration" ]
120
+ ]
121
+ opts.each { |args| puts " %-17s %s" % args }
122
+ puts ""
123
+
124
+ show_task_help
125
+
126
+ unless Rake.application.have_rakefile
127
+ puts ""
128
+ puts "Run this command in a project with a 'config/deploy.rb' file to see more options."
129
+ end
130
+
131
+ puts ""
132
+ puts "All of Rake's options are also available as '#{name}' options. See 'rake --help'"
133
+ puts "for more information."
134
+ exit
135
+ end
136
+
137
+ # ### tasks
138
+ # Display all tasks in a nice table.
139
+ #
140
+ # $ mina tasks
141
+
142
+ desc "Show all tasks."
143
+ task :tasks do
144
+ show_task_help :full => true
145
+ end