capistrano 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +5 -2
- data/CHANGELOG.md +36 -3
- data/CONTRIBUTING.md +91 -0
- data/Gemfile +9 -0
- data/README.md +9 -11
- data/capistrano.gemspec +5 -8
- data/features/configuration.feature +15 -0
- data/features/deploy.feature +1 -0
- data/features/deploy_failure.feature +17 -0
- data/features/step_definitions/assertions.rb +19 -0
- data/features/step_definitions/cap_commands.rb +5 -1
- data/features/step_definitions/setup.rb +13 -0
- data/features/support/remote_command_helpers.rb +4 -0
- data/lib/capistrano/application.rb +41 -3
- data/lib/capistrano/configuration.rb +8 -0
- data/lib/capistrano/configuration/server.rb +28 -5
- data/lib/capistrano/configuration/servers.rb +3 -6
- data/lib/capistrano/configuration/servers/host_filter.rb +82 -0
- data/lib/capistrano/dsl.rb +16 -1
- data/lib/capistrano/dsl/env.rb +11 -1
- data/lib/capistrano/dsl/paths.rb +8 -0
- data/lib/capistrano/dsl/stages.rb +8 -1
- data/lib/capistrano/dsl/task_enhancements.rb +13 -2
- data/lib/capistrano/git.rb +35 -0
- data/lib/capistrano/hg.rb +32 -0
- data/lib/capistrano/i18n.rb +6 -2
- data/lib/capistrano/scm.rb +116 -0
- data/lib/capistrano/setup.rb +4 -3
- data/lib/capistrano/tasks/console.rake +9 -1
- data/lib/capistrano/tasks/deploy.rake +17 -15
- data/lib/capistrano/tasks/framework.rake +1 -0
- data/lib/capistrano/tasks/git.rake +16 -10
- data/lib/capistrano/tasks/hg.rake +13 -9
- data/lib/capistrano/templates/Capfile +1 -2
- data/lib/capistrano/templates/deploy.rb.erb +20 -2
- data/lib/capistrano/templates/stage.rb.erb +1 -4
- data/lib/capistrano/version.rb +1 -1
- data/spec/integration/dsl_spec.rb +147 -2
- data/spec/lib/capistrano/application_spec.rb +2 -5
- data/spec/lib/capistrano/configuration/server_spec.rb +40 -4
- data/spec/lib/capistrano/configuration/servers/host_filter_spec.rb +84 -0
- data/spec/lib/capistrano/configuration/servers_spec.rb +35 -0
- data/spec/lib/capistrano/configuration_spec.rb +8 -0
- data/spec/lib/capistrano/dsl_spec.rb +0 -11
- data/spec/lib/capistrano/git_spec.rb +70 -0
- data/spec/lib/capistrano/hg_spec.rb +70 -0
- data/spec/lib/capistrano/scm_spec.rb +104 -0
- data/spec/support/tasks/fail.cap +7 -0
- data/spec/support/tasks/failed.cap +5 -0
- data/spec/support/test_app.rb +33 -3
- metadata +29 -52
- data/spec/lib/capistrano/dsl/env_spec.rb +0 -10
data/lib/capistrano/setup.rb
CHANGED
@@ -8,11 +8,12 @@ end
|
|
8
8
|
|
9
9
|
stages.each do |stage|
|
10
10
|
Rake::Task.define_task(stage) do
|
11
|
+
set(:stage, stage.to_sym)
|
12
|
+
|
11
13
|
invoke 'load:defaults'
|
12
|
-
load
|
13
|
-
load "
|
14
|
+
load deploy_config_path
|
15
|
+
load stage_config_path.join("#{stage}.rb")
|
14
16
|
load "capistrano/#{fetch(:scm)}.rb"
|
15
|
-
set(:stage, stage.to_sym)
|
16
17
|
I18n.locale = fetch(:locale, :en)
|
17
18
|
configure_backend
|
18
19
|
end
|
@@ -4,7 +4,15 @@ task :console do
|
|
4
4
|
puts I18n.t('console.welcome', scope: :capistrano, stage: stage)
|
5
5
|
loop do
|
6
6
|
print "#{stage}> "
|
7
|
-
|
7
|
+
|
8
|
+
if input = $stdin.gets
|
9
|
+
command = input.chomp
|
10
|
+
else
|
11
|
+
command = 'exit'
|
12
|
+
end
|
13
|
+
|
14
|
+
next if command.empty?
|
15
|
+
|
8
16
|
if %w{quit exit q}.include? command
|
9
17
|
puts t('console.bye')
|
10
18
|
break
|
@@ -15,7 +15,6 @@ namespace :deploy do
|
|
15
15
|
|
16
16
|
task :publishing do
|
17
17
|
invoke 'deploy:symlink:release'
|
18
|
-
invoke 'deploy:restart'
|
19
18
|
end
|
20
19
|
|
21
20
|
task :finishing do
|
@@ -42,7 +41,7 @@ namespace :deploy do
|
|
42
41
|
namespace :check do
|
43
42
|
desc 'Check shared and release directories exist'
|
44
43
|
task :directories do
|
45
|
-
on
|
44
|
+
on release_roles :all do
|
46
45
|
execute :mkdir, '-pv', shared_path, releases_path
|
47
46
|
end
|
48
47
|
end
|
@@ -50,15 +49,15 @@ namespace :deploy do
|
|
50
49
|
desc 'Check directories to be linked exist in shared'
|
51
50
|
task :linked_dirs do
|
52
51
|
next unless any? :linked_dirs
|
53
|
-
on
|
52
|
+
on release_roles :all do
|
54
53
|
execute :mkdir, '-pv', linked_dirs(shared_path)
|
55
54
|
end
|
56
55
|
end
|
57
|
-
|
56
|
+
|
58
57
|
desc 'Check directories of files to be linked exist in shared'
|
59
58
|
task :make_linked_dirs do
|
60
59
|
next unless any? :linked_files
|
61
|
-
on
|
60
|
+
on release_roles :all do |host|
|
62
61
|
execute :mkdir, '-pv', linked_file_dirs(shared_path)
|
63
62
|
end
|
64
63
|
end
|
@@ -66,7 +65,7 @@ namespace :deploy do
|
|
66
65
|
desc 'Check files to be linked exist in shared'
|
67
66
|
task :linked_files do
|
68
67
|
next unless any? :linked_files
|
69
|
-
on
|
68
|
+
on release_roles :all do |host|
|
70
69
|
linked_files(shared_path).each do |file|
|
71
70
|
unless test "[ -f #{file} ]"
|
72
71
|
error t(:linked_file_does_not_exist, file: file, host: host)
|
@@ -80,7 +79,7 @@ namespace :deploy do
|
|
80
79
|
namespace :symlink do
|
81
80
|
desc 'Symlink release to current'
|
82
81
|
task :release do
|
83
|
-
on
|
82
|
+
on release_roles :all do
|
84
83
|
execute :rm, '-rf', current_path
|
85
84
|
execute :ln, '-s', release_path, current_path
|
86
85
|
end
|
@@ -95,7 +94,7 @@ namespace :deploy do
|
|
95
94
|
desc 'Symlink linked directories'
|
96
95
|
task :linked_dirs do
|
97
96
|
next unless any? :linked_dirs
|
98
|
-
on
|
97
|
+
on release_roles :all do
|
99
98
|
execute :mkdir, '-pv', linked_dir_parents(release_path)
|
100
99
|
|
101
100
|
fetch(:linked_dirs).each do |dir|
|
@@ -114,7 +113,7 @@ namespace :deploy do
|
|
114
113
|
desc 'Symlink linked files'
|
115
114
|
task :linked_files do
|
116
115
|
next unless any? :linked_files
|
117
|
-
on
|
116
|
+
on release_roles :all do
|
118
117
|
execute :mkdir, '-pv', linked_file_dirs(release_path)
|
119
118
|
|
120
119
|
fetch(:linked_files).each do |file|
|
@@ -133,7 +132,7 @@ namespace :deploy do
|
|
133
132
|
|
134
133
|
desc 'Clean up old releases'
|
135
134
|
task :cleanup do
|
136
|
-
on
|
135
|
+
on release_roles :all do |host|
|
137
136
|
releases = capture(:ls, '-x', releases_path).split
|
138
137
|
if releases.count >= fetch(:keep_releases)
|
139
138
|
info t(:keeping_releases, host: host.to_s, keep_releases: fetch(:keep_releases), releases: releases.count)
|
@@ -152,7 +151,7 @@ namespace :deploy do
|
|
152
151
|
|
153
152
|
desc 'Remove and archive rolled-back release.'
|
154
153
|
task :cleanup_rollback do
|
155
|
-
on
|
154
|
+
on release_roles(:all) do
|
156
155
|
last_release = capture(:ls, '-xr', releases_path).split.first
|
157
156
|
last_release_path = releases_path.join(last_release)
|
158
157
|
if test "[ `readlink #{current_path}` != #{last_release_path} ]"
|
@@ -168,7 +167,7 @@ namespace :deploy do
|
|
168
167
|
|
169
168
|
desc 'Log details of the deploy'
|
170
169
|
task :log_revision do
|
171
|
-
on
|
170
|
+
on release_roles(:all) do
|
172
171
|
within releases_path do
|
173
172
|
execute %{echo "#{revision_log_message}" >> #{revision_log}}
|
174
173
|
end
|
@@ -177,7 +176,7 @@ namespace :deploy do
|
|
177
176
|
|
178
177
|
desc 'Revert to previous release timestamp'
|
179
178
|
task :revert_release => :rollback_release_path do
|
180
|
-
on
|
179
|
+
on release_roles(:all) do
|
181
180
|
set(:revision_log_message, rollback_log_message)
|
182
181
|
end
|
183
182
|
end
|
@@ -187,18 +186,21 @@ namespace :deploy do
|
|
187
186
|
end
|
188
187
|
|
189
188
|
task :last_release_path do
|
190
|
-
on
|
189
|
+
on release_roles(:all) do
|
191
190
|
last_release = capture(:ls, '-xr', releases_path).split[1]
|
192
191
|
set_release_path(last_release)
|
193
192
|
end
|
194
193
|
end
|
195
194
|
|
196
195
|
task :rollback_release_path do
|
197
|
-
on
|
196
|
+
on release_roles(:all) do
|
198
197
|
last_release = capture(:ls, '-xr', releases_path).split[1]
|
199
198
|
set_release_path(last_release)
|
200
199
|
set(:rollback_timestamp, last_release)
|
201
200
|
end
|
202
201
|
end
|
203
202
|
|
203
|
+
task :restart
|
204
|
+
task :failed
|
205
|
+
|
204
206
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
namespace :git do
|
2
2
|
|
3
|
+
def strategy
|
4
|
+
@strategy ||= Capistrano::Git.new(self, fetch(:git_strategy, Capistrano::Git::DefaultStrategy))
|
5
|
+
end
|
6
|
+
|
3
7
|
set :git_environmental_variables, ->() {
|
4
8
|
{
|
5
9
|
git_askpass: "/bin/echo",
|
@@ -9,7 +13,7 @@ namespace :git do
|
|
9
13
|
|
10
14
|
desc 'Upload the git wrapper script, this script guarantees that we can script git without getting an interactive prompt'
|
11
15
|
task :wrapper do
|
12
|
-
on
|
16
|
+
on release_roles :all do
|
13
17
|
execute :mkdir, "-p", "#{fetch(:tmp_dir)}/#{fetch(:application)}/"
|
14
18
|
upload! StringIO.new("#!/bin/sh -e\nexec /usr/bin/ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no \"$@\"\n"), "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
|
15
19
|
execute :chmod, "+x", "#{fetch(:tmp_dir)}/#{fetch(:application)}/git-ssh.sh"
|
@@ -19,22 +23,22 @@ namespace :git do
|
|
19
23
|
desc 'Check that the repository is reachable'
|
20
24
|
task check: :'git:wrapper' do
|
21
25
|
fetch(:branch)
|
22
|
-
on
|
26
|
+
on release_roles :all do
|
23
27
|
with fetch(:git_environmental_variables) do
|
24
|
-
exit 1 unless
|
28
|
+
exit 1 unless strategy.check
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
29
33
|
desc 'Clone the repo to the cache'
|
30
34
|
task clone: :'git:wrapper' do
|
31
|
-
on
|
32
|
-
if test
|
35
|
+
on release_roles :all do
|
36
|
+
if strategy.test
|
33
37
|
info t(:mirror_exists, at: repo_path)
|
34
38
|
else
|
35
39
|
within deploy_path do
|
36
40
|
with fetch(:git_environmental_variables) do
|
37
|
-
|
41
|
+
strategy.clone
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
@@ -43,20 +47,22 @@ namespace :git do
|
|
43
47
|
|
44
48
|
desc 'Update the repo mirror to reflect the origin state'
|
45
49
|
task update: :'git:clone' do
|
46
|
-
on
|
50
|
+
on release_roles :all do
|
47
51
|
within repo_path do
|
48
|
-
|
52
|
+
capturing_revisions do
|
53
|
+
strategy.update
|
54
|
+
end
|
49
55
|
end
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
53
59
|
desc 'Copy repo to releases'
|
54
60
|
task create_release: :'git:update' do
|
55
|
-
on
|
61
|
+
on release_roles :all do
|
56
62
|
with fetch(:git_environmental_variables) do
|
57
63
|
within repo_path do
|
58
64
|
execute :mkdir, '-p', release_path
|
59
|
-
|
65
|
+
strategy.release
|
60
66
|
end
|
61
67
|
end
|
62
68
|
end
|
@@ -1,19 +1,23 @@
|
|
1
1
|
namespace :hg do
|
2
|
+
def strategy
|
3
|
+
@strategy ||= Capistrano::Hg.new(self, fetch(:hg_strategy, Capistrano::Hg::DefaultStrategy))
|
4
|
+
end
|
5
|
+
|
2
6
|
desc 'Check that the repo is reachable'
|
3
7
|
task :check do
|
4
|
-
on
|
5
|
-
|
8
|
+
on release_roles :all do
|
9
|
+
strategy.check
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
9
13
|
desc 'Clone the repo to the cache'
|
10
14
|
task :clone do
|
11
|
-
on
|
12
|
-
if test
|
15
|
+
on release_roles :all do
|
16
|
+
if strategy.test
|
13
17
|
info t(:mirror_exists, at: repo_path)
|
14
18
|
else
|
15
19
|
within deploy_path do
|
16
|
-
|
20
|
+
strategy.clone
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -21,18 +25,18 @@ namespace :hg do
|
|
21
25
|
|
22
26
|
desc 'Pull changes from the remote repo'
|
23
27
|
task :update => :'hg:clone' do
|
24
|
-
on
|
28
|
+
on release_roles :all do
|
25
29
|
within repo_path do
|
26
|
-
|
30
|
+
strategy.update
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
35
|
desc 'Copy repo to releases'
|
32
36
|
task :create_release => :'hg:update' do
|
33
|
-
on
|
37
|
+
on release_roles :all do
|
34
38
|
within repo_path do
|
35
|
-
|
39
|
+
strategy.release
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
@@ -12,8 +12,7 @@ require 'capistrano/deploy'
|
|
12
12
|
# https://github.com/capistrano/rbenv
|
13
13
|
# https://github.com/capistrano/chruby
|
14
14
|
# https://github.com/capistrano/bundler
|
15
|
-
# https://github.com/capistrano/rails
|
16
|
-
# https://github.com/capistrano/rails/tree/master/migrations
|
15
|
+
# https://github.com/capistrano/rails
|
17
16
|
#
|
18
17
|
# require 'capistrano/rvm'
|
19
18
|
# require 'capistrano/rbenv'
|
@@ -1,19 +1,37 @@
|
|
1
|
+
# config valid only for Capistrano 3.1
|
2
|
+
lock '<%= Capistrano::VERSION %>'
|
3
|
+
|
1
4
|
set :application, 'my_app_name'
|
2
5
|
set :repo_url, 'git@example.com:me/my_repo.git'
|
3
6
|
|
7
|
+
# Default branch is :master
|
4
8
|
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
|
5
9
|
|
10
|
+
# Default deploy_to directory is /var/www/my_app
|
6
11
|
# set :deploy_to, '/var/www/my_app'
|
12
|
+
|
13
|
+
# Default value for :scm is :git
|
7
14
|
# set :scm, :git
|
8
15
|
|
16
|
+
# Default value for :format is :pretty
|
9
17
|
# set :format, :pretty
|
18
|
+
|
19
|
+
# Default value for :log_level is :debug
|
10
20
|
# set :log_level, :debug
|
21
|
+
|
22
|
+
# Default value for :pty is false
|
11
23
|
# set :pty, true
|
12
24
|
|
25
|
+
# Default value for :linked_files is []
|
13
26
|
# set :linked_files, %w{config/database.yml}
|
27
|
+
|
28
|
+
# Default value for linked_dirs is []
|
14
29
|
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
|
15
30
|
|
31
|
+
# Default value for default_env is {}
|
16
32
|
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
|
33
|
+
|
34
|
+
# Default value for keep_releases is 5
|
17
35
|
# set :keep_releases, 5
|
18
36
|
|
19
37
|
namespace :deploy do
|
@@ -26,6 +44,8 @@ namespace :deploy do
|
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
47
|
+
after :publishing, :restart
|
48
|
+
|
29
49
|
after :restart, :clear_cache do
|
30
50
|
on roles(:web), in: :groups, limit: 3, wait: 10 do
|
31
51
|
# Here we can do anything such as:
|
@@ -35,6 +55,4 @@ namespace :deploy do
|
|
35
55
|
end
|
36
56
|
end
|
37
57
|
|
38
|
-
after :finishing, 'deploy:cleanup'
|
39
|
-
|
40
58
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
set :stage, :<%= stage %>
|
2
|
-
|
3
1
|
# Simple Role Syntax
|
4
2
|
# ==================
|
5
3
|
# Supports bulk-adding hosts to roles, the primary
|
6
4
|
# server in each group is considered to be the first
|
7
5
|
# unless any hosts have the primary property set.
|
6
|
+
# Don't declare `role :all`, it's a meta role
|
8
7
|
role :app, %w{deploy@example.com}
|
9
8
|
role :web, %w{deploy@example.com}
|
10
9
|
role :db, %w{deploy@example.com}
|
@@ -38,5 +37,3 @@ server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
|
|
38
37
|
# # password: 'please use keys'
|
39
38
|
# }
|
40
39
|
# setting per server overrides global ssh_options
|
41
|
-
|
42
|
-
# fetch(:default_env).merge!(rails_env: :<%= stage %>)
|
data/lib/capistrano/version.rb
CHANGED
@@ -4,6 +4,10 @@ describe Capistrano::DSL do
|
|
4
4
|
|
5
5
|
let(:dsl) { Class.new.extend Capistrano::DSL }
|
6
6
|
|
7
|
+
before do
|
8
|
+
Capistrano::Configuration.reset!
|
9
|
+
end
|
10
|
+
|
7
11
|
describe 'setting and fetching hosts' do
|
8
12
|
describe 'when defining a host using the `server` syntax' do
|
9
13
|
before do
|
@@ -11,13 +15,33 @@ describe Capistrano::DSL do
|
|
11
15
|
dsl.server 'example2.com', roles: %w{web}
|
12
16
|
dsl.server 'example3.com', roles: %w{app web}, active: true
|
13
17
|
dsl.server 'example4.com', roles: %w{app}, primary: true
|
18
|
+
dsl.server 'example5.com', roles: %w{db}, no_release: true
|
14
19
|
end
|
15
20
|
|
16
21
|
describe 'fetching all servers' do
|
17
22
|
subject { dsl.roles(:all) }
|
18
23
|
|
19
24
|
it 'returns all servers' do
|
20
|
-
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
25
|
+
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'fetching all release servers' do
|
30
|
+
|
31
|
+
context 'with no additional options' do
|
32
|
+
subject { dsl.release_roles(:all) }
|
33
|
+
|
34
|
+
it 'returns all release servers' do
|
35
|
+
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with filter options' do
|
40
|
+
subject { dsl.release_roles(:all, filter: :active) }
|
41
|
+
|
42
|
+
it 'returns all release servers that match the filter' do
|
43
|
+
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
44
|
+
end
|
21
45
|
end
|
22
46
|
end
|
23
47
|
|
@@ -36,6 +60,14 @@ describe Capistrano::DSL do
|
|
36
60
|
end
|
37
61
|
end
|
38
62
|
|
63
|
+
describe 'fetching servers by an array of roles' do
|
64
|
+
subject { dsl.roles([:app]) }
|
65
|
+
|
66
|
+
it 'returns the servers' do
|
67
|
+
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
39
71
|
describe 'fetching filtered servers by role' do
|
40
72
|
subject { dsl.roles(:app, filter: :active) }
|
41
73
|
|
@@ -70,6 +102,14 @@ describe Capistrano::DSL do
|
|
70
102
|
|
71
103
|
end
|
72
104
|
|
105
|
+
describe 'when defining role with reserved name' do
|
106
|
+
it 'fails with ArgumentError' do
|
107
|
+
expect {
|
108
|
+
dsl.role :all, %w{example1.com}
|
109
|
+
}.to raise_error(ArgumentError, "all reserved name for role. Please choose another name")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
73
113
|
describe 'when defining hosts using the `role` syntax' do
|
74
114
|
before do
|
75
115
|
dsl.role :web, %w{example1.com example2.com example3.com}
|
@@ -77,16 +117,37 @@ describe Capistrano::DSL do
|
|
77
117
|
dsl.role :app, %w{example3.com example4.com}
|
78
118
|
dsl.role :app, %w{example3.com}, active: true
|
79
119
|
dsl.role :app, %w{example4.com}, primary: true
|
120
|
+
dsl.role :db, %w{example5.com}, no_release: true
|
80
121
|
end
|
81
122
|
|
82
123
|
describe 'fetching all servers' do
|
83
124
|
subject { dsl.roles(:all) }
|
84
125
|
|
85
126
|
it 'returns all servers' do
|
86
|
-
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
127
|
+
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
87
128
|
end
|
88
129
|
end
|
89
130
|
|
131
|
+
describe 'fetching all release servers' do
|
132
|
+
|
133
|
+
context 'with no additional options' do
|
134
|
+
subject { dsl.release_roles(:all) }
|
135
|
+
|
136
|
+
it 'returns all release servers' do
|
137
|
+
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'with filter options' do
|
142
|
+
subject { dsl.release_roles(:all, filter: :active) }
|
143
|
+
|
144
|
+
it 'returns all release servers that match the filter' do
|
145
|
+
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
90
151
|
describe 'fetching servers by role' do
|
91
152
|
subject { dsl.roles(:app) }
|
92
153
|
|
@@ -95,6 +156,14 @@ describe Capistrano::DSL do
|
|
95
156
|
end
|
96
157
|
end
|
97
158
|
|
159
|
+
describe 'fetching servers by an array of roles' do
|
160
|
+
subject { dsl.roles([:app]) }
|
161
|
+
|
162
|
+
it 'returns the servers' do
|
163
|
+
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
98
167
|
describe 'fetching filtered servers by role' do
|
99
168
|
subject { dsl.roles(:app, filter: :active) }
|
100
169
|
|
@@ -129,6 +198,34 @@ describe Capistrano::DSL do
|
|
129
198
|
|
130
199
|
end
|
131
200
|
|
201
|
+
describe 'when defining a host using a combination of the `server` and `role` syntax' do
|
202
|
+
|
203
|
+
before do
|
204
|
+
dsl.server 'example1.com:1234', roles: %w{web}, active: true
|
205
|
+
dsl.server 'example1.com:5678', roles: %w{web}, active: true
|
206
|
+
dsl.role :app, %w{example1.com:5678}
|
207
|
+
end
|
208
|
+
|
209
|
+
describe 'fetching all servers' do
|
210
|
+
subject { dsl.roles(:all).map { |server| "#{server.hostname}:#{server.port}" } }
|
211
|
+
|
212
|
+
it 'creates a server instance for each unique host:port combination' do
|
213
|
+
expect(subject).to eq %w{example1.com:1234 example1.com:5678}
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe 'fetching servers for a role' do
|
218
|
+
it 'roles defined using the `server` syntax are included' do
|
219
|
+
expect(dsl.roles(:web)).to have(2).items
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'roles defined using the `role` syntax are included' do
|
223
|
+
expect(dsl.roles(:app)).to have(1).items
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
132
229
|
end
|
133
230
|
|
134
231
|
describe 'setting and fetching variables' do
|
@@ -340,5 +437,53 @@ describe Capistrano::DSL do
|
|
340
437
|
end
|
341
438
|
end
|
342
439
|
|
440
|
+
describe 'setting deploy configuration path' do
|
441
|
+
subject { dsl.deploy_config_path.to_s }
|
442
|
+
|
443
|
+
context 'where no config path is set' do
|
444
|
+
before do
|
445
|
+
dsl.delete(:deploy_config_path)
|
446
|
+
end
|
447
|
+
|
448
|
+
it 'returns "config/deploy.rb"' do
|
449
|
+
expect(subject).to eq 'config/deploy.rb'
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
context 'where a custom path is set' do
|
454
|
+
before do
|
455
|
+
dsl.set(:deploy_config_path, 'my/custom/path.rb')
|
456
|
+
end
|
457
|
+
|
458
|
+
it 'returns the custom path' do
|
459
|
+
expect(subject).to eq 'my/custom/path.rb'
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
describe 'setting stage configuration path' do
|
465
|
+
subject { dsl.stage_config_path.to_s }
|
466
|
+
|
467
|
+
context 'where no config path is set' do
|
468
|
+
|
469
|
+
before do
|
470
|
+
dsl.delete(:stage_config_path)
|
471
|
+
end
|
472
|
+
|
473
|
+
it 'returns "config/deploy"' do
|
474
|
+
expect(subject).to eq 'config/deploy'
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
context 'where a custom path is set' do
|
479
|
+
before do
|
480
|
+
dsl.set(:stage_config_path, 'my/custom/path')
|
481
|
+
end
|
482
|
+
|
483
|
+
it 'returns the custom path' do
|
484
|
+
expect(subject).to eq 'my/custom/path'
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
343
488
|
end
|
344
489
|
end
|