Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The commit introduces a `remote_file` task, allowing the existence of a remote file to be set as a prerequisite. These tasks can in turn depend on local files if required. In this implementation, the fact that we're dealing with a file in the shared path is assumed. As as example, this task can be used to ensure that files to be linked exist before running the `check:linked_files` task: namespace :deploy do namespace :check do task :linked_files => 'config/newrelic.yml' end end remote_file 'config/newrelic.yml' => '/tmp/newrelic.yml', roles: :app file '/tmp/newrelic.yml' do |t| sh "curl -o #{t.name} https://rpm.newrelic.com/accounts/xx/newrelic.yml" end
- Loading branch information
1 parent
251956c
commit ba0d313
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'integration_spec_helper' | ||
|
||
describe 'cap deploy:started', slow: true do | ||
before do | ||
install_test_app_with(config) | ||
copy_task_to_test_app('spec/support/tasks/database.cap') | ||
end | ||
|
||
let(:config) { | ||
%{ | ||
set :stage, :#{stage} | ||
set :deploy_to, '#{deploy_to}' | ||
set :repo_url, 'git://github.com/capistrano/capistrano.git' | ||
set :branch, 'v3' | ||
server 'localhost', roles: %w{web app}, user: '#{current_user}' | ||
set :linked_files, %w{config/database.yml} | ||
set :linked_dirs, %w{config} | ||
} | ||
} | ||
|
||
describe 'linked_files' do | ||
|
||
before do | ||
cap 'deploy:check:linked_dirs' | ||
end | ||
|
||
subject { cap 'deploy:check:linked_files' } | ||
|
||
context 'where the file does not exist' do | ||
it 'creates the file with the remote_task prerequisite' do | ||
expect(subject).to match 'Uploading' | ||
expect(subject).not_to match 'config/database.yml does not exist' | ||
expect(subject).to match 'successful' | ||
end | ||
end | ||
|
||
context 'where the file already exists' do | ||
before do | ||
FileUtils.touch(shared_path.join('config/database.yml')) | ||
end | ||
|
||
it 'will not recreate the file if it already exists' do | ||
expect(subject).not_to match 'Uploading' | ||
expect(subject).not_to match 'config/database.yml does not exist' | ||
expect(subject).to match 'successful' | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace :deploy do | ||
namespace :check do | ||
task :linked_files => 'config/database.yml' | ||
end | ||
end | ||
|
||
remote_file 'config/database.yml' => '/tmp/database.yml', roles: :all | ||
|
||
file '/tmp/database.yml' do |t| | ||
sh "touch #{t.name}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters