mina 0.3.8 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +16 -0
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +1156 -0
  5. data/Gemfile +2 -8
  6. data/{CHANGELOG.md → PRE_1_CHANGELOG.md} +0 -0
  7. data/Rakefile +2 -18
  8. data/Readme.md +39 -1116
  9. data/bin/mina +1 -62
  10. data/data/deploy.rb +19 -46
  11. data/data/deploy.sh.erb +22 -23
  12. data/docs/Readme.md +8 -0
  13. data/docs/command_line_options.md +33 -0
  14. data/docs/deploying.md +97 -0
  15. data/docs/faq.md +1 -0
  16. data/docs/getting_started.md +44 -0
  17. data/docs/migrating.md +30 -0
  18. data/docs/writing_your_own_tasks.md +117 -0
  19. data/lib/Minafile +3 -0
  20. data/lib/mina.rb +30 -18
  21. data/lib/mina/application.rb +74 -0
  22. data/lib/mina/backend/local.rb +22 -0
  23. data/lib/mina/backend/remote.rb +42 -0
  24. data/lib/mina/commands.rb +45 -0
  25. data/lib/mina/configuration.rb +36 -0
  26. data/lib/mina/dsl.rb +47 -0
  27. data/lib/mina/helpers/internal.rb +29 -0
  28. data/lib/mina/helpers/output.rb +42 -0
  29. data/lib/mina/runner.rb +39 -0
  30. data/lib/mina/runner/exec.rb +15 -0
  31. data/lib/mina/runner/pretty.rb +53 -0
  32. data/lib/mina/runner/printer.rb +17 -0
  33. data/lib/mina/runner/system.rb +15 -0
  34. data/lib/mina/version.rb +1 -3
  35. data/mina.gemspec +27 -16
  36. data/spec/lib/mina/application_spec.rb +39 -0
  37. data/spec/lib/mina/backend/local_spec.rb +16 -0
  38. data/spec/lib/mina/backend/remote_spec.rb +17 -0
  39. data/spec/lib/mina/commands_spec.rb +93 -0
  40. data/spec/lib/mina/configuration_spec.rb +52 -0
  41. data/spec/lib/mina/helpers/internal_spec.rb +50 -0
  42. data/spec/lib/mina/helpers/output_spec.rb +48 -0
  43. data/spec/lib/mina/runner_spec.rb +36 -0
  44. data/spec/lib/mina_spec.rb +7 -0
  45. data/spec/spec_helper.rb +13 -21
  46. data/spec/support/run_helper.rb +36 -0
  47. data/tasks/mina/bundler.rb +15 -0
  48. data/tasks/mina/chruby.rb +19 -0
  49. data/tasks/mina/default.rb +36 -0
  50. data/tasks/mina/deploy.rb +85 -0
  51. data/tasks/mina/git.rb +36 -0
  52. data/tasks/mina/install.rb +18 -0
  53. data/tasks/mina/rails.rb +108 -0
  54. data/tasks/mina/rbenv.rb +15 -0
  55. data/tasks/mina/rvm.rb +39 -0
  56. data/tasks/mina/ry.rb +26 -0
  57. data/test_env/config/deploy.rb +44 -72
  58. metadata +82 -59
  59. data/.travis.yml +0 -21
  60. data/CONTRIBUTING.md +0 -124
  61. data/HISTORY.md +0 -394
  62. data/Makefile +0 -32
  63. data/Notes.md +0 -70
  64. data/lib/mina/bundler.rb +0 -49
  65. data/lib/mina/chruby.rb +0 -49
  66. data/lib/mina/default.rb +0 -158
  67. data/lib/mina/deploy.rb +0 -160
  68. data/lib/mina/deploy_helpers.rb +0 -34
  69. data/lib/mina/exec_helpers.rb +0 -111
  70. data/lib/mina/foreman.rb +0 -83
  71. data/lib/mina/git.rb +0 -69
  72. data/lib/mina/helpers.rb +0 -408
  73. data/lib/mina/local_helpers.rb +0 -97
  74. data/lib/mina/npm.rb +0 -89
  75. data/lib/mina/output_helpers.rb +0 -92
  76. data/lib/mina/rails.rb +0 -245
  77. data/lib/mina/rake.rb +0 -10
  78. data/lib/mina/rbenv.rb +0 -47
  79. data/lib/mina/rvm.rb +0 -88
  80. data/lib/mina/ry.rb +0 -55
  81. data/lib/mina/settings.rb +0 -32
  82. data/lib/mina/ssh_helpers.rb +0 -125
  83. data/lib/mina/tools.rb +0 -20
  84. data/lib/mina/whenever.rb +0 -51
  85. data/manual/index.md +0 -15
  86. data/manual/modules.md +0 -2
  87. data/spec/command_helper.rb +0 -52
  88. data/spec/commands/cleanup_spec.rb +0 -16
  89. data/spec/commands/command_spec.rb +0 -71
  90. data/spec/commands/custom_config_spec.rb +0 -20
  91. data/spec/commands/deploy_spec.rb +0 -40
  92. data/spec/commands/outside_project_spec.rb +0 -35
  93. data/spec/commands/real_deploy_spec.rb +0 -56
  94. data/spec/commands/ssh_spec.rb +0 -14
  95. data/spec/commands/verbose_spec.rb +0 -21
  96. data/spec/dsl/invoke_spec.rb +0 -49
  97. data/spec/dsl/queue_spec.rb +0 -49
  98. data/spec/dsl/settings_in_rake_spec.rb +0 -39
  99. data/spec/dsl/settings_spec.rb +0 -61
  100. data/spec/dsl/to_spec.rb +0 -20
  101. data/spec/fixtures/custom_file_env/custom_deploy.rb +0 -15
  102. data/spec/fixtures/empty_env/config/deploy.rb +0 -15
  103. data/spec/helpers/exec_helper_spec.rb +0 -19
  104. data/spec/helpers/local_helper_spec.rb +0 -70
  105. data/spec/helpers/output_helper_spec.rb +0 -38
  106. data/support/Readme-footer.md +0 -31
  107. data/support/Readme-header.md +0 -16
  108. data/support/guide.md +0 -297
  109. data/support/index.html +0 -53
  110. data/support/third_party_modules.md +0 -23
  111. data/support/to_md.rb +0 -11
data/Makefile DELETED
@@ -1,32 +0,0 @@
1
- Readme.md: \
2
- support/Readme-header.md \
3
- support/guide.md \
4
- support/helpers.md \
5
- support/modules.md \
6
- support/third_party_modules.md \
7
- support/Readme-footer.md
8
- cat $^ > $@
9
-
10
- support/modules.md: \
11
- lib/mina/bundler.rb \
12
- lib/mina/default.rb \
13
- lib/mina/deploy.rb \
14
- lib/mina/foreman.rb \
15
- lib/mina/git.rb \
16
- lib/mina/rails.rb \
17
- lib/mina/rbenv.rb \
18
- lib/mina/rvm.rb \
19
- lib/mina/npm.rb \
20
- lib/mina/tools.rb \
21
- lib/mina/whenever.rb
22
- cat $^ | ruby support/to_md.rb > $@
23
-
24
- support/helpers.md: \
25
- lib/mina/helpers.rb \
26
- lib/mina/deploy_helpers.rb
27
- cat $^ | ruby support/to_md.rb > $@
28
-
29
- clean:
30
- rm Readme.md support/modules.md support/helpers.md
31
-
32
- .PHONY: clean
data/Notes.md DELETED
@@ -1,70 +0,0 @@
1
- Readme
2
- ------
3
-
4
- The readme file is auto-generated using make.
5
-
6
- $ make Readme.md
7
-
8
- Documentation
9
- -------------
10
-
11
- Please consult the [project documentation](http://mina-deploy.github.io/mina) for full
12
- details.
13
-
14
- Problems or suggestions? File issues at the [issue tracker][issues].
15
-
16
- Documentation sources
17
- ---------------------
18
-
19
- See [mina-deploy/mina-docs](https://github.com/mina-deploy/mina-docs) for the sources of
20
- the documentation site. Please ensure that docs there are in sync with the
21
- features here.
22
-
23
- Development & testing
24
- ---------------------
25
-
26
- To test out stuff in development:
27
-
28
- ``` sh
29
- # Run specs
30
- $ rspec
31
- $ rspec -t ssh # Run SSH tests (read test_env/config/deploy.rb first)
32
- $ rake=10 rspec
33
- $ rake=0.9 rspec
34
- $ rake=0.8 rspec
35
-
36
- # Alias your 'mina' to use it everywhere
37
- $ alias mina="`pwd -LP`/bin/mina"
38
- ```
39
-
40
- ### Doing test deploys
41
-
42
- Try out the test environment:
43
-
44
- ``` sh
45
- $ cd test_env
46
- $ mina deploy --simulate
47
- $ mina deploy
48
-
49
- # There's an rspec task for it too
50
- $ rspec -t ssh
51
- ```
52
-
53
- ### Gem management
54
-
55
- ``` sh
56
- # To release the gem:
57
- # Install the Git changelog helper: https://gist.github.com/2880525
58
- # Then:
59
-
60
- $ vim lib/mina/version.rb
61
- $ git clog -w
62
- $ vim HISTORY.md
63
- $ git commit -m "Release v0.8.4."
64
- $ rake release
65
-
66
- # Please don't forget to tag the release in github.com/nadarei/mina-docs too!
67
-
68
- $ rake build # Builds the gem file
69
- $ rake install # Installs the gem locally
70
- ```
data/lib/mina/bundler.rb DELETED
@@ -1,49 +0,0 @@
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
- echo "-----> 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
data/lib/mina/chruby.rb DELETED
@@ -1,49 +0,0 @@
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 DELETED
@@ -1,158 +0,0 @@
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
- # ### env_vars
27
- # Environment variables to be passed to `ssh` command. (e.g. "foo=bar baz=1")
28
-
29
- # ## Tasks
30
- # Any and all of these settings can be overriden in your `deploy.rb`.
31
-
32
- # ### environment
33
- # Make the `:environment` task exist by default. This is meant to be overridden
34
- # by users.
35
-
36
- task :environment do
37
- end
38
-
39
- # ### init
40
- # Initializes a new Mina project.
41
- #
42
- # $ mina init
43
-
44
- desc "Creates a sample config file."
45
- task :init => :environment do
46
- name = Rake.application.name
47
- config_file = Rake.application.rakefile
48
-
49
- unless config_file.to_s.empty?
50
- print_str "! You already have #{config_file}."
51
- exit 8
52
- end
53
-
54
- outfile = './config/deploy.rb'
55
- require 'fileutils'
56
- FileUtils.mkdir_p './config'
57
- FileUtils.cp Mina.root_path('data/deploy.rb'), outfile
58
-
59
- print_str "-----> Created #{outfile}"
60
- print_str "Edit this file, then run `#{name} setup` after."
61
- end
62
-
63
- task :default => :help
64
-
65
- module HelpHelpers
66
- def get_tasks(&blk)
67
- Rake.application.tasks.select &blk
68
- end
69
-
70
- def print_tasks(tasks, width=nil)
71
- name = Rake.application.name
72
-
73
- width ||= tasks.map { |t| t.name_with_args.length }.max || 10
74
- tasks.each do |t|
75
- if t.comment
76
- puts " #{name} %-#{width}s # %s" % [ t.name_with_args, t.comment ]
77
- else
78
- puts " #{name} %s" % [ t.name_with_args ]
79
- end
80
- end
81
- end
82
-
83
- SYSTEM_TASKS = %w[help tasks init]
84
- def system_tasks() get_tasks { |t| SYSTEM_TASKS.include? t.name }; end
85
- def top_tasks() get_tasks { |t| ! t.name.include?(':') && t.comment && !system_tasks.include?(t) }; end
86
- def sub_tasks() get_tasks { |t| t.name.include?(':') }; end
87
-
88
- def show_task_help(options={})
89
- puts "Basic usage:"
90
- print_tasks system_tasks
91
-
92
- if top_tasks.any?
93
- puts "\nServer tasks:"
94
- print_tasks top_tasks
95
- end
96
-
97
- if sub_tasks.any? && options[:full]
98
- puts "\nMore tasks:"
99
- print_tasks sub_tasks
100
- end
101
- end
102
- end
103
-
104
- extend HelpHelpers
105
-
106
- # ### help
107
- # Shows the help screen.
108
-
109
- desc "Show help."
110
- task :help do
111
- name = Rake.application.name
112
-
113
- puts "#{name} - Really fast server deployment and automation tool\n\n"
114
- puts "Options:"
115
-
116
- opts = [
117
- [ "-h, --help", "Show help" ],
118
- [ "-V, --version", "Show program version" ],
119
- [ "-v, --verbose", "Show commands as they happen" ],
120
- [ "-S, --simulate", "Run in simulation mode" ],
121
- [ "-t, --trace", "Show backtraces when errors occur" ],
122
- [ "-f FILE", "Use FILE as the deploy configuration" ]
123
- ]
124
- opts.each { |args| puts " %-17s %s" % args }
125
- puts ""
126
-
127
- show_task_help
128
-
129
- unless Rake.application.have_rakefile
130
- puts ""
131
- puts "Run this command in a project with a 'config/deploy.rb' file to see more options."
132
- end
133
-
134
- puts ""
135
- puts "All of Rake's options are also available as '#{name}' options. See 'rake --help'"
136
- puts "for more information."
137
- exit
138
- end
139
-
140
- # ### tasks
141
- # Display all tasks in a nice table.
142
- #
143
- # $ mina tasks
144
-
145
- desc "Show all tasks."
146
- task :tasks do
147
- show_task_help :full => true
148
- end
149
-
150
- # ### ssh
151
- # Connects to the server via ssh and cd to deploy_to folder
152
- #
153
- # $ mina ssh
154
-
155
- desc "Open an ssh session to the server and cd to deploy_to folder"
156
- task :ssh do
157
- exec ssh_command + " 'cd #{deploy_to} && exec \$SHELL'"
158
- end
data/lib/mina/deploy.rb DELETED
@@ -1,160 +0,0 @@
1
- # # Modules: Deployment
2
- # This module is automatically loaded for all Mina projects.
3
-
4
- # ## Settings
5
- # Any and all of these settings can be overriden in your `deploy.rb`.
6
-
7
- # ### releases_path
8
- # (default: 'releases')
9
- set_default :releases_path, "releases"
10
-
11
- # ### shared_path
12
- # (default: 'shared')
13
- set_default :shared_path, "shared"
14
-
15
- # ### current_path
16
- # (default: 'current_path')
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')
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)
27
- set_default :keep_releases, 5
28
-
29
- namespace :deploy do
30
- # ## Tasks
31
-
32
- # ### deploy:force_unlock
33
- # Forces a deploy unlock by deleting the lock file.
34
- #
35
- # $ mina deploy:force_unlock
36
- #
37
- # You can also combine that task with `deploy`:
38
- #
39
- # $ mina deploy:force_unlock deploy
40
-
41
- desc "Forces a deploy unlock."
42
- task :force_unlock do
43
- queue %{echo "-----> Unlocking"}
44
- queue echo_cmd %{rm -f "#{deploy_to}/#{lock_file}"}
45
- end
46
-
47
- # ### deploy:link_shared_paths
48
- # Links the shared paths in the `shared_paths` setting.
49
-
50
- desc "Links paths set in :shared_paths."
51
- task :link_shared_paths do
52
- dirs = settings.shared_paths!.map { |file| File.dirname("./#{file}") }.uniq
53
-
54
- cmds = dirs.map do |dir|
55
- echo_cmd %{mkdir -p "#{dir}"}
56
- end
57
-
58
- cmds += shared_paths.map do |file|
59
- [
60
- echo_cmd(%{rm -rf "./#{file}"}),
61
- echo_cmd(%{ln -s "#{deploy_to}/#{shared_path}/#{file}" "./#{file}"})
62
- ]
63
- end
64
-
65
- queue %{
66
- echo "-----> Symlinking shared paths"
67
- #{cmds.flatten.join(" &&\n")}
68
- }
69
- end
70
-
71
- # ### deploy:cleanup
72
- # Cleans up old releases.
73
- #
74
- # By default, the last 5 releases are kept on each server (though you can
75
- # change this with the keep_releases setting). All other deployed revisions
76
- # are removed from the servers."
77
-
78
- desc "Clean up old releases."
79
- task :cleanup do
80
- queue %{
81
- echo "-----> Cleaning up old releases (keeping #{keep_releases!})"
82
- #{echo_cmd %{cd "#{deploy_to!}/#{releases_path!}" || exit 15}}
83
- #{echo_cmd %{count=`ls -1d [0-9]* | sort -rn | wc -l`}}
84
- #{echo_cmd %{remove=$((count > #{keep_releases} ? count - #{keep_releases} : 0))}}
85
- #{echo_cmd %{ls -1d [0-9]* | sort -rn | tail -n $remove | xargs rm -rf {}}}
86
- }
87
- end
88
-
89
- # ### deploy:rollback
90
- # Rollbacks the latest release.
91
- #
92
- # Changes the current link to previous release, and deletes the newest deploy release
93
- # Does NOT rollback the database, use
94
- #
95
- # mina "rake[db:rollback]"
96
- desc "Rollbacks the latest release"
97
- task :rollback => :environment do
98
- queue %[echo "-----> Rolling back to previous release for instance: #{domain}"]
99
-
100
- # Delete existing sym link and create a new symlink pointing to the previous release
101
- queue %[echo -n "-----> Creating new symlink from the previous release: "]
102
- queue %[ls -Art "#{deploy_to}/releases" | sort | tail -n 2 | head -n 1]
103
- queue! %[ls -Art "#{deploy_to}/releases" | sort | tail -n 2 | head -n 1 | xargs -I active ln -nfs "#{deploy_to}/releases/active" "#{deploy_to}/current"]
104
-
105
- # Remove latest release folder (current release)
106
- queue %[echo -n "-----> Deleting current release: "]
107
- queue %[ls -Art "#{deploy_to}/releases" | sort | tail -n 1]
108
- queue! %[ls -Art "#{deploy_to}/releases" | sort | tail -n 1 | xargs -I active rm -rf "#{deploy_to}/releases/active"]
109
- end
110
- end
111
-
112
- # ### setup
113
- # Sets up a site's directory structure.
114
-
115
- desc "Sets up a site."
116
- task :setup do
117
- set_default :term_mode, :pretty
118
-
119
- settings.deploy_to!
120
-
121
- user = settings.user? ? "#{settings.user}" : "username"
122
-
123
- queue %{
124
- echo "-----> Setting up #{deploy_to}" && (
125
- #{echo_cmd %{mkdir -p "#{deploy_to}"}} &&
126
- #{echo_cmd %{chown -R `whoami` "#{deploy_to}"}} &&
127
- #{echo_cmd %{chmod g+rx,u+rwx "#{deploy_to}"}} &&
128
- #{echo_cmd %{cd "#{deploy_to}"}} &&
129
- #{echo_cmd %{mkdir -p "#{releases_path}"}} &&
130
- #{echo_cmd %{chmod g+rx,u+rwx "#{releases_path}"}} &&
131
- #{echo_cmd %{mkdir -p "#{shared_path}"}} &&
132
- #{echo_cmd %{chmod g+rx,u+rwx "#{shared_path}"}} &&
133
- echo "" &&
134
- #{echo_cmd %{ls -la "#{deploy_to}"}} &&
135
- echo "" &&
136
- echo "-----> Done."
137
- ) || (
138
- echo "! ERROR: Setup failed."
139
- echo "! Ensure that the path '#{deploy_to}' is accessible to the SSH user."
140
- echo "! Try doing:"
141
- echo "! sudo mkdir -p \\"#{deploy_to}\\" && sudo chown -R #{user} \\"#{deploy_to}\\""
142
- )
143
- }
144
- end
145
-
146
- # ### run[]
147
- # Runs a command on a server.
148
- #
149
- # $ mina "run[tail -f logs.txt]"
150
-
151
- desc "Runs a command in the server."
152
- task :run, [:command] => [:environment] do |t, args|
153
- command = args[:command]
154
- unless command
155
- puts %[You need to provide a command. Try: mina "run[ls -la]"]
156
- exit 1
157
- end
158
-
159
- queue %[cd #{deploy_to!} && #{command}]
160
- end