capistrano 2.15.11 → 3.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +17 -8
- data/Gemfile +1 -12
- data/LICENSE.txt +18 -0
- data/README.md +65 -68
- data/Rakefile +4 -10
- data/bin/cap +2 -3
- data/bin/capify +7 -91
- data/capistrano.gemspec +20 -34
- data/lib/Capfile +2 -0
- data/lib/capistrano/application.rb +28 -0
- data/lib/capistrano/bundler.rb +1 -0
- data/lib/capistrano/configuration/question.rb +42 -0
- data/lib/capistrano/configuration/server.rb +24 -0
- data/lib/capistrano/configuration/servers.rb +43 -95
- data/lib/capistrano/configuration.rb +81 -44
- data/lib/capistrano/console.rb +1 -0
- data/lib/capistrano/defaults.rb +11 -0
- data/lib/capistrano/deploy.rb +3 -0
- data/lib/capistrano/dotfile.rb +3 -0
- data/lib/capistrano/dsl/env.rb +57 -0
- data/lib/capistrano/dsl/paths.rb +74 -0
- data/lib/capistrano/dsl/stages.rb +15 -0
- data/lib/capistrano/dsl/task_enhancements.rb +15 -0
- data/lib/capistrano/dsl.rb +38 -0
- data/lib/capistrano/git.rb +1 -0
- data/lib/capistrano/i18n.rb +33 -0
- data/lib/capistrano/install.rb +1 -0
- data/lib/capistrano/setup.rb +17 -0
- data/lib/capistrano/tasks/bundler.rake +13 -0
- data/lib/capistrano/tasks/console.rake +21 -0
- data/lib/capistrano/tasks/deploy.rake +153 -0
- data/lib/capistrano/tasks/framework.rake +45 -0
- data/lib/capistrano/tasks/git.rake +65 -0
- data/lib/capistrano/tasks/install.rake +39 -0
- data/lib/capistrano/templates/Capfile +43 -0
- data/lib/capistrano/templates/deploy.rb.erb +17 -0
- data/lib/capistrano/templates/stage.rb.erb +20 -0
- data/lib/capistrano/version.rb +1 -11
- data/lib/capistrano.rb +9 -3
- data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +48 -0
- data/spec/lib/capistrano/configuration/servers_spec.rb +79 -0
- data/spec/lib/capistrano/configuration_spec.rb +80 -0
- data/spec/lib/capistrano/dsl/env_spec.rb +83 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
- data/spec/lib/capistrano/dsl_spec.rb +51 -0
- data/spec/lib/capistrano_spec.rb +8 -0
- data/spec/spec_helper.rb +14 -0
- metadata +89 -215
- data/.travis.yml +0 -9
- data/CHANGELOG +0 -1203
- data/lib/capistrano/callback.rb +0 -45
- data/lib/capistrano/cli/execute.rb +0 -85
- data/lib/capistrano/cli/help.rb +0 -125
- data/lib/capistrano/cli/help.txt +0 -81
- data/lib/capistrano/cli/options.rb +0 -243
- data/lib/capistrano/cli/ui.rb +0 -40
- data/lib/capistrano/cli.rb +0 -47
- data/lib/capistrano/command.rb +0 -303
- data/lib/capistrano/configuration/actions/file_transfer.rb +0 -50
- data/lib/capistrano/configuration/actions/inspect.rb +0 -46
- data/lib/capistrano/configuration/actions/invocation.rb +0 -329
- data/lib/capistrano/configuration/alias_task.rb +0 -26
- data/lib/capistrano/configuration/callbacks.rb +0 -147
- data/lib/capistrano/configuration/connections.rb +0 -237
- data/lib/capistrano/configuration/execution.rb +0 -142
- data/lib/capistrano/configuration/loading.rb +0 -205
- data/lib/capistrano/configuration/log_formatters.rb +0 -75
- data/lib/capistrano/configuration/namespaces.rb +0 -223
- data/lib/capistrano/configuration/roles.rb +0 -83
- data/lib/capistrano/configuration/variables.rb +0 -127
- data/lib/capistrano/errors.rb +0 -19
- data/lib/capistrano/ext/multistage.rb +0 -67
- data/lib/capistrano/ext/string.rb +0 -5
- data/lib/capistrano/extensions.rb +0 -57
- data/lib/capistrano/fix_rake_deprecated_dsl.rb +0 -8
- data/lib/capistrano/logger.rb +0 -166
- data/lib/capistrano/processable.rb +0 -55
- data/lib/capistrano/recipes/compat.rb +0 -32
- data/lib/capistrano/recipes/deploy/assets.rb +0 -202
- data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
- data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -117
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
- data/lib/capistrano/recipes/deploy/scm/base.rb +0 -200
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
- data/lib/capistrano/recipes/deploy/scm/git.rb +0 -299
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
- data/lib/capistrano/recipes/deploy/scm/none.rb +0 -55
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -152
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
- data/lib/capistrano/recipes/deploy/scm.rb +0 -19
- data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -92
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -338
- data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
- data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +0 -21
- data/lib/capistrano/recipes/deploy/strategy.rb +0 -20
- data/lib/capistrano/recipes/deploy.rb +0 -625
- data/lib/capistrano/recipes/standard.rb +0 -37
- data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/role.rb +0 -102
- data/lib/capistrano/server_definition.rb +0 -56
- data/lib/capistrano/shell.rb +0 -265
- data/lib/capistrano/ssh.rb +0 -95
- data/lib/capistrano/task_definition.rb +0 -77
- data/lib/capistrano/transfer.rb +0 -218
- data/test/cli/execute_test.rb +0 -132
- data/test/cli/help_test.rb +0 -165
- data/test/cli/options_test.rb +0 -329
- data/test/cli/ui_test.rb +0 -28
- data/test/cli_test.rb +0 -17
- data/test/command_test.rb +0 -322
- data/test/configuration/actions/file_transfer_test.rb +0 -61
- data/test/configuration/actions/inspect_test.rb +0 -76
- data/test/configuration/actions/invocation_test.rb +0 -306
- data/test/configuration/alias_task_test.rb +0 -118
- data/test/configuration/callbacks_test.rb +0 -201
- data/test/configuration/connections_test.rb +0 -439
- data/test/configuration/execution_test.rb +0 -175
- data/test/configuration/loading_test.rb +0 -148
- data/test/configuration/namespace_dsl_test.rb +0 -332
- data/test/configuration/roles_test.rb +0 -157
- data/test/configuration/servers_test.rb +0 -183
- data/test/configuration/variables_test.rb +0 -190
- data/test/configuration_test.rb +0 -77
- data/test/deploy/local_dependency_test.rb +0 -76
- data/test/deploy/remote_dependency_test.rb +0 -146
- data/test/deploy/scm/accurev_test.rb +0 -23
- data/test/deploy/scm/base_test.rb +0 -55
- data/test/deploy/scm/bzr_test.rb +0 -51
- data/test/deploy/scm/darcs_test.rb +0 -37
- data/test/deploy/scm/git_test.rb +0 -274
- data/test/deploy/scm/mercurial_test.rb +0 -134
- data/test/deploy/scm/none_test.rb +0 -35
- data/test/deploy/scm/perforce_test.rb +0 -23
- data/test/deploy/scm/subversion_test.rb +0 -68
- data/test/deploy/strategy/copy_test.rb +0 -360
- data/test/extensions_test.rb +0 -69
- data/test/fixtures/cli_integration.rb +0 -5
- data/test/fixtures/config.rb +0 -5
- data/test/fixtures/custom.rb +0 -3
- data/test/logger_formatting_test.rb +0 -149
- data/test/logger_test.rb +0 -134
- data/test/recipes_test.rb +0 -25
- data/test/role_test.rb +0 -11
- data/test/server_definition_test.rb +0 -121
- data/test/shell_test.rb +0 -96
- data/test/ssh_test.rb +0 -113
- data/test/task_definition_test.rb +0 -117
- data/test/transfer_test.rb +0 -168
- data/test/utils.rb +0 -37
- data/test/version_test.rb +0 -11
@@ -0,0 +1,153 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
|
3
|
+
task :started do
|
4
|
+
invoke 'deploy:check'
|
5
|
+
end
|
6
|
+
|
7
|
+
task :update do
|
8
|
+
invoke "#{scm}:create_release"
|
9
|
+
invoke 'deploy:symlink:shared'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :finalize do
|
13
|
+
invoke 'deploy:symlink:release'
|
14
|
+
end
|
15
|
+
|
16
|
+
task :finished do
|
17
|
+
invoke 'deploy:log_revision'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Check required files and directories exist'
|
21
|
+
task :check do
|
22
|
+
invoke "#{scm}:check"
|
23
|
+
invoke 'deploy:check:directories'
|
24
|
+
invoke 'deploy:check:linked_dirs'
|
25
|
+
invoke 'deploy:check:linked_files'
|
26
|
+
end
|
27
|
+
|
28
|
+
namespace :check do
|
29
|
+
desc 'Check shared and release directories exist'
|
30
|
+
task :directories do
|
31
|
+
on roles :all do
|
32
|
+
execute :mkdir, '-pv', shared_path, releases_path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Check directories to be linked exist in shared'
|
37
|
+
task :linked_dirs do
|
38
|
+
next unless any? :linked_dirs
|
39
|
+
on roles :app do
|
40
|
+
execute :mkdir, '-pv', linked_dirs(shared_path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Check files to be linked exist in shared'
|
45
|
+
task :linked_files do
|
46
|
+
next unless any? :linked_files
|
47
|
+
on roles :app do |host|
|
48
|
+
execute :mkdir, '-pv', linked_file_dirs(shared_path)
|
49
|
+
linked_files(shared_path).each do |file|
|
50
|
+
unless test "[ -f #{file} ]"
|
51
|
+
error t(:linked_file_does_not_exist, file: file, host: host)
|
52
|
+
exit 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
namespace :symlink do
|
60
|
+
desc 'Symlink release to current'
|
61
|
+
task :release do
|
62
|
+
on roles :web, :app do
|
63
|
+
execute :rm, '-rf', current_path
|
64
|
+
execute :ln, '-s', release_path, current_path
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'Symlink files and directories from shared to release'
|
69
|
+
task :shared do
|
70
|
+
invoke 'deploy:symlink:linked_files'
|
71
|
+
invoke 'deploy:symlink:linked_dirs'
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'Symlink linked directories'
|
75
|
+
task :linked_dirs do
|
76
|
+
next unless any? :linked_dirs
|
77
|
+
on roles :app do
|
78
|
+
execute :mkdir, '-pv', linked_dir_parents(release_path)
|
79
|
+
|
80
|
+
fetch(:linked_dirs).each do |dir|
|
81
|
+
target = release_path.join(dir)
|
82
|
+
source = shared_path.join(dir)
|
83
|
+
unless test "[ -L #{target} ]"
|
84
|
+
if test "[ -f #{target} ]"
|
85
|
+
execute :rm, '-rf', target
|
86
|
+
end
|
87
|
+
execute :ln, '-s', source, target
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
desc 'Symlink linked files'
|
94
|
+
task :linked_files do
|
95
|
+
next unless any? :linked_files
|
96
|
+
on roles :app do
|
97
|
+
execute :mkdir, '-pv', linked_file_dirs(release_path)
|
98
|
+
|
99
|
+
fetch(:linked_files).each do |file|
|
100
|
+
target = release_path.join(file)
|
101
|
+
source = shared_path.join(file)
|
102
|
+
unless test "[ -L #{target} ]"
|
103
|
+
if test "[ -f #{target} ]"
|
104
|
+
execute :rm, target
|
105
|
+
end
|
106
|
+
execute :ln, '-s', source, target
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
desc 'Clean up old releases'
|
114
|
+
task :cleanup do
|
115
|
+
releases = on primary :app do
|
116
|
+
capture(:ls, '-xt', releases_path).split.reverse
|
117
|
+
end
|
118
|
+
|
119
|
+
on roles :all do
|
120
|
+
if releases.count >= fetch(:keep_releases)
|
121
|
+
info t(:keeping_releases, keep_releases: fetch(:keep_releases), releases: releases.count)
|
122
|
+
directories = (releases - releases.last(fetch(:keep_releases))).map { |release|
|
123
|
+
releases_path.join(release) }.join(" ")
|
124
|
+
execute :rm, '-rf', directories
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
desc 'Log details of the deploy'
|
130
|
+
task :log_revision do
|
131
|
+
on primary :app do
|
132
|
+
within releases_path do
|
133
|
+
execute %{echo "#{revision_log_message}" >> #{revision_log}}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
desc 'Rollback to the last release'
|
139
|
+
task :rollback do
|
140
|
+
on primary :app do
|
141
|
+
last_release = capture(:ls, '-xt', releases_path).split[1]
|
142
|
+
set(:rollback_release_timestamp, last_release)
|
143
|
+
set(:branch, last_release)
|
144
|
+
set(:revision_log_message, rollback_log_message)
|
145
|
+
end
|
146
|
+
|
147
|
+
on roles :app do
|
148
|
+
%w{check finalize restart finishing finished}.each do |task|
|
149
|
+
invoke "deploy:#{task}"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
|
3
|
+
desc 'Starting'
|
4
|
+
task :starting do
|
5
|
+
end
|
6
|
+
|
7
|
+
desc 'Started'
|
8
|
+
task :started do
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Update'
|
12
|
+
task :update do
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Finalize'
|
16
|
+
task :finalize do
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Restart'
|
20
|
+
task :restart do
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Finishing'
|
24
|
+
task :finishing do
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Finished'
|
28
|
+
task :finished do
|
29
|
+
end
|
30
|
+
|
31
|
+
before :starting, :ensure_stage do
|
32
|
+
unless stage_set?
|
33
|
+
puts t(:stage_not_set)
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Deploy'
|
40
|
+
task :deploy do
|
41
|
+
%w{starting started update finalize restart finishing finished}.each do |task|
|
42
|
+
invoke "deploy:#{task}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
task default: :deploy
|
@@ -0,0 +1,65 @@
|
|
1
|
+
namespace :git do
|
2
|
+
|
3
|
+
git_environmental_variables = {
|
4
|
+
git_askpass: '/bin/echo',
|
5
|
+
git_ssh: '/tmp/git-ssh.sh'
|
6
|
+
}
|
7
|
+
|
8
|
+
desc 'Upload the git wrapper script, this script guarantees that we can script git without getting an interactive prompt'
|
9
|
+
task :wrapper do
|
10
|
+
on roles :all do
|
11
|
+
upload! StringIO.new("#!/bin/sh -e\nexec /usr/bin/ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no \"$@\"\n"), '/tmp/git-ssh.sh'
|
12
|
+
execute :chmod, "+x", '/tmp/git-ssh.sh'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Check that the repository is reachable'
|
17
|
+
task check: :'git:wrapper' do
|
18
|
+
fetch(:branch)
|
19
|
+
on roles :all do
|
20
|
+
with git_environmental_variables do
|
21
|
+
execute :git, :'ls-remote', fetch(:repo)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'Clone the repo to the cache'
|
27
|
+
task clone: :'git:wrapper' do
|
28
|
+
on roles :all do
|
29
|
+
if test " [ -f #{repo_path}/HEAD ] "
|
30
|
+
info t(:mirror_exists, at: repo_path)
|
31
|
+
else
|
32
|
+
within deploy_path do
|
33
|
+
with git_environmental_variables do
|
34
|
+
execute :git, :clone, '--mirror', fetch(:repo), repo_path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Update the repo mirror to reflect the origin state'
|
42
|
+
task update: :'git:clone' do
|
43
|
+
on roles :all do
|
44
|
+
within repo_path do
|
45
|
+
execute :git, :remote, :update
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Copy repo to releases'
|
51
|
+
task create_release: :'git:update' do
|
52
|
+
on roles :all do
|
53
|
+
with git_environmental_variables do
|
54
|
+
within repo_path do
|
55
|
+
execute :git, :clone, '--branch', fetch(:branch), \
|
56
|
+
'--depth 1', \
|
57
|
+
'--recursive', \
|
58
|
+
'--no-hardlinks', \
|
59
|
+
repo_path, release_path
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'pathname'
|
3
|
+
desc 'Install Capistrano, cap install STAGES=staging,production'
|
4
|
+
task :install do
|
5
|
+
envs = ENV['STAGES'] || 'staging,production'
|
6
|
+
|
7
|
+
tasks_dir = Pathname.new('lib/capistrano/tasks')
|
8
|
+
config_dir = Pathname.new('config')
|
9
|
+
deploy_dir = config_dir.join('deploy')
|
10
|
+
|
11
|
+
deploy_rb = File.expand_path("../../templates/deploy.rb.erb", __FILE__)
|
12
|
+
stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
|
13
|
+
capfile = File.expand_path("../../templates/Capfile", __FILE__)
|
14
|
+
|
15
|
+
mkdir_p deploy_dir
|
16
|
+
|
17
|
+
template = File.read(deploy_rb)
|
18
|
+
file = config_dir.join('deploy.rb')
|
19
|
+
File.open(file, 'w+') do |f|
|
20
|
+
f.write(ERB.new(template).result(binding))
|
21
|
+
puts I18n.t(:written_file, scope: :capistrano, file: file)
|
22
|
+
end
|
23
|
+
|
24
|
+
template = File.read(stage_rb)
|
25
|
+
envs.split(',').each do |stage|
|
26
|
+
file = deploy_dir.join("#{stage}.rb")
|
27
|
+
File.open(file, 'w+') do |f|
|
28
|
+
f.write(ERB.new(template).result(binding))
|
29
|
+
puts I18n.t(:written_file, scope: :capistrano, file: file)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
mkdir_p tasks_dir
|
34
|
+
|
35
|
+
FileUtils.cp(capfile, 'Capfile')
|
36
|
+
|
37
|
+
|
38
|
+
puts I18n.t :capified, scope: :capistrano
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env cap
|
2
|
+
# loads dsl, sets up stages
|
3
|
+
require 'capistrano/setup'
|
4
|
+
|
5
|
+
# provides remote execution of arbitrary commands
|
6
|
+
require 'capistrano/console'
|
7
|
+
|
8
|
+
# includes default deployment tasks
|
9
|
+
# remove to start completely from scratch
|
10
|
+
require 'capistrano/deploy'
|
11
|
+
|
12
|
+
# Includes tasks from other gems included in your Gemfile
|
13
|
+
#
|
14
|
+
# For documentation on these, see for example:
|
15
|
+
#
|
16
|
+
# https://github.com/capistrano/bundler
|
17
|
+
# https://github.com/capistrano/rails/tree/master/assets
|
18
|
+
# https://github.com/capistrano/rails/tree/master/migrations
|
19
|
+
#
|
20
|
+
# require 'capistrano/bundler'
|
21
|
+
# require 'capistrano/rails/assets'
|
22
|
+
# require 'capistrano/rails/migrations'
|
23
|
+
# require 'capistrano/heroku'
|
24
|
+
|
25
|
+
# Loads custom tasks from lib/capistrano/tasks if you have any defined.
|
26
|
+
# Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
27
|
+
|
28
|
+
namespace :deploy do
|
29
|
+
desc 'Restart application'
|
30
|
+
task :restart do
|
31
|
+
on roles(:app), in: :sequence, wait: 5 do
|
32
|
+
#
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
after :restart, :clear_cache do
|
37
|
+
on roles(:web), in: :groups, limit: 3, wait: 10 do
|
38
|
+
#
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
after :finishing, 'deploy:cleanup'
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
set :application, 'my app name'
|
2
|
+
set :repo, 'git@example.com:me/my_repo.git'
|
3
|
+
|
4
|
+
ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
|
5
|
+
|
6
|
+
# set :deploy_to, '/var/www/my_app'
|
7
|
+
# set :scm, :git
|
8
|
+
|
9
|
+
# set :format, :pretty
|
10
|
+
# set :log_level, :debug
|
11
|
+
# set :pty, true
|
12
|
+
|
13
|
+
# set :linked_files, %w{config/database.yml}
|
14
|
+
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
|
15
|
+
|
16
|
+
# set :default_environment, { path: "/opt/ruby/bin:$PATH" }
|
17
|
+
# set :keep_releases, 5
|
@@ -0,0 +1,20 @@
|
|
1
|
+
set :stage, :<%= stage %>
|
2
|
+
|
3
|
+
# Simple Role Syntax
|
4
|
+
# ==================
|
5
|
+
# Supports bulk-adding hosts to roles, the primary
|
6
|
+
# server in each group is considered to be the first
|
7
|
+
# unless any hosts have the primary property set.
|
8
|
+
role :app, %w{example.com}
|
9
|
+
role :web, %w{example.com}
|
10
|
+
role :db, %w{example.com}
|
11
|
+
|
12
|
+
# Extended Server Syntax
|
13
|
+
# ======================
|
14
|
+
# This can be used to drop a more detailed server
|
15
|
+
# definition into the server list. The second argument
|
16
|
+
# something that quacks like a has can be used to set
|
17
|
+
# extended properties on the server.
|
18
|
+
server 'example.com', roles: %w{web app}, my_property: :my_value
|
19
|
+
|
20
|
+
# set :rails_env, :<%= stage %>
|
data/lib/capistrano/version.rb
CHANGED
data/lib/capistrano.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'rake'
|
2
|
+
require 'sshkit'
|
2
3
|
|
4
|
+
require 'capistrano/version'
|
5
|
+
require 'capistrano/i18n'
|
6
|
+
require 'capistrano/dsl'
|
7
|
+
require 'capistrano/application'
|
3
8
|
require 'capistrano/configuration'
|
4
|
-
|
5
|
-
|
9
|
+
|
10
|
+
module Capistrano
|
11
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
describe Question do
|
7
|
+
|
8
|
+
let(:question) { Question.new(env, key, default) }
|
9
|
+
let(:default) { :default }
|
10
|
+
let(:key) { :branch }
|
11
|
+
let(:env) { stub }
|
12
|
+
|
13
|
+
describe '.new' do
|
14
|
+
it 'takes a key, default' do
|
15
|
+
question
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#call' do
|
20
|
+
subject { question.call }
|
21
|
+
|
22
|
+
context 'value is entered' do
|
23
|
+
let(:branch) { 'branch' }
|
24
|
+
|
25
|
+
before do
|
26
|
+
$stdout.expects(:puts).with('Please enter branch: |default|')
|
27
|
+
$stdin.expects(:gets).returns(branch)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'sets the value' do
|
31
|
+
env.expects(:set).with(key, branch)
|
32
|
+
question.call
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'value is not entered' do
|
37
|
+
let(:branch) { default }
|
38
|
+
|
39
|
+
before do
|
40
|
+
$stdout.expects(:puts).with('Please enter branch: |default|')
|
41
|
+
$stdin.expects(:gets).returns('')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'sets the default as the value' do
|
45
|
+
env.expects(:set).with(key, branch)
|
46
|
+
question.call
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
class Configuration
|
5
|
+
describe Server do
|
6
|
+
let(:server) { Server.new('hostname') }
|
7
|
+
|
8
|
+
describe 'adding a role' do
|
9
|
+
subject { server.add_role(:test) }
|
10
|
+
it 'adds the role' do
|
11
|
+
expect{subject}.to change{server.roles.size}.from(0).to(1)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'checking roles' do
|
16
|
+
subject { server.has_role?(:test) }
|
17
|
+
|
18
|
+
before do
|
19
|
+
server.add_role(:test)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'adds the role' do
|
23
|
+
expect{subject}.to be_true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'comparing identity' do
|
28
|
+
subject { server.matches? hostname }
|
29
|
+
|
30
|
+
context 'with the same hostname' do
|
31
|
+
let(:hostname) { 'hostname' }
|
32
|
+
it { should be_true }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with the same hostname and a user' do
|
36
|
+
let(:hostname) { 'user@hostname' }
|
37
|
+
it { should be_true }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with a different hostname' do
|
41
|
+
let(:hostname) { 'otherserver' }
|
42
|
+
it { should be_false }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
class Configuration
|
5
|
+
describe Servers do
|
6
|
+
let(:servers) { Servers.new }
|
7
|
+
|
8
|
+
describe 'adding a role' do
|
9
|
+
subject { servers.add_role(:app, %w{1 2}) }
|
10
|
+
|
11
|
+
it 'adds two new server instances' do
|
12
|
+
expect{subject}.to change{servers.count}.from(0).to(2)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'adding a role to an existing server' do
|
17
|
+
before do
|
18
|
+
servers.add_role(:web, %w{1 2})
|
19
|
+
servers.add_role(:app, %w{1 2})
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'adds new roles to existing servers' do
|
23
|
+
expect(servers.count).to eq 2
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'collecting server roles' do
|
28
|
+
let(:app) { Set.new([:app]) }
|
29
|
+
let(:web_app) { Set.new([:web, :app]) }
|
30
|
+
let(:web) { Set.new([:web]) }
|
31
|
+
|
32
|
+
before do
|
33
|
+
servers.add_role(:app, %w{1 2 3})
|
34
|
+
servers.add_role(:web, %w{2 3 4})
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns an array of the roles' do
|
38
|
+
expect(servers.fetch_roles([:app]).collect(&:roles)).to eq [app, web_app, web_app]
|
39
|
+
expect(servers.fetch_roles([:web]).collect(&:roles)).to eq [web_app, web_app, web]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'finding the primary server' do
|
44
|
+
it 'takes the first server for if none have the primary property' do
|
45
|
+
servers.add_role(:app, %w{1 2})
|
46
|
+
servers.fetch_primary(:app).hostname.should == "1"
|
47
|
+
end
|
48
|
+
it 'takes the first server with the primary have the primary flag' do
|
49
|
+
servers.add_role(:app, %w{1 2})
|
50
|
+
servers.add_host('2', primary: true)
|
51
|
+
servers.fetch_primary(:app).hostname.should == "2"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'fetching servers' do
|
56
|
+
before do
|
57
|
+
servers.add_role(:app, %w{1 2})
|
58
|
+
servers.add_role(:web, %w{2 3})
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns the correct app servers' do
|
62
|
+
expect(servers.fetch_roles([:app]).map(&:hostname)).to eq %w{1 2}
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns the correct web servers' do
|
66
|
+
expect(servers.fetch_roles([:web]).map(&:hostname)).to eq %w{2 3}
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns the correct app and web servers' do
|
70
|
+
expect(servers.fetch_roles([:app, :web]).map(&:hostname)).to eq %w{1 2 3}
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns all servers' do
|
74
|
+
expect(servers.fetch_roles([:all]).map(&:hostname)).to eq %w{1 2 3}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
describe Configuration do
|
5
|
+
let(:config) { Configuration.new }
|
6
|
+
let(:servers) { stub }
|
7
|
+
|
8
|
+
describe '.env' do
|
9
|
+
it 'is a global accessor to a single instance' do
|
10
|
+
Configuration.env.set(:test, true)
|
11
|
+
expect(Configuration.env.fetch(:test)).to be_true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'roles' do
|
16
|
+
context 'adding a role' do
|
17
|
+
subject { config.role(:app, %w{server1 server2}) }
|
18
|
+
|
19
|
+
before do
|
20
|
+
Configuration::Servers.expects(:new).returns(servers)
|
21
|
+
servers.expects(:add_role).with(:app, %w{server1 server2})
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'adds the role' do
|
25
|
+
expect(subject)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'setting and fetching' do
|
31
|
+
subject { config.fetch(:key, :default) }
|
32
|
+
|
33
|
+
context 'value is set' do
|
34
|
+
before do
|
35
|
+
config.set(:key, :value)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns the set value' do
|
39
|
+
expect(subject).to eq :value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'value is not set' do
|
44
|
+
it 'returns the default value' do
|
45
|
+
expect(subject).to eq :default
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'value is a proc' do
|
50
|
+
subject { config.fetch(:key, Proc.new { :proc } ) }
|
51
|
+
it 'calls the proc' do
|
52
|
+
expect(subject).to eq :proc
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'block is passed to fetch' do
|
57
|
+
subject { config.fetch(:key, :default) { fail 'we need this!' } }
|
58
|
+
|
59
|
+
it 'returns the block value' do
|
60
|
+
expect { subject }.to raise_error
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'asking' do
|
66
|
+
let(:question) { stub }
|
67
|
+
|
68
|
+
before do
|
69
|
+
Configuration::Question.expects(:new).with(config, :branch, :default).
|
70
|
+
returns(question)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'prompts for the value when fetching' do
|
74
|
+
config.ask(:branch, :default)
|
75
|
+
expect(config.fetch(:branch)).to eq question
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|