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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +16 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +1156 -0
- data/Gemfile +2 -8
- data/{CHANGELOG.md → PRE_1_CHANGELOG.md} +0 -0
- data/Rakefile +2 -18
- data/Readme.md +39 -1116
- data/bin/mina +1 -62
- data/data/deploy.rb +19 -46
- data/data/deploy.sh.erb +22 -23
- data/docs/Readme.md +8 -0
- data/docs/command_line_options.md +33 -0
- data/docs/deploying.md +97 -0
- data/docs/faq.md +1 -0
- data/docs/getting_started.md +44 -0
- data/docs/migrating.md +30 -0
- data/docs/writing_your_own_tasks.md +117 -0
- data/lib/Minafile +3 -0
- data/lib/mina.rb +30 -18
- data/lib/mina/application.rb +74 -0
- data/lib/mina/backend/local.rb +22 -0
- data/lib/mina/backend/remote.rb +42 -0
- data/lib/mina/commands.rb +45 -0
- data/lib/mina/configuration.rb +36 -0
- data/lib/mina/dsl.rb +47 -0
- data/lib/mina/helpers/internal.rb +29 -0
- data/lib/mina/helpers/output.rb +42 -0
- data/lib/mina/runner.rb +39 -0
- data/lib/mina/runner/exec.rb +15 -0
- data/lib/mina/runner/pretty.rb +53 -0
- data/lib/mina/runner/printer.rb +17 -0
- data/lib/mina/runner/system.rb +15 -0
- data/lib/mina/version.rb +1 -3
- data/mina.gemspec +27 -16
- data/spec/lib/mina/application_spec.rb +39 -0
- data/spec/lib/mina/backend/local_spec.rb +16 -0
- data/spec/lib/mina/backend/remote_spec.rb +17 -0
- data/spec/lib/mina/commands_spec.rb +93 -0
- data/spec/lib/mina/configuration_spec.rb +52 -0
- data/spec/lib/mina/helpers/internal_spec.rb +50 -0
- data/spec/lib/mina/helpers/output_spec.rb +48 -0
- data/spec/lib/mina/runner_spec.rb +36 -0
- data/spec/lib/mina_spec.rb +7 -0
- data/spec/spec_helper.rb +13 -21
- data/spec/support/run_helper.rb +36 -0
- data/tasks/mina/bundler.rb +15 -0
- data/tasks/mina/chruby.rb +19 -0
- data/tasks/mina/default.rb +36 -0
- data/tasks/mina/deploy.rb +85 -0
- data/tasks/mina/git.rb +36 -0
- data/tasks/mina/install.rb +18 -0
- data/tasks/mina/rails.rb +108 -0
- data/tasks/mina/rbenv.rb +15 -0
- data/tasks/mina/rvm.rb +39 -0
- data/tasks/mina/ry.rb +26 -0
- data/test_env/config/deploy.rb +44 -72
- metadata +82 -59
- data/.travis.yml +0 -21
- data/CONTRIBUTING.md +0 -124
- data/HISTORY.md +0 -394
- data/Makefile +0 -32
- data/Notes.md +0 -70
- data/lib/mina/bundler.rb +0 -49
- data/lib/mina/chruby.rb +0 -49
- data/lib/mina/default.rb +0 -158
- data/lib/mina/deploy.rb +0 -160
- data/lib/mina/deploy_helpers.rb +0 -34
- data/lib/mina/exec_helpers.rb +0 -111
- data/lib/mina/foreman.rb +0 -83
- data/lib/mina/git.rb +0 -69
- data/lib/mina/helpers.rb +0 -408
- data/lib/mina/local_helpers.rb +0 -97
- data/lib/mina/npm.rb +0 -89
- data/lib/mina/output_helpers.rb +0 -92
- data/lib/mina/rails.rb +0 -245
- data/lib/mina/rake.rb +0 -10
- data/lib/mina/rbenv.rb +0 -47
- data/lib/mina/rvm.rb +0 -88
- data/lib/mina/ry.rb +0 -55
- data/lib/mina/settings.rb +0 -32
- data/lib/mina/ssh_helpers.rb +0 -125
- data/lib/mina/tools.rb +0 -20
- data/lib/mina/whenever.rb +0 -51
- data/manual/index.md +0 -15
- data/manual/modules.md +0 -2
- data/spec/command_helper.rb +0 -52
- data/spec/commands/cleanup_spec.rb +0 -16
- data/spec/commands/command_spec.rb +0 -71
- data/spec/commands/custom_config_spec.rb +0 -20
- data/spec/commands/deploy_spec.rb +0 -40
- data/spec/commands/outside_project_spec.rb +0 -35
- data/spec/commands/real_deploy_spec.rb +0 -56
- data/spec/commands/ssh_spec.rb +0 -14
- data/spec/commands/verbose_spec.rb +0 -21
- data/spec/dsl/invoke_spec.rb +0 -49
- data/spec/dsl/queue_spec.rb +0 -49
- data/spec/dsl/settings_in_rake_spec.rb +0 -39
- data/spec/dsl/settings_spec.rb +0 -61
- data/spec/dsl/to_spec.rb +0 -20
- data/spec/fixtures/custom_file_env/custom_deploy.rb +0 -15
- data/spec/fixtures/empty_env/config/deploy.rb +0 -15
- data/spec/helpers/exec_helper_spec.rb +0 -19
- data/spec/helpers/local_helper_spec.rb +0 -70
- data/spec/helpers/output_helper_spec.rb +0 -38
- data/support/Readme-footer.md +0 -31
- data/support/Readme-header.md +0 -16
- data/support/guide.md +0 -297
- data/support/index.html +0 -53
- data/support/third_party_modules.md +0 -23
- data/support/to_md.rb +0 -11
data/docs/migrating.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Migrating from 0.3.x to 1.0
|
2
|
+
--------------------
|
3
|
+
# DSL
|
4
|
+
|
5
|
+
## old
|
6
|
+
* `queue` -> `command` # adds command to queue
|
7
|
+
* `queue!` -> `command` # it will output the command if verbose is true
|
8
|
+
* `to` -> `on` # changes queue name
|
9
|
+
* `in_directory` -> `in_path` # wraps commands to be run in specified path
|
10
|
+
|
11
|
+
## new
|
12
|
+
* `run` # runs commands on a specified backend
|
13
|
+
* `comment` # adds a 'echo -----> #{command}' to queue
|
14
|
+
|
15
|
+
**Other commands have been removed!**
|
16
|
+
|
17
|
+
# Setting variables
|
18
|
+
|
19
|
+
## same
|
20
|
+
* `set` # remained for setting variables
|
21
|
+
|
22
|
+
## new
|
23
|
+
* `fetch` # **ALL** variables now need to be fetched with `fetch`. Removed `method_missing`
|
24
|
+
* `set?`
|
25
|
+
* `ensure!`
|
26
|
+
|
27
|
+
# Deploy variables
|
28
|
+
|
29
|
+
All `*_path` variables (`:current_path`, `:shared_path`, ...) now include `:deploy_to`
|
30
|
+
* `#{fetch(:deploy_to)}/#{fetch(:current_path)}` -> `fetch(:current_path)`
|
@@ -0,0 +1,117 @@
|
|
1
|
+
Writing your own tasks
|
2
|
+
--------------------
|
3
|
+
|
4
|
+
# Defining tasks
|
5
|
+
|
6
|
+
The file `deploy.rb` is simply a Rakefile invoked by Rake. In fact, `mina` is
|
7
|
+
mostly an alias that invokes Rake to load `deploy.rb`.
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
# Sample config/deploy.rb
|
11
|
+
set :domain, 'your.server.com'
|
12
|
+
|
13
|
+
task :restart do
|
14
|
+
comment 'Restart application'
|
15
|
+
command "passenger-config restart-app --ignore-app-not-running #{deploy_to}"
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
As it's all Rake, you can define tasks that you can invoke using `mina`. In this
|
20
|
+
example, it provides the `mina restart` command.
|
21
|
+
|
22
|
+
The magic of Mina is in the new commands it gives you.
|
23
|
+
|
24
|
+
The `command` command queues up Bash commands to be run on the remote server.
|
25
|
+
If you invoke `mina restart`, it will invoke the task above and run the queued
|
26
|
+
commands on the remote server `your.server.com` via SSH.
|
27
|
+
|
28
|
+
# Workflow
|
29
|
+
|
30
|
+
WIP
|
31
|
+
|
32
|
+
# DSL
|
33
|
+
|
34
|
+
## Helpers
|
35
|
+
|
36
|
+
### invoke
|
37
|
+
Invokes another Rake task.
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
invoke :'git:clone'
|
41
|
+
invoke :restart
|
42
|
+
```
|
43
|
+
|
44
|
+
### command
|
45
|
+
Adds a command to the command queue.
|
46
|
+
|
47
|
+
This queues code to be run on the current queue name (defaults to `:default`).
|
48
|
+
|
49
|
+
``` ruby
|
50
|
+
command 'ls -al' # => [ls -al]
|
51
|
+
```
|
52
|
+
|
53
|
+
### comment
|
54
|
+
Adds a comment to the command queue.
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
comment 'ls -al' # => [echo '-----> ls -al']
|
58
|
+
```
|
59
|
+
|
60
|
+
### run
|
61
|
+
Runs the given block on the defined backend
|
62
|
+
|
63
|
+
``` ruby
|
64
|
+
run :remote do
|
65
|
+
command 'ls -al'
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
### on
|
70
|
+
Change the queue name for the given block. Use this if you have multiple places where commands need to end up. Mainly used in `deploy` task.
|
71
|
+
|
72
|
+
``` ruby
|
73
|
+
on :launch do
|
74
|
+
invoke :restart
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
### in_path
|
79
|
+
Change the path the commands in the given block is run.
|
80
|
+
|
81
|
+
``` ruby
|
82
|
+
in_path('some/new/path') do
|
83
|
+
command 'ls -al' # => cd some/new/path && ls -al
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
## Configuration
|
88
|
+
|
89
|
+
### set
|
90
|
+
Sets configuration variable. Can a value or a proc/lambda.
|
91
|
+
|
92
|
+
``` ruby
|
93
|
+
set :deploy_to -> '/path/to/deploy'
|
94
|
+
```
|
95
|
+
|
96
|
+
### fetch
|
97
|
+
Gets configuration variable. Runs `.call` if callable.
|
98
|
+
Returns nil if not set. If default parameter is passed returns default if not set.
|
99
|
+
|
100
|
+
``` ruby
|
101
|
+
fetch(:deploy_to)
|
102
|
+
fetch(:deploy_to, 'some_default')
|
103
|
+
```
|
104
|
+
|
105
|
+
### set?
|
106
|
+
Checks if a variable is set.
|
107
|
+
|
108
|
+
``` ruby
|
109
|
+
set?(:deploy_to)
|
110
|
+
```
|
111
|
+
|
112
|
+
### ensure!
|
113
|
+
Raises an error if variable is not set
|
114
|
+
|
115
|
+
``` ruby
|
116
|
+
ensure!(:deploy_to)
|
117
|
+
```
|
data/lib/Minafile
ADDED
data/lib/mina.rb
CHANGED
@@ -1,24 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
ROOT = File.expand_path('../../', __FILE__)
|
1
|
+
require 'rake'
|
2
|
+
Rake.application.options.trace = true
|
4
3
|
|
5
|
-
|
4
|
+
require 'pry'
|
5
|
+
# require 'awesome_print'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
autoload :ExecHelpers, 'mina/exec_helpers'
|
12
|
-
autoload :Helpers, 'mina/helpers'
|
13
|
-
autoload :Settings, 'mina/settings'
|
14
|
-
autoload :Tools, 'mina/tools'
|
7
|
+
require 'forwardable'
|
8
|
+
require 'shellwords'
|
9
|
+
require 'singleton'
|
10
|
+
require 'open4'
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
require 'mina/version'
|
13
|
+
require 'mina/configuration'
|
14
|
+
require 'mina/dsl'
|
15
|
+
require 'mina/helpers/output'
|
16
|
+
require 'mina/helpers/internal'
|
17
|
+
require 'mina/commands'
|
18
|
+
require 'mina/runner'
|
19
|
+
require 'mina/runner/pretty'
|
20
|
+
require 'mina/runner/system'
|
21
|
+
require 'mina/runner/exec'
|
22
|
+
require 'mina/runner/printer'
|
23
|
+
require 'mina/backend/local'
|
24
|
+
require 'mina/backend/remote'
|
25
|
+
require 'mina/application'
|
20
26
|
|
21
|
-
|
22
|
-
|
27
|
+
module Mina
|
28
|
+
# Error = Class.new(Exception)
|
29
|
+
# class Failed < Error
|
30
|
+
# attr_accessor :exitstatus
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
def self.root_path(*args)
|
34
|
+
File.join File.expand_path('../../', __FILE__), *args
|
23
35
|
end
|
24
36
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Mina
|
2
|
+
class Application < Rake::Application
|
3
|
+
def initialize
|
4
|
+
super
|
5
|
+
@rakefiles = ['config/deploy.rb', minafile]
|
6
|
+
end
|
7
|
+
|
8
|
+
def name
|
9
|
+
'mina'
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
Rake.application = self
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def sort_options(options)
|
18
|
+
not_applicable_to_mina = %w(quiet silent verbose dry-run)
|
19
|
+
options.reject! do |(switch, *)|
|
20
|
+
switch =~ /--#{Regexp.union(not_applicable_to_mina)}/
|
21
|
+
end
|
22
|
+
|
23
|
+
super.push(version, verbose, simulate, debug_configuration_variables)
|
24
|
+
end
|
25
|
+
|
26
|
+
def top_level_tasks
|
27
|
+
@top_level_tasks << :debug_configuration_variables
|
28
|
+
@top_level_tasks << :run_commands
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def minafile
|
34
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..', 'Minafile'))
|
35
|
+
end
|
36
|
+
|
37
|
+
def version
|
38
|
+
['--version', '-V',
|
39
|
+
'Display the program version.',
|
40
|
+
lambda do |_value|
|
41
|
+
puts "Mina, version v#{Mina::VERSION}"
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
def verbose
|
48
|
+
['--verbose', '-v',
|
49
|
+
'Print more info',
|
50
|
+
lambda do |_value|
|
51
|
+
Mina::Configuration.instance.set(:verbose, true)
|
52
|
+
end
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
def simulate
|
57
|
+
['--simulate', '-s',
|
58
|
+
'Do a simulate run without executing actions',
|
59
|
+
lambda do |_value|
|
60
|
+
Mina::Configuration.instance.set(:simulate, true)
|
61
|
+
end
|
62
|
+
]
|
63
|
+
end
|
64
|
+
|
65
|
+
def debug_configuration_variables
|
66
|
+
['--debug-configuration-variables', '-d',
|
67
|
+
'Display the defined config variables before runnig the tasks.',
|
68
|
+
lambda do |_value|
|
69
|
+
Mina::Configuration.instance.set(:debug_configuration_variables, true)
|
70
|
+
end
|
71
|
+
]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mina
|
2
|
+
module Backend
|
3
|
+
class Local
|
4
|
+
attr_reader :commands, :configuration
|
5
|
+
extend Forwardable
|
6
|
+
def_delegators :configuration, :fetch, :set?
|
7
|
+
|
8
|
+
def initialize(commands)
|
9
|
+
@configuration = Mina::Configuration.instance
|
10
|
+
@commands = commands
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare
|
14
|
+
if fetch(:simulate)
|
15
|
+
['#!/usr/bin/env bash', '# Executing the following:', '#', commands, ' '].join("\n")
|
16
|
+
else
|
17
|
+
Shellwords.escape(commands)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Mina
|
2
|
+
module Backend
|
3
|
+
class Remote
|
4
|
+
attr_reader :commands, :configuration
|
5
|
+
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :configuration, :fetch, :set?
|
8
|
+
|
9
|
+
def initialize(commands)
|
10
|
+
@configuration = Mina::Configuration.instance
|
11
|
+
@commands = commands
|
12
|
+
end
|
13
|
+
|
14
|
+
def prepare
|
15
|
+
if fetch(:simulate)
|
16
|
+
[
|
17
|
+
'#!/usr/bin/env bash', "# Executing the following via '#{ssh}':",
|
18
|
+
'#', commands, ' '
|
19
|
+
].join("\n")
|
20
|
+
else
|
21
|
+
command = Shellwords.escape(commands)
|
22
|
+
[ssh, '--', command].join(' ')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def ssh
|
29
|
+
fail 'No domain set' unless set?(:domain)
|
30
|
+
args = fetch(:domain)
|
31
|
+
args = "#{fetch(:user)}@#{fetch(:domain)}" if set?(:user)
|
32
|
+
args << " -i #{fetch(:identity_file)}" if set?(:identity_file)
|
33
|
+
args << " -p #{fetch(:port)}" if set?(:port)
|
34
|
+
args << ' -A' if set?(:forward_agent)
|
35
|
+
args << " #{fetch(:ssh_options)}" if set?(:ssh_options)
|
36
|
+
args << ' -tt'
|
37
|
+
"ssh #{args}"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Mina
|
2
|
+
class Commands
|
3
|
+
extend Forwardable
|
4
|
+
include Helpers::Internal
|
5
|
+
|
6
|
+
attr_reader :queue
|
7
|
+
attr_accessor :stage
|
8
|
+
def_delegators :queue, :find, :fetch, :process
|
9
|
+
|
10
|
+
def initialize(stage = :default)
|
11
|
+
@stage = stage
|
12
|
+
@queue = Hash.new { |hash, key| hash[key] = [] }
|
13
|
+
end
|
14
|
+
|
15
|
+
def command(code, quiet: false, indent: nil)
|
16
|
+
code = indent(indent, code) if indent
|
17
|
+
queue[stage] << (quiet ? code : echo_cmd(code))
|
18
|
+
end
|
19
|
+
|
20
|
+
def comment(code, indent: nil)
|
21
|
+
if indent
|
22
|
+
queue[stage] << indent(indent, "echo '-----> #{code}'")
|
23
|
+
else
|
24
|
+
queue[stage] << "echo '-----> #{code}'"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def fetch(stage)
|
29
|
+
queue.delete(stage) || []
|
30
|
+
end
|
31
|
+
|
32
|
+
def process(path = nil)
|
33
|
+
if path
|
34
|
+
queue[stage].unshift("echo '$ cd #{path}'") if Mina::Configuration.instance.fetch(:verbose)
|
35
|
+
"(cd #{path} && #{queue[stage].join(' && ')})"
|
36
|
+
else
|
37
|
+
fetch(stage).join("\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def run(backend)
|
42
|
+
Mina::Runner.new(process, backend).run
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mina
|
2
|
+
class Configuration
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
attr_reader :variables
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@variables ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def set(key, value = nil, &block)
|
12
|
+
variables[key] = block || value
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch(key, default = nil)
|
16
|
+
value = ENV[key.to_s] || variables.fetch(key, default)
|
17
|
+
value.respond_to?(:call) ? value.call : value
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove(key)
|
21
|
+
variables.delete(key)
|
22
|
+
end
|
23
|
+
|
24
|
+
def set?(key)
|
25
|
+
!variables.fetch(key, nil).nil?
|
26
|
+
end
|
27
|
+
|
28
|
+
def ensure!(key)
|
29
|
+
fail "#{key} must be defined!" unless set?(key)
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset!
|
33
|
+
@variables = {}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mina/dsl.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Mina
|
2
|
+
module DSL
|
3
|
+
attr_reader :commands
|
4
|
+
|
5
|
+
extend Forwardable
|
6
|
+
def_delegators :configuration, :fetch, :set, :set?, :ensure!
|
7
|
+
def_delegators :commands, :command, :comment
|
8
|
+
|
9
|
+
def configuration
|
10
|
+
Configuration.instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def invoke(task, *args)
|
14
|
+
Rake::Task[task].invoke(*args)
|
15
|
+
Rake::Task[task].reenable
|
16
|
+
end
|
17
|
+
|
18
|
+
def commands
|
19
|
+
@commands ||= Commands.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def run(backend)
|
23
|
+
@commands = Commands.new
|
24
|
+
yield
|
25
|
+
commands.run(backend)
|
26
|
+
end
|
27
|
+
|
28
|
+
def on(stage)
|
29
|
+
old_stage, commands.stage = commands.stage, stage
|
30
|
+
yield
|
31
|
+
commands.stage = old_stage
|
32
|
+
end
|
33
|
+
|
34
|
+
def in_path(path, indent: nil)
|
35
|
+
real_commands = commands
|
36
|
+
@commands = Commands.new
|
37
|
+
yield
|
38
|
+
real_commands.command(commands.process(path), quiet: true, indent: indent)
|
39
|
+
@commands = real_commands
|
40
|
+
end
|
41
|
+
|
42
|
+
def deploy(&block)
|
43
|
+
command deploy_script(&block), quiet: true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
extend Mina::DSL
|