mina-traackr 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +10 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +12 -0
  4. data/CONTRIBUTING.md +124 -0
  5. data/Gemfile +10 -0
  6. data/HISTORY.md +304 -0
  7. data/LICENSE +23 -0
  8. data/Makefile +29 -0
  9. data/Notes.md +72 -0
  10. data/Rakefile +20 -0
  11. data/Readme.md +1009 -0
  12. data/bin/mina +65 -0
  13. data/data/deploy.rb +74 -0
  14. data/data/deploy.sh.erb +120 -0
  15. data/lib/mina.rb +23 -0
  16. data/lib/mina/bundler.rb +44 -0
  17. data/lib/mina/chruby.rb +49 -0
  18. data/lib/mina/default.rb +144 -0
  19. data/lib/mina/deploy.rb +138 -0
  20. data/lib/mina/deploy_helpers.rb +34 -0
  21. data/lib/mina/exec_helpers.rb +104 -0
  22. data/lib/mina/foreman.rb +78 -0
  23. data/lib/mina/git.rb +62 -0
  24. data/lib/mina/helpers.rb +383 -0
  25. data/lib/mina/output_helpers.rb +92 -0
  26. data/lib/mina/rails.rb +206 -0
  27. data/lib/mina/rake.rb +9 -0
  28. data/lib/mina/rbenv.rb +47 -0
  29. data/lib/mina/rvm.rb +88 -0
  30. data/lib/mina/settings.rb +32 -0
  31. data/lib/mina/ssh_helpers.rb +122 -0
  32. data/lib/mina/tools.rb +20 -0
  33. data/lib/mina/version.rb +5 -0
  34. data/lib/mina/whenever.rb +27 -0
  35. data/manual/index.md +15 -0
  36. data/manual/modules.md +2 -0
  37. data/mina.gemspec +17 -0
  38. data/spec/command_helper.rb +52 -0
  39. data/spec/commands/cleanup_spec.rb +16 -0
  40. data/spec/commands/command_spec.rb +71 -0
  41. data/spec/commands/custom_config_spec.rb +20 -0
  42. data/spec/commands/deploy_spec.rb +40 -0
  43. data/spec/commands/outside_project_spec.rb +35 -0
  44. data/spec/commands/real_deploy_spec.rb +54 -0
  45. data/spec/commands/ssh_spec.rb +14 -0
  46. data/spec/commands/verbose_spec.rb +21 -0
  47. data/spec/dsl/invoke_spec.rb +33 -0
  48. data/spec/dsl/queue_spec.rb +49 -0
  49. data/spec/dsl/settings_in_rake_spec.rb +39 -0
  50. data/spec/dsl/settings_spec.rb +55 -0
  51. data/spec/dsl/to_spec.rb +20 -0
  52. data/spec/fixtures/custom_file_env/custom_deploy.rb +15 -0
  53. data/spec/fixtures/empty_env/config/deploy.rb +15 -0
  54. data/spec/helpers/output_helper_spec.rb +38 -0
  55. data/spec/spec_helper.rb +21 -0
  56. data/support/Readme-footer.md +32 -0
  57. data/support/Readme-header.md +17 -0
  58. data/support/guide.md +297 -0
  59. data/support/index.html +53 -0
  60. data/support/to_md.rb +11 -0
  61. data/test_env/config/deploy.rb +72 -0
  62. metadata +157 -0
@@ -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
62
+ end
63
+ end
64
+ end
65
+
@@ -0,0 +1,74 @@
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
+ # Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
19
+ # They will be linked in the 'deploy:link_shared_paths' step.
20
+ set :shared_paths, ['config/database.yml', 'log']
21
+
22
+ # Optional settings:
23
+ # set :user, 'foobar' # Username in the server to SSH to.
24
+ # set :port, '30000' # SSH port number.
25
+
26
+ # This task is the environment that is loaded for most commands, such as
27
+ # `mina deploy` or `mina rake`.
28
+ task :environment do
29
+ # If you're using rbenv, use this to load the rbenv environment.
30
+ # Be sure to commit your .rbenv-version to your repository.
31
+ # invoke :'rbenv:load'
32
+
33
+ # For those using RVM, use this to load an RVM version@gemset.
34
+ # invoke :'rvm:use[ruby-1.9.3-p125@default]'
35
+ end
36
+
37
+ # Put any custom mkdir's in here for when `mina setup` is ran.
38
+ # For Rails apps, we'll make some of the shared paths that are shared between
39
+ # all releases.
40
+ task :setup => :environment do
41
+ queue! %[mkdir -p "#{deploy_to}/shared/log"]
42
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
43
+
44
+ queue! %[mkdir -p "#{deploy_to}/shared/config"]
45
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
46
+
47
+ queue! %[touch "#{deploy_to}/shared/config/database.yml"]
48
+ queue %[echo "-----> Be sure to edit '#{deploy_to}/shared/config/database.yml'."]
49
+ end
50
+
51
+ desc "Deploys the current version to the server."
52
+ task :deploy => :environment do
53
+ deploy do
54
+ # Put things that will set up an empty directory into a fully set-up
55
+ # instance of your project.
56
+ invoke :'git:clone'
57
+ invoke :'deploy:link_shared_paths'
58
+ invoke :'bundle:install'
59
+ invoke :'rails:db_migrate'
60
+ invoke :'rails:assets_precompile'
61
+
62
+ to :launch do
63
+ queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
64
+ end
65
+ end
66
+ end
67
+
68
+ # For help in making your deploy script, see the Mina documentation:
69
+ #
70
+ # - http://nadarei.co/mina
71
+ # - http://nadarei.co/mina/tasks
72
+ # - http://nadarei.co/mina/settings
73
+ # - http://nadarei.co/mina/helpers
74
+
@@ -0,0 +1,120 @@
1
+ <%
2
+ prepare = commands(:default).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
3
+ build = commands(:build).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
4
+ launch = commands(:launch).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
5
+ clean = commands(:clean).map { |s| "(\n\n#{indent 2, s}\n\n)" }.join(" && ")
6
+ %>
7
+ #!/usr/bin/env bash
8
+
9
+ # Go to the deploy path
10
+ cd "<%= deploy_to %>" || (
11
+ echo "! ERROR: not set up."
12
+ echo "The path '<%= deploy_to %>' is not accessible on the server."
13
+ echo "You may need to run 'mina setup' first."
14
+ false
15
+ ) || exit 15
16
+
17
+ # Check releases path
18
+ if [ ! -d "<%= releases_path %>" ]; then
19
+ echo "! ERROR: not set up."
20
+ echo "The directory '<%= releases_path %>' does not exist on the server."
21
+ echo "You may need to run 'mina setup' first."
22
+ exit 16
23
+ fi
24
+
25
+ # Check lockfile
26
+ if [ -e "<%= lock_file %>" ]; then
27
+ echo "! ERROR: another deployment is ongoing."
28
+ echo "The file '<%= lock_file %>' was found."
29
+ echo "If no other deployment is ongoing, delete the file to continue."
30
+ exit 17
31
+ fi
32
+
33
+ # Determine $previous_path and other variables
34
+ [ -h "<%= current_path %>" ] && [ -d "<%= current_path %>" ] && previous_path=$(cd "<%= current_path %>" >/dev/null && pwd -LP)
35
+ build_path="./tmp/build-`date +%s`$RANDOM"
36
+ version=$((`cat "<%= deploy_to %>/last_version" 2>/dev/null`+1))
37
+ release_path="<%= releases_path %>/$version"
38
+
39
+ # Sanity check
40
+ if [ -e "$build_path" ]; then
41
+ echo "! ERROR: Path already exists."
42
+ exit 18
43
+ fi
44
+
45
+ # Bootstrap script (in deployer)
46
+ (
47
+ echo "-----> Creating a temporary build path"
48
+ <%= echo_cmd %[touch "#{lock_file}"] %> &&
49
+ <%= echo_cmd %[mkdir -p "$build_path"] %> &&
50
+ <%= echo_cmd %[cd "$build_path"] %> &&
51
+ (
52
+ <%= indent 4, (prepare.empty? ? "true" : prepare) %>
53
+ ) &&
54
+ echo "-----> Deploy finished"
55
+ ) &&
56
+
57
+ #
58
+ # Build
59
+ (
60
+ echo "-----> Building"
61
+ echo "-----> Moving build to $release_path"
62
+ <%= echo_cmd %[mv "$build_path" "$release_path"] %> &&
63
+ <%= echo_cmd %[cd "$release_path"] %> &&
64
+ (
65
+ <%= indent 4, (build.empty? ? "true" : build) %>
66
+ ) &&
67
+ echo "-----> Build finished"
68
+
69
+ ) &&
70
+
71
+ #
72
+ # Launching
73
+ # Rename to the real release path, then symlink 'current'
74
+ (
75
+ echo "-----> Launching"
76
+ echo "-----> Updating the <%= current_path %> symlink" &&
77
+ <%= echo_cmd %[ln -nfs "$release_path" "#{current_path}"] %>
78
+ ) &&
79
+
80
+ # ============================
81
+ # === Start up serve => (in deployer)
82
+ (
83
+ echo "-----> Launching"
84
+ <%= echo_cmd %[cd "$release_path"] %>
85
+ <%= indent 2, (launch.empty? ? "true" : launch) %>
86
+ ) &&
87
+
88
+ # ============================
89
+ # === Complete & unlock
90
+ (
91
+ rm -f "<%= lock_file %>"
92
+ echo "$version" > "./last_version"
93
+ echo "-----> Done. Deployed v$version"
94
+ ) ||
95
+
96
+ # ============================
97
+ # === Failed deployment
98
+ (
99
+ echo "! ERROR: Deploy failed."
100
+
101
+ <%= indent 2, clean %>
102
+
103
+ echo "-----> Cleaning up build"
104
+ [ -e "$build_path" ] && (
105
+ <%= echo_cmd %[rm -rf "$build_path"] %>
106
+ )
107
+ [ -e "$release_path" ] && (
108
+ echo "Deleting release"
109
+ <%= echo_cmd %[rm -rf "$release_path"] %>
110
+ )
111
+ (
112
+ echo "Unlinking current"
113
+ [ -n "$previous_path" ] && <%= echo_cmd %[ln -nfs "$previous_path" "#{current_path}"] %>
114
+ )
115
+
116
+ # Unlock
117
+ <%= echo_cmd %[rm -f "#{lock_file}"] %>
118
+ echo "OK"
119
+ exit 19
120
+ )
@@ -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,44 @@
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_options
23
+ # Sets the options for installing gems via Bundler.
24
+
25
+ set_default :bundle_options, lambda { %{--without development:test --path "#{bundle_path}" --binstubs bin/ --deployment} }
26
+
27
+ # ## Deploy tasks
28
+ # These tasks are meant to be invoked inside deploy scripts, not invoked on
29
+ # their own.
30
+
31
+ namespace :bundle do
32
+ # ### bundle:install
33
+ # Installs gems.
34
+ desc "Install gem dependencies using Bundler."
35
+ task :install do
36
+ queue %{
37
+ echo "-----> Installing gem dependencies using Bundler"
38
+ #{echo_cmd %[mkdir -p "#{deploy_to}/#{shared_path}/bundle"]}
39
+ #{echo_cmd %[mkdir -p "#{File.dirname bundle_path}"]}
40
+ #{echo_cmd %[ln -s "#{deploy_to}/#{shared_path}/bundle" "#{bundle_path}"]}
41
+ #{echo_cmd %[#{bundle_bin} install #{bundle_options}]}
42
+ }
43
+ end
44
+ 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,144 @@
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
+ end
135
+
136
+ # ### tasks
137
+ # Display all tasks in a nice table.
138
+ #
139
+ # $ mina tasks
140
+
141
+ desc "Show all tasks."
142
+ task :tasks do
143
+ show_task_help :full => true
144
+ end