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/bin/mina
CHANGED
@@ -1,65 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
-
|
4
|
-
require 'rubygems' unless Object.const_defined?(:Gem)
|
5
2
|
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
3
|
|
4
|
+
Mina::Application.new.run
|
data/data/deploy.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'mina/bundler'
|
2
2
|
require 'mina/rails'
|
3
3
|
require 'mina/git'
|
4
|
-
# require 'mina/rbenv' # for rbenv support. (
|
5
|
-
# require 'mina/rvm' # for rvm support. (
|
4
|
+
# require 'mina/rbenv' # for rbenv support. (https://rbenv.org)
|
5
|
+
# require 'mina/rvm' # for rvm support. (https://rvm.io)
|
6
6
|
|
7
7
|
# Basic settings:
|
8
8
|
# domain - The hostname to SSH to.
|
@@ -15,18 +15,15 @@ set :deploy_to, '/var/www/foobar.com'
|
|
15
15
|
set :repository, 'git://...'
|
16
16
|
set :branch, 'master'
|
17
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', 'config/secrets.yml', 'log']
|
24
|
-
|
25
18
|
# Optional settings:
|
26
|
-
# set :user, 'foobar'
|
27
|
-
# set :port, '30000'
|
19
|
+
# set :user, 'foobar' # Username in the server to SSH to.
|
20
|
+
# set :port, '30000' # SSH port number.
|
28
21
|
# set :forward_agent, true # SSH forward_agent.
|
29
22
|
|
23
|
+
# They will be linked in the 'deploy:link_shared_paths' step.
|
24
|
+
# set :shared_dirs, -> { fetch(:shared_dirs, []).push('config') }
|
25
|
+
# set :shared_files, -> { fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml') }
|
26
|
+
|
30
27
|
# This task is the environment that is loaded for most commands, such as
|
31
28
|
# `mina deploy` or `mina rake`.
|
32
29
|
task :environment do
|
@@ -38,37 +35,14 @@ task :environment do
|
|
38
35
|
# invoke :'rvm:use[ruby-1.9.3-p125@default]'
|
39
36
|
end
|
40
37
|
|
41
|
-
# Put any custom
|
42
|
-
#
|
43
|
-
|
44
|
-
|
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! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"]
|
53
|
-
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml' and 'secrets.yml'."]
|
54
|
-
|
55
|
-
if repository
|
56
|
-
repo_host = repository.split(%r{@|://}).last.split(%r{:|\/}).first
|
57
|
-
repo_port = /:([0-9]+)/.match(repository) && /:([0-9]+)/.match(repository)[1] || '22'
|
58
|
-
|
59
|
-
queue %[
|
60
|
-
if ! ssh-keygen -H -F #{repo_host} &>/dev/null; then
|
61
|
-
ssh-keyscan -t rsa -p #{repo_port} -H #{repo_host} >> ~/.ssh/known_hosts
|
62
|
-
fi
|
63
|
-
]
|
64
|
-
end
|
38
|
+
# Put any custom commands you need to run at setup
|
39
|
+
# All paths in `shared_dirs` and `shared_paths` will be created on their own.
|
40
|
+
task setup: :environment do
|
41
|
+
# command 'rbenv install 2.3.0'
|
65
42
|
end
|
66
43
|
|
67
44
|
desc "Deploys the current version to the server."
|
68
|
-
task :
|
69
|
-
to :before_hook do
|
70
|
-
# Put things to run locally before ssh
|
71
|
-
end
|
45
|
+
task deploy: :environment do
|
72
46
|
deploy do
|
73
47
|
# Put things that will set up an empty directory into a fully set-up
|
74
48
|
# instance of your project.
|
@@ -79,16 +53,15 @@ task :deploy => :environment do
|
|
79
53
|
invoke :'rails:assets_precompile'
|
80
54
|
invoke :'deploy:cleanup'
|
81
55
|
|
82
|
-
|
83
|
-
|
84
|
-
|
56
|
+
on :launch do
|
57
|
+
in_path(fetch(:current_path)) do
|
58
|
+
command "mkdir -p tmp/"
|
59
|
+
command "touch tmp/restart.txt"
|
60
|
+
end
|
85
61
|
end
|
86
62
|
end
|
87
63
|
end
|
88
64
|
|
89
65
|
# For help in making your deploy script, see the Mina documentation:
|
90
66
|
#
|
91
|
-
# -
|
92
|
-
# - http://nadarei.co/mina/tasks
|
93
|
-
# - http://nadarei.co/mina/settings
|
94
|
-
# - http://nadarei.co/mina/helpers
|
67
|
+
# - https://github.com/mina-deploy/mina/docs
|
data/data/deploy.sh.erb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
<%
|
2
|
-
|
3
|
-
build = commands(:build).map { |s|
|
4
|
-
launch = commands(:launch).map { |s|
|
5
|
-
clean = commands(:clean).map { |s|
|
2
|
+
default = commands.fetch(:default).map { |s| indent 2, s }.join(" &&\n")
|
3
|
+
build = commands.fetch(:build).map { |s| indent 2, s }.join(" &&\n")
|
4
|
+
launch = commands.fetch(:launch).map { |s| indent 2, s }.join(" &&\n")
|
5
|
+
clean = commands.fetch(:clean).map { |s| indent 2, s }.join(" &&\n")
|
6
6
|
%>
|
7
7
|
#!/usr/bin/env bash
|
8
8
|
|
9
9
|
# Go to the deploy path
|
10
|
-
cd "<%= deploy_to %>" || (
|
10
|
+
cd "<%= fetch(:deploy_to) %>" || (
|
11
11
|
echo "! ERROR: not set up."
|
12
|
-
echo "The path '<%= deploy_to %>' is not accessible on the server."
|
12
|
+
echo "The path '<%= fetch(:deploy_to) %>' is not accessible on the server."
|
13
13
|
echo "You may need to run 'mina setup' first."
|
14
14
|
false
|
15
15
|
) || exit 15
|
16
16
|
|
17
17
|
# Check releases path
|
18
|
-
if [ ! -d "<%= releases_path %>" ]; then
|
18
|
+
if [ ! -d "<%= fetch(:releases_path) %>" ]; then
|
19
19
|
echo "! ERROR: not set up."
|
20
|
-
echo "The directory '<%= releases_path %>' does not exist on the server."
|
20
|
+
echo "The directory '<%= fetch(:releases_path) %>' does not exist on the server."
|
21
21
|
echo "You may need to run 'mina setup' first."
|
22
22
|
exit 16
|
23
23
|
fi
|
24
24
|
|
25
25
|
# Check lockfile
|
26
|
-
if [ -e "<%= lock_file %>" ]; then
|
26
|
+
if [ -e "<%= fetch(:lock_file) %>" ]; then
|
27
27
|
echo "! ERROR: another deployment is ongoing."
|
28
|
-
echo "The file '<%= lock_file %>' was found."
|
28
|
+
echo "The file '<%= fetch(:lock_file) %>' was found."
|
29
29
|
echo "If no other deployment is ongoing, run 'mina deploy:force_unlock' to delete the file."
|
30
30
|
exit 17
|
31
31
|
fi
|
32
32
|
|
33
33
|
# Determine $previous_path and other variables
|
34
|
-
[ -h "<%= current_path %>" ] && [ -d "<%= current_path %>" ] && previous_path=$(cd "<%= current_path %>" >/dev/null && pwd -LP)
|
34
|
+
[ -h "<%= fetch(:current_path) %>" ] && [ -d "<%= fetch(:current_path) %>" ] && previous_path=$(cd "<%= fetch(:current_path) %>" >/dev/null && pwd -LP)
|
35
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"
|
36
|
+
version=$((`cat "<%= fetch(:deploy_to) %>/last_version" 2>/dev/null`+1))
|
37
|
+
release_path="<%= fetch(:releases_path) %>/$version"
|
38
38
|
|
39
39
|
# Sanity check
|
40
40
|
if [ -e "$build_path" ]; then
|
@@ -45,11 +45,11 @@ fi
|
|
45
45
|
# Bootstrap script (in deployer)
|
46
46
|
(
|
47
47
|
echo "-----> Creating a temporary build path"
|
48
|
-
<%= echo_cmd %[touch "#{lock_file}"] %> &&
|
48
|
+
<%= echo_cmd %[touch "#{fetch(:lock_file)}"] %> &&
|
49
49
|
<%= echo_cmd %[mkdir -p "$build_path"] %> &&
|
50
50
|
<%= echo_cmd %[cd "$build_path"] %> &&
|
51
51
|
(
|
52
|
-
<%= indent
|
52
|
+
<%= indent 2, (default.empty? ? "true" : default) %>
|
53
53
|
) &&
|
54
54
|
echo "-----> Deploy finished"
|
55
55
|
) &&
|
@@ -62,7 +62,7 @@ fi
|
|
62
62
|
<%= echo_cmd %[mv "$build_path" "$release_path"] %> &&
|
63
63
|
<%= echo_cmd %[cd "$release_path"] %> &&
|
64
64
|
(
|
65
|
-
<%= indent
|
65
|
+
<%= indent 2, (build.empty? ? "true" : build) %>
|
66
66
|
) &&
|
67
67
|
echo "-----> Build finished"
|
68
68
|
|
@@ -73,22 +73,21 @@ fi
|
|
73
73
|
# Rename to the real release path, then symlink 'current'
|
74
74
|
(
|
75
75
|
echo "-----> Launching"
|
76
|
-
echo "-----> Updating the <%= current_path %> symlink" &&
|
77
|
-
<%= echo_cmd %[ln -nfs "$release_path" "#{current_path}"] %>
|
76
|
+
echo "-----> Updating the <%= fetch(:current_path) %> symlink" &&
|
77
|
+
<%= echo_cmd %[ln -nfs "$release_path" "#{fetch(:current_path)}"] %>
|
78
78
|
) &&
|
79
79
|
|
80
80
|
# ============================
|
81
81
|
# === Start up server => (in deployer)
|
82
82
|
(
|
83
|
-
|
84
|
-
<%= echo_cmd %[cd "#{current_path}"] %>
|
83
|
+
<%= echo_cmd %[cd "#{fetch(:current_path)}"] %>
|
85
84
|
<%= indent 2, (launch.empty? ? "true" : launch) %>
|
86
85
|
) &&
|
87
86
|
|
88
87
|
# ============================
|
89
88
|
# === Complete & unlock
|
90
89
|
(
|
91
|
-
rm -f "<%= lock_file %>"
|
90
|
+
rm -f "<%= fetch(:lock_file) %>"
|
92
91
|
echo "$version" > "./last_version"
|
93
92
|
echo "-----> Done. Deployed v$version"
|
94
93
|
) ||
|
@@ -110,11 +109,11 @@ fi
|
|
110
109
|
)
|
111
110
|
(
|
112
111
|
echo "Unlinking current"
|
113
|
-
[ -n "$previous_path" ] && <%= echo_cmd %[ln -nfs "$previous_path" "#{current_path}"] %>
|
112
|
+
[ -n "$previous_path" ] && <%= echo_cmd %[ln -nfs "$previous_path" "#{fetch(:current_path)}"] %>
|
114
113
|
)
|
115
114
|
|
116
115
|
# Unlock
|
117
|
-
<%= echo_cmd %[rm -f "#{lock_file}"] %>
|
116
|
+
<%= echo_cmd %[rm -f "#{fetch(:lock_file)}"] %>
|
118
117
|
echo "OK"
|
119
118
|
exit 19
|
120
119
|
)
|
data/docs/Readme.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Mina Documentations
|
2
|
+
|
3
|
+
* [Getting started](getting_started.md)
|
4
|
+
* [Migrating from 0.3.x to 1.0](migrating.md)
|
5
|
+
* [Deploying](deploying.md)
|
6
|
+
* [Writing your own tasks](writing_your_own_tasks.md)
|
7
|
+
* [Command line options](command_line_options.md)
|
8
|
+
* [FAQ](faq.md)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Command line options
|
2
|
+
--------------------
|
3
|
+
|
4
|
+
Basic usage:
|
5
|
+
|
6
|
+
$ mina [OPTIONS] [TASKS] [VAR1=val VAR2=val ...]
|
7
|
+
|
8
|
+
### Options
|
9
|
+
|
10
|
+
Beside normal rake options mina added some of its own:
|
11
|
+
|
12
|
+
* `-v` / `--verbose` - This will show commands being done on the server. Off by
|
13
|
+
default.
|
14
|
+
|
15
|
+
* `-s` / `--simulate` - This will not run any commands; instead, it will simply output the script it builds.
|
16
|
+
|
17
|
+
* `-V` / `--version` - Shows the current version.
|
18
|
+
|
19
|
+
* `-d` / `--debug-configuration-variables` - Display the defined config variables before runnig the tasks.
|
20
|
+
|
21
|
+
### Tasks
|
22
|
+
|
23
|
+
There are many tasks available. See the [tasks reference](http://mina-deploy.github.io/mina/tasks/), or
|
24
|
+
type `mina -T`.
|
25
|
+
|
26
|
+
### Variables
|
27
|
+
|
28
|
+
You may specify additional variables in the `KEY=value` style, just like any other command line tools.
|
29
|
+
You can add as many variables as needed.
|
30
|
+
|
31
|
+
$ mina restart on=staging
|
32
|
+
|
33
|
+
# This sets the ENV['on'] variable to 'staging'.
|
data/docs/deploying.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
Deploying
|
2
|
+
--------------------
|
3
|
+
|
4
|
+
Mina provides the `deploy` command which runs your commands on remote backend.
|
5
|
+
|
6
|
+
``` ruby
|
7
|
+
# config/deploy.rb
|
8
|
+
set :domain, 'flipstack.com'
|
9
|
+
set :user, 'flipstack'
|
10
|
+
set :deploy_to, '/var/www/flipstack.com'
|
11
|
+
set :repository, 'http://github.com/flipstack/flipstack.git'
|
12
|
+
|
13
|
+
task :deploy do
|
14
|
+
deploy do
|
15
|
+
# Put things that prepare the empty release folder here.
|
16
|
+
# Commands queued here will be run on a new release directory.
|
17
|
+
invoke :'git:clone'
|
18
|
+
invoke :'bundle:install'
|
19
|
+
|
20
|
+
# These are instructions to start the app after it's been prepared.
|
21
|
+
to :launch do
|
22
|
+
queue 'touch tmp/restart.txt'
|
23
|
+
end
|
24
|
+
|
25
|
+
# This optional block defines how a broken release should be cleaned up.
|
26
|
+
to :clean do
|
27
|
+
queue 'log "failed deployment"'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
It works by capturing the *queue*d commands inside the block, wrapping them
|
34
|
+
in a deploy script, then *queue*ing them back in.
|
35
|
+
|
36
|
+
### How deploying works
|
37
|
+
|
38
|
+
Here is an example of a deploy! (Note that some commands have been simplified
|
39
|
+
to illustrate the point better.)
|
40
|
+
|
41
|
+
### Step 1: Build it
|
42
|
+
|
43
|
+
The deploy process builds a new temp folder with instructions you provide.
|
44
|
+
In this example, it will do `git:clone` and `bundle:install`.
|
45
|
+
|
46
|
+
$ mina deploy --verbose
|
47
|
+
-----> Creating the build path
|
48
|
+
$ mkdir tmp/build-128293482394
|
49
|
+
-----> Cloning the Git repository
|
50
|
+
$ git clone https://github.com/flipstack/flipstack.git . -n --recursive
|
51
|
+
Cloning... done.
|
52
|
+
-----> Installing gem dependencies using Bundler
|
53
|
+
$ bundle install --without development:test
|
54
|
+
Using i18n (0.6.0)
|
55
|
+
Using multi_json (1.0.4)
|
56
|
+
...
|
57
|
+
Your bundle is complete! It was installed to ./vendor/bundle
|
58
|
+
|
59
|
+
### Step 2: Move it to releases
|
60
|
+
|
61
|
+
Once the project has been built, it will be moved to `releases/`. A symlink
|
62
|
+
called `current/` will be created to point to the active release.
|
63
|
+
|
64
|
+
$
|
65
|
+
-----> Moving to releases/4
|
66
|
+
$ mv "./tmp/build-128293482394" "releases/4"
|
67
|
+
-----> Symlinking to current
|
68
|
+
$ ln -nfs releases/4 current
|
69
|
+
|
70
|
+
### Step 3: Launch it
|
71
|
+
|
72
|
+
Invoke the commands queued up in the `to :launch` block. These often
|
73
|
+
commands to restart the webserver process. Once this in complete, you're done!
|
74
|
+
|
75
|
+
$
|
76
|
+
-----> Launching
|
77
|
+
$ cd releases/4
|
78
|
+
$ sudo service nginx restart
|
79
|
+
-----> Done. Deployed v4
|
80
|
+
|
81
|
+
### What about failure?
|
82
|
+
|
83
|
+
If it fails at any point, the release path will be deleted. If any commands are
|
84
|
+
queued using the `to :clean` block, they will be run. It will be as if nothing
|
85
|
+
happened. Lets see what happens if a build fails:
|
86
|
+
|
87
|
+
$
|
88
|
+
-----> Launching
|
89
|
+
$ cd releases/4
|
90
|
+
$ sudo service nginx restart
|
91
|
+
Starting nginx... error: can't start service
|
92
|
+
-----> ERROR: Deploy failed.
|
93
|
+
-----> Cleaning up build
|
94
|
+
$ rm -rf tmp/build-128293482394
|
95
|
+
-----> Unlinking current
|
96
|
+
$ ln -nfs releases/3 current
|
97
|
+
OK
|
data/docs/faq.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# WIP
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Setting up a project
|
2
|
+
--------------------
|
3
|
+
|
4
|
+
Let's deploy a project using Mina.
|
5
|
+
|
6
|
+
### Step 1: Create a config/deploy.rb
|
7
|
+
|
8
|
+
In your project, type `mina init` to create a sample of this file.
|
9
|
+
|
10
|
+
$ mina init
|
11
|
+
Created config/deploy.rb.
|
12
|
+
|
13
|
+
This is just a Rake file with tasks! See [How to write your own tasks](writing_your_own_tasks.md) for
|
14
|
+
more info on what *deploy.rb* is. You will want to at least configure your
|
15
|
+
server:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
# config/deploy.rb
|
19
|
+
set :user, 'username'
|
20
|
+
set :domain, 'your.server.com'
|
21
|
+
set :deploy_to, '/var/www/flipstack.com'
|
22
|
+
...
|
23
|
+
```
|
24
|
+
|
25
|
+
### Step 2: Run 'mina setup'
|
26
|
+
|
27
|
+
Back at your computer, do `mina setup` to set up the folder structure in `deploy_to` path.
|
28
|
+
This will connect to your server via SSH and create the right directories.
|
29
|
+
|
30
|
+
$ mina setup
|
31
|
+
-----> Creating folders... done.
|
32
|
+
|
33
|
+
See [directory structure](https://github.com/mina-deploy/mina/wiki/Directory-structure) for more info.
|
34
|
+
|
35
|
+
### Step 3: Deploy!
|
36
|
+
|
37
|
+
Use `mina deploy` to run the `deploy` task defined in *config/deploy.rb*.
|
38
|
+
|
39
|
+
$ mina deploy
|
40
|
+
-----> Deploying to 2012-06-12-040248
|
41
|
+
...
|
42
|
+
Lots of things happening...
|
43
|
+
...
|
44
|
+
-----> Done.
|