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/spec/dsl/settings_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Settings' do
|
4
|
-
describe 'instances' do
|
5
|
-
before :each do
|
6
|
-
@settings = Mina::Settings.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'setting/getting should work' do
|
10
|
-
@settings.domain = '192.168.1.1'
|
11
|
-
|
12
|
-
expect(@settings.domain).to eq('192.168.1.1')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'question mark should work' do
|
16
|
-
@settings.deploy_to = '/var/www/there'
|
17
|
-
|
18
|
-
expect(@settings.deploy_to?).to be_truthy
|
19
|
-
expect(@settings.foobar?).to be_falsey
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'question mark should work with nils' do
|
23
|
-
@settings.deploy_to = nil
|
24
|
-
|
25
|
-
expect(@settings.deploy_to?).to be_truthy
|
26
|
-
expect(@settings.foobar?).to be_falsey
|
27
|
-
end
|
28
|
-
|
29
|
-
it '||= should work (1)' do
|
30
|
-
@settings.x = 2
|
31
|
-
@settings.x ||= 3
|
32
|
-
|
33
|
-
expect(@settings.x).to eq(2)
|
34
|
-
end
|
35
|
-
|
36
|
-
it '||= should work (2)' do
|
37
|
-
@settings.x ||= 3
|
38
|
-
|
39
|
-
expect(@settings.x).to eq(3)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'lambdas should work' do
|
43
|
-
@settings.path = lambda { "/var/www/#{@settings.version}" }
|
44
|
-
@settings.version = '3'
|
45
|
-
|
46
|
-
expect(@settings.path?).to be_truthy
|
47
|
-
expect(@settings.path).to eq("/var/www/3")
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'bangs should check for settings' do
|
51
|
-
expect { @settings.non_existent_setting! }.to raise_error(Mina::Error, /non_existent_setting/)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'bangs should return settings' do
|
55
|
-
@settings.version = 4
|
56
|
-
|
57
|
-
expect(@settings.version!).to eq(4)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
data/spec/dsl/to_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Mina' do
|
4
|
-
it '#to should work' do
|
5
|
-
rake {
|
6
|
-
task :deploy do
|
7
|
-
queue 'git clone'
|
8
|
-
|
9
|
-
to :restart do
|
10
|
-
queue 'touch tmp/restart.txt'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
}
|
14
|
-
|
15
|
-
rake { invoke :deploy }
|
16
|
-
|
17
|
-
expect(rake.commands).to eq(['git clone'])
|
18
|
-
expect(rake.commands(:restart)).to eq(['touch tmp/restart.txt'])
|
19
|
-
end
|
20
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
FileUtils.mkdir_p "#{Dir.pwd}/deploy"
|
3
|
-
|
4
|
-
require 'mina/git'
|
5
|
-
|
6
|
-
set :domain, 'localhost'
|
7
|
-
set :deploy_to, "#{Dir.pwd}/deploy"
|
8
|
-
set :repository, "#{Dir.pwd}"
|
9
|
-
|
10
|
-
desc "Deploys."
|
11
|
-
task :deploy do
|
12
|
-
deploy do
|
13
|
-
invoke :'git:clone'
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
FileUtils.mkdir_p "#{Dir.pwd}/deploy"
|
3
|
-
|
4
|
-
require 'mina/git'
|
5
|
-
|
6
|
-
set :domain, 'localhost'
|
7
|
-
set :deploy_to, "#{Dir.pwd}/deploy"
|
8
|
-
set :repository, "#{Dir.pwd}"
|
9
|
-
|
10
|
-
desc "Deploys."
|
11
|
-
task :deploy do
|
12
|
-
deploy do
|
13
|
-
invoke :'git:clone'
|
14
|
-
end
|
15
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Exec Helpers' do
|
4
|
-
before :each do
|
5
|
-
@exec = Object.new
|
6
|
-
@exec.send :extend, Mina::ExecHelpers
|
7
|
-
|
8
|
-
allow(@exec).to receive(:print_char)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'pretty_system' do
|
12
|
-
@exec.pretty_system "echo 'Hello there'"
|
13
|
-
|
14
|
-
expect(@exec).to have_received(:print_char).
|
15
|
-
with("e").with("r").with("e").with("h").with("t").
|
16
|
-
with(" ").
|
17
|
-
with("o").with("l").with("l").with("e").with("H")
|
18
|
-
end
|
19
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mina::LocalHelpers::Local do
|
4
|
-
describe '.invoke' do
|
5
|
-
let :scope do
|
6
|
-
double("rake_application").tap do |scope|
|
7
|
-
allow(scope).to receive(:settings).and_return(settings)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:settings) { OpenStruct.new }
|
12
|
-
|
13
|
-
it 'uses the pretty system with shell-escaped command when term_mode is set to :pretty and pretty is supported' do
|
14
|
-
settings.term_mode = :pretty
|
15
|
-
cmd = %[echo "hello"]
|
16
|
-
|
17
|
-
allow(described_class).to receive(:pretty_supported?).and_return(true)
|
18
|
-
expect(scope).to receive(:pretty_system).with(Shellwords.escape(cmd)).and_return(0)
|
19
|
-
|
20
|
-
described_class.invoke(cmd, scope)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'does NOT use the pretty system when term_mode is set to :pretty and pretty is NOT supported' do
|
24
|
-
settings.term_mode = :pretty
|
25
|
-
cmd = %[echo "hello"]
|
26
|
-
|
27
|
-
allow(described_class).to receive(:pretty_supported?).and_return(false)
|
28
|
-
expect(scope).not_to receive(:pretty_system)
|
29
|
-
expect(Kernel).to receive(:exec).and_return(0)
|
30
|
-
|
31
|
-
described_class.invoke(cmd, scope)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'returns the sub-shell exit status when using the pretty system' do
|
35
|
-
settings.term_mode = :pretty
|
36
|
-
|
37
|
-
allow(described_class).to receive(:pretty_supported?).and_return(true)
|
38
|
-
allow(scope).to receive(:pretty_system).with("return0").and_return(0)
|
39
|
-
allow(scope).to receive(:pretty_system).with("return13").and_return(13)
|
40
|
-
|
41
|
-
expect(described_class.invoke("return0", scope)).to eq 0
|
42
|
-
expect(described_class.invoke("return13", scope)).to eq 13
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'calls Kernel.exec with non shell-escaped command when term_mode is :exec' do
|
46
|
-
settings.term_mode = :exec
|
47
|
-
cmd = %[echo "hello"]
|
48
|
-
|
49
|
-
expect(Kernel).to receive(:exec).with(cmd).and_return(0)
|
50
|
-
|
51
|
-
described_class.invoke(cmd, scope)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'calls Kernel.system with non shell-escaped command when term_mode is not :pretty nor :exec' do
|
55
|
-
settings.term_mode = nil
|
56
|
-
cmd = %[echo "hello"]
|
57
|
-
|
58
|
-
expect(Kernel).to receive(:system).with(cmd).and_return("hello\n")
|
59
|
-
|
60
|
-
described_class.invoke(cmd, scope)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'returns the sub-shell exit status when using Kernel.system' do
|
64
|
-
settings.term_mode = nil
|
65
|
-
|
66
|
-
expect(described_class.invoke(%[/bin/sh -c 'exit 0'], scope)).to eq 0
|
67
|
-
expect(described_class.invoke(%[/bin/sh -c 'exit 13'], scope)).to eq 13
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Output Helpers' do
|
4
|
-
before :each do
|
5
|
-
@out = Object.new
|
6
|
-
@out.send :extend, Mina::OutputHelpers
|
7
|
-
|
8
|
-
allow(@out).to receive(:print_stdout)
|
9
|
-
allow(@out).to receive(:print_status)
|
10
|
-
allow(@out).to receive(:print_error)
|
11
|
-
allow(@out).to receive(:print_command)
|
12
|
-
allow(@out).to receive(:print_clear)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'print_str to stdout' do
|
16
|
-
@out.print_str "Hello there\n"
|
17
|
-
|
18
|
-
expect(@out).to have_received(:print_stdout).with("Hello there\n")
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'print_str to status' do
|
22
|
-
@out.print_str "-----> Getting password"
|
23
|
-
|
24
|
-
expect(@out).to have_received(:print_status).with("Getting password")
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'print_str to status (2)' do
|
28
|
-
@out.print_str "-> Getting password"
|
29
|
-
|
30
|
-
expect(@out).to have_received(:print_status).with("Getting password")
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'print_str to error' do
|
34
|
-
@out.print_str "! Something went wrong"
|
35
|
-
|
36
|
-
expect(@out).to have_received(:print_error).with("Something went wrong")
|
37
|
-
end
|
38
|
-
end
|
data/support/Readme-footer.md
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
Acknowledgements
|
3
|
-
----------------
|
4
|
-
|
5
|
-
© 2012-2015, Nadarei. Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
6
|
-
|
7
|
-
Mina is authored and maintained by [Rico Sta. Cruz][rsc] and [Michael
|
8
|
-
Galero][mg] with help from its [contributors][c]. It is sponsored by our
|
9
|
-
startup, [Nadarei][nd].
|
10
|
-
|
11
|
-
* [Nadarei](http://nadarei.co) (nadarei.co)
|
12
|
-
* [Github](http://github.com/nadarei) (@nadarei)
|
13
|
-
|
14
|
-
Rico:
|
15
|
-
|
16
|
-
* [My website](http://ricostacruz.com) (ricostacruz.com)
|
17
|
-
* [Github](http://github.com/rstacruz) (@rstacruz)
|
18
|
-
* [Twitter](http://twitter.com/rstacruz) (@rstacruz)
|
19
|
-
|
20
|
-
Michael:
|
21
|
-
|
22
|
-
* [My website][mg] (michaelgalero.com)
|
23
|
-
* [Github](http://github.com/mikong) (@mikong)
|
24
|
-
|
25
|
-
[rsc]: http://ricostacruz.com
|
26
|
-
[mg]: http://devblog.michaelgalero.com/
|
27
|
-
[c]: http://github.com/mina-deploy/mina/graphs/contributors
|
28
|
-
[nd]: http://nadarei.co
|
29
|
-
[issues]: https://github.com/mina-deploy/mina/issues
|
30
|
-
[trello]: https://trello.com/board/mina/4fc8b3023d9c9a4d72e573e6
|
31
|
-
|
data/support/Readme-header.md
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# Mina
|
2
|
-
|
3
|
-
Really fast deployer and server automation tool.
|
4
|
-
|
5
|
-
Mina works really fast because it's a deploy Bash script generator. It
|
6
|
-
generates an entire procedure as a Bash script and runs it remotely in the
|
7
|
-
server.
|
8
|
-
|
9
|
-
Compare this to the likes of Vlad or Capistrano, where each command
|
10
|
-
is run separately on their own SSH sessions. Mina only creates *one* SSH
|
11
|
-
session per deploy, minimizing the SSH connection overhead.
|
12
|
-
|
13
|
-
$ gem install mina
|
14
|
-
$ mina
|
15
|
-
|
16
|
-
[![Build Status](https://travis-ci.org/mina-deploy/mina.svg?branch=master)](https://travis-ci.org/mina-deploy/mina) [![Gem Version](https://badge.fury.io/rb/mina.svg)](http://badge.fury.io/rb/mina) [![Inline docs](http://inch-ci.org/github/mina-deploy/mina.svg?branch=master)](http://inch-ci.org/github/mina-deploy/mina)
|
data/support/guide.md
DELETED
@@ -1,297 +0,0 @@
|
|
1
|
-
|
2
|
-
User guide
|
3
|
-
==========
|
4
|
-
|
5
|
-
Setting up a project
|
6
|
-
--------------------
|
7
|
-
|
8
|
-
Let's deploy a project using Mina.
|
9
|
-
|
10
|
-
### Step 1: Create a config/deploy.rb
|
11
|
-
|
12
|
-
In your project, type `mina init` to create a sample of this file.
|
13
|
-
|
14
|
-
$ mina init
|
15
|
-
Created config/deploy.rb.
|
16
|
-
|
17
|
-
This is just a Rake file with tasks! See [About deploy.rb](#about-deployrb) for
|
18
|
-
more info on what *deploy.rb* is. You will want to at least configure your
|
19
|
-
server:
|
20
|
-
|
21
|
-
~~~ ruby
|
22
|
-
# config/deploy.rb
|
23
|
-
set :user, 'username'
|
24
|
-
set :domain, 'your.server.com'
|
25
|
-
set :deploy_to, '/var/www/flipstack.com'
|
26
|
-
...
|
27
|
-
~~~
|
28
|
-
|
29
|
-
### Step 2: Set up your server
|
30
|
-
|
31
|
-
Make a directory in your server called `/var/www/flipstack.com` (in *deploy_to*)
|
32
|
-
change it's ownership to the correct user.
|
33
|
-
|
34
|
-
$ ssh username@your.server.com
|
35
|
-
|
36
|
-
# Once in your server, create the deploy folder:
|
37
|
-
~@your.server.com$ mkdir /var/www/flipstack.com
|
38
|
-
~@your.server.com$ chown -R username /var/www/flipstack.com
|
39
|
-
|
40
|
-
### Step 3: Run 'mina setup'
|
41
|
-
|
42
|
-
Back at your computer, do `mina setup` to set up the [folder
|
43
|
-
structure](#directory_structure) in this path. This will connect to your server
|
44
|
-
via SSH and create the right directories.
|
45
|
-
|
46
|
-
$ mina setup
|
47
|
-
-----> Creating folders... done.
|
48
|
-
|
49
|
-
See [directory structure](#directory_structure) for more info.
|
50
|
-
|
51
|
-
### Step 4: Deploy!
|
52
|
-
|
53
|
-
Use `mina deploy` to run the `deploy` task defined in *config/deploy.rb*.
|
54
|
-
|
55
|
-
$ mina deploy
|
56
|
-
-----> Deploying to 2012-06-12-040248
|
57
|
-
...
|
58
|
-
Lots of things happening...
|
59
|
-
...
|
60
|
-
-----> Done.
|
61
|
-
|
62
|
-
About deploy.rb
|
63
|
-
---------------
|
64
|
-
|
65
|
-
The file `deploy.rb` is simply a Rakefile invoked by Rake. In fact, `mina` is
|
66
|
-
mostly an alias that invokes Rake to load `deploy.rb`.
|
67
|
-
|
68
|
-
~~~ ruby
|
69
|
-
# Sample config/deploy.rb
|
70
|
-
set :domain, 'your.server.com'
|
71
|
-
|
72
|
-
task :restart do
|
73
|
-
queue 'sudo service restart apache'
|
74
|
-
end
|
75
|
-
~~~
|
76
|
-
|
77
|
-
As it's all Rake, you can define tasks that you can invoke using `mina`. In this
|
78
|
-
example, it provides the `mina restart` command.
|
79
|
-
|
80
|
-
The magic of Mina is in the new commands it gives you.
|
81
|
-
|
82
|
-
The `queue` command queues up Bash commands to be run on the remote server.
|
83
|
-
If you invoke `mina restart`, it will invoke the task above and run the queued
|
84
|
-
commands on the remote server `your.server.com` via SSH.
|
85
|
-
|
86
|
-
See [the command queue](#the-command-queue) for more information on the *queue*
|
87
|
-
command.
|
88
|
-
|
89
|
-
The command queue
|
90
|
-
-----------------
|
91
|
-
|
92
|
-
At the heart of it, Mina is merely sugar on top of Rake to queue commands
|
93
|
-
and execute them remotely at the end. Take a look at this minimal *deploy.rb*
|
94
|
-
configuration:
|
95
|
-
|
96
|
-
~~~ ruby
|
97
|
-
# config/deploy.rb
|
98
|
-
set :user, 'john'
|
99
|
-
set :domain, 'flipstack.com'
|
100
|
-
|
101
|
-
task :logs do
|
102
|
-
queue 'echo "Contents of the log file are as follows:"'
|
103
|
-
queue "tail -f /var/log/apache.log"
|
104
|
-
end
|
105
|
-
~~~
|
106
|
-
|
107
|
-
Once you type `mina logs` in your terminal, it invokes the *queue*d commands
|
108
|
-
remotely on the server using the command `ssh john@flipstack.com`.
|
109
|
-
|
110
|
-
~~~ sh
|
111
|
-
$ mina logs --simulate
|
112
|
-
# Execute the following commands via
|
113
|
-
# ssh john@flipstack.com:
|
114
|
-
#
|
115
|
-
echo "Contents of the log file are as follows:"
|
116
|
-
tail -f /var/log/apache.log
|
117
|
-
~~~
|
118
|
-
|
119
|
-
Subtasks
|
120
|
-
--------
|
121
|
-
|
122
|
-
Mina provides the helper `invoke` to invoke other tasks from a
|
123
|
-
task.
|
124
|
-
|
125
|
-
~~~ ruby
|
126
|
-
# config/deploy.rb
|
127
|
-
task :down do
|
128
|
-
invoke :maintenance_on
|
129
|
-
invoke :restart
|
130
|
-
end
|
131
|
-
|
132
|
-
task :maintenance_on
|
133
|
-
queue 'touch maintenance.txt'
|
134
|
-
end
|
135
|
-
|
136
|
-
task :restart
|
137
|
-
queue 'sudo service restart apache'
|
138
|
-
end
|
139
|
-
~~~
|
140
|
-
|
141
|
-
In this example above, if you type `mina down`, it simply invokes the other
|
142
|
-
subtasks which queues up their commands. The commands will be run after
|
143
|
-
everything.
|
144
|
-
|
145
|
-
Directory structure
|
146
|
-
-------------------
|
147
|
-
|
148
|
-
The deploy procedures make the assumption that you have a folder like so:
|
149
|
-
|
150
|
-
/var/www/flipstack.com/ # The deploy_to path
|
151
|
-
|- releases/ # Holds releases, one subdir per release
|
152
|
-
| |- 1/
|
153
|
-
| |- 2/
|
154
|
-
| |- 3/
|
155
|
-
| '- ...
|
156
|
-
|- shared/ # Holds files shared between releases
|
157
|
-
| |- logs/ # Log files are usually stored here
|
158
|
-
| `- ...
|
159
|
-
'- current/ # A symlink to the current release in releases/
|
160
|
-
|
161
|
-
It also assumes that the `deploy_to` path is fully writeable/readable for the
|
162
|
-
user we're going to SSH with.
|
163
|
-
|
164
|
-
Deploying
|
165
|
-
---------
|
166
|
-
|
167
|
-
Mina provides the `deploy` command which *queue*s up a deploy script for
|
168
|
-
you.
|
169
|
-
|
170
|
-
~~~ ruby
|
171
|
-
# config/deploy.rb
|
172
|
-
set :domain, 'flipstack.com'
|
173
|
-
set :user, 'flipstack'
|
174
|
-
set :deploy_to, '/var/www/flipstack.com'
|
175
|
-
set :repository, 'http://github.com/flipstack/flipstack.git'
|
176
|
-
|
177
|
-
task :deploy do
|
178
|
-
deploy do
|
179
|
-
# Put things that prepare the empty release folder here.
|
180
|
-
# Commands queued here will be run on a new release directory.
|
181
|
-
invoke :'git:clone'
|
182
|
-
invoke :'bundle:install'
|
183
|
-
|
184
|
-
# These are instructions to start the app after it's been prepared.
|
185
|
-
to :launch do
|
186
|
-
queue 'touch tmp/restart.txt'
|
187
|
-
end
|
188
|
-
|
189
|
-
# This optional block defines how a broken release should be cleaned up.
|
190
|
-
to :clean do
|
191
|
-
queue 'log "failed deployment"'
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
~~~
|
196
|
-
|
197
|
-
It works by capturing the *queue*d commands inside the block, wrapping them
|
198
|
-
in a deploy script, then *queue*ing them back in.
|
199
|
-
|
200
|
-
### How deploying works
|
201
|
-
|
202
|
-
Here is an example of a deploy! (Note that some commands have been simplified
|
203
|
-
to illustrate the point better.)
|
204
|
-
|
205
|
-
### Step 1: Build it
|
206
|
-
|
207
|
-
The deploy process builds a new temp folder with instructions you provide.
|
208
|
-
In this example, it will do `git:clone` and `bundle:install`.
|
209
|
-
|
210
|
-
$ mina deploy --verbose
|
211
|
-
-----> Creating the build path
|
212
|
-
$ mkdir tmp/build-128293482394
|
213
|
-
-----> Cloning the Git repository
|
214
|
-
$ git clone https://github.com/flipstack/flipstack.git . -n --recursive
|
215
|
-
Cloning... done.
|
216
|
-
-----> Installing gem dependencies using Bundler
|
217
|
-
$ bundle install --without development:test
|
218
|
-
Using i18n (0.6.0)
|
219
|
-
Using multi_json (1.0.4)
|
220
|
-
...
|
221
|
-
Your bundle is complete! It was installed to ./vendor/bundle
|
222
|
-
|
223
|
-
### Step 2: Move it to releases
|
224
|
-
|
225
|
-
Once the project has been built, it will be moved to `releases/`. A symlink
|
226
|
-
called `current/` will be created to point to the active release.
|
227
|
-
|
228
|
-
$
|
229
|
-
-----> Moving to releases/4
|
230
|
-
$ mv "./tmp/build-128293482394" "releases/4"
|
231
|
-
-----> Symlinking to current
|
232
|
-
$ ln -nfs releases/4 current
|
233
|
-
|
234
|
-
### Step 3: Launch it
|
235
|
-
|
236
|
-
Invoke the commands queued up in the `to :launch` block. These often
|
237
|
-
commands to restart the webserver process. Once this in complete, you're done!
|
238
|
-
|
239
|
-
$
|
240
|
-
-----> Launching
|
241
|
-
$ cd releases/4
|
242
|
-
$ sudo service nginx restart
|
243
|
-
-----> Done. Deployed v4
|
244
|
-
|
245
|
-
### What about failure?
|
246
|
-
|
247
|
-
If it fails at any point, the release path will be deleted. If any commands are
|
248
|
-
queued using the `to :clean` block, they will be run. It will be as if nothing
|
249
|
-
happened. Lets see what happens if a build fails:
|
250
|
-
|
251
|
-
$
|
252
|
-
-----> Launching
|
253
|
-
$ cd releases/4
|
254
|
-
$ sudo service nginx restart
|
255
|
-
Starting nginx... error: can't start service
|
256
|
-
-----> ERROR: Deploy failed.
|
257
|
-
-----> Cleaning up build
|
258
|
-
$ rm -rf tmp/build-128293482394
|
259
|
-
-----> Unlinking current
|
260
|
-
$ ln -nfs releases/3 current
|
261
|
-
OK
|
262
|
-
|
263
|
-
Command line options
|
264
|
-
--------------------
|
265
|
-
|
266
|
-
Basic usage:
|
267
|
-
|
268
|
-
$ mina [OPTIONS] [TASKS] [VAR1=val VAR2=val ...]
|
269
|
-
|
270
|
-
### Options
|
271
|
-
|
272
|
-
* `-v` / `--verbose` - This will show commands being done on the server. Off by
|
273
|
-
default.
|
274
|
-
|
275
|
-
* `-S` / `--simulate` - This will not invoke any SSH connections; instead, it
|
276
|
-
will simply output the script it builds.
|
277
|
-
|
278
|
-
* `-t` / `--trace` - Show backtraces when errors occur.
|
279
|
-
|
280
|
-
* `-f FILE` - Use a custom deploy.rb configuration.
|
281
|
-
|
282
|
-
* `-V` / `--version` - Shows the current version.
|
283
|
-
|
284
|
-
### Tasks
|
285
|
-
|
286
|
-
There are many tasks available. See the [tasks reference](http://mina-deploy.github.io/mina/tasks/), or
|
287
|
-
type `mina tasks`.
|
288
|
-
|
289
|
-
### Variables
|
290
|
-
|
291
|
-
You may specify additional variables in the `KEY=value` style, just like Rake.
|
292
|
-
You can add as many variables as needed.
|
293
|
-
|
294
|
-
$ mina restart on=staging
|
295
|
-
|
296
|
-
# This sets the ENV['on'] variable to 'staging'.
|
297
|
-
|