1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Focus deploy task

Placeholder descriptions added, symlink tasks now ensure parent
directories exist
This commit is contained in:
seenmyfate 2013-03-15 21:30:51 +00:00
parent 8e75196dc2
commit dcc513843a
4 changed files with 79 additions and 75 deletions

View file

@ -22,6 +22,8 @@ TODO:
- [x] support set/fetch/role configuration - [x] support set/fetch/role configuration
- [x] basic deploy - [x] basic deploy
- [x] ask - [x] ask
- [x] add `deploy:check`
- [ ] simplify default deploy
- [ ] prefer `roles(:all)` over `all_roles` - [ ] prefer `roles(:all)` over `all_roles`
- [ ] support primary servers `on primary(:db)` - [ ] support primary servers `on primary(:db)`
- [ ] basic rollback - [ ] basic rollback

View file

@ -1,3 +1,4 @@
desc 'Execute remote commands'
task :console do task :console do
stage = fetch(:stage) stage = fetch(:stage)
puts I18n.t('console.welcome', scope: :capistrano, stage: stage) puts I18n.t('console.welcome', scope: :capistrano, stage: stage)

View file

@ -1,7 +1,7 @@
namespace :deploy do namespace :deploy do
task :started do task :started do
invoke 'deploy:ensure:directories' invoke 'deploy:check'
invoke "#{scm}:prepare"
end end
task :update do task :update do
@ -11,24 +11,22 @@ namespace :deploy do
task :finalize do task :finalize do
invoke 'deploy:symlink:release' invoke 'deploy:symlink:release'
invoke 'deploy:normalise_assets'
end
after :restart, 'deploy:web:ensure'
task :finishing do
invoke 'deploy:cleanup'
end end
task :finished do task :finished do
invoke 'deploy:log_revision' invoke 'deploy:log_revision'
end end
namespace :check do desc 'Check required files and directories exist'
task :check do
invoke "#{scm}:check"
invoke 'deploy:check:directories'
invoke 'deploy:check:linked_dirs'
invoke 'deploy:check:linked_files'
end end
namespace :ensure do namespace :check do
desc 'Check shared and release directories exist'
task :directories do task :directories do
on all do on all do
unless test "[ -d #{shared_path} ]" unless test "[ -d #{shared_path} ]"
@ -40,41 +38,9 @@ namespace :deploy do
end end
end end
end end
end
namespace :symlink do desc 'Check directories to be linked exist in shared'
task :release do task :linked_dirs do
on all do
execute :rm, '-rf', current_path
execute :ln, '-s', release_path, current_path
end
end
task :shared do
# configuration exists
on all do
fetch(:linked_files).each do |file|
unless test "[ -f #{shared_path}/#{file} ]"
# create config file
end
end
end
# configuration is symlinked
on all do
fetch(:linked_files).each do |file|
target = File.join(release_path, file)
source = File.join(shared_path, file)
unless test "[ -L #{target} ]"
if test "[ -f #{target} ]"
execute :rm, target
end
execute :ln, '-s', source, target
end
end
end
# tmp/log/public folders exist in shared
on all do on all do
fetch(:linked_dirs).each do |dir| fetch(:linked_dirs).each do |dir|
dir = File.join(shared_path, dir) dir = File.join(shared_path, dir)
@ -83,12 +49,50 @@ namespace :deploy do
end end
end end
end end
end
# tmp/log/public folders are symlinked desc 'Check files to be linked exist in shared'
task :linked_files do
on all do
fetch(:linked_files).each do |file|
parent = File.join(shared_path, File.dirname(file))
unless test "[ -d #{parent} ]"
execute :mkdir, '-p', parent
end
unless test "[ -f #{File.join(shared_path, file)} ]"
error "linked file #{file} does not exist"
exit 1
end
end
end
end
end
namespace :symlink do
desc 'Symlink release to current'
task :release do
on all do
execute :rm, '-rf', current_path
execute :ln, '-s', release_path, current_path
end
end
desc 'Symlink files and directories from shared to release'
task :shared do
invoke 'deploy:symlink:linked_files'
invoke 'deploy:symlink:linked_dirs'
end
desc 'Symlink linked directories'
task :linked_dirs do
on all do on all do
fetch(:linked_dirs).each do |dir| fetch(:linked_dirs).each do |dir|
target = File.join(release_path, dir) target = File.join(release_path, dir)
source = File.join(shared_path, dir) source = File.join(shared_path, dir)
parent = File.join(release_path, File.dirname(dir))
unless test "[ -d #{parent} ]"
execute :mkdir, '-p', parent
end
unless test "[ -L #{target} ]" unless test "[ -L #{target} ]"
if test "[ -f #{target} ]" if test "[ -f #{target} ]"
execute :rm, '-rf', target execute :rm, '-rf', target
@ -98,38 +102,29 @@ namespace :deploy do
end end
end end
end end
end
namespace :web do desc 'Symlink linked files'
task :ensure do task :linked_files do
on roles(:web) do on all do
within shared_path do fetch(:linked_files).each do |file|
file = File.join(shared_path, maintenance_page) target = File.join(release_path, file)
if test "[ -f #{shared_path}/#{file} ]" source = File.join(shared_path, file)
execute :rm, file parent = File.join(release_path, File.dirname(file))
unless test "[ -d #{parent} ]"
execute :mkdir, '-p', parent
end
unless test "[ -L #{target} ]"
if test "[ -f #{target} ]"
execute :rm, target
end
execute :ln, '-s', source, target
end end
end end
end end
end end
end end
task :disable do desc 'Clean up old releases'
on all do
within shared_path do
execute :touch, maintenance_page
end
end
end
task :normalise_assets do
on roles(:web) do
within release_path do
assets = %{public/images public/javascripts public/stylesheets}
execute :find, "#{assets} -exec touch -t #{asset_timestamp} {} ';'; true"
end
end
end
task :cleanup do task :cleanup do
on all do on all do
count = fetch(:keep_releases, 5).to_i count = fetch(:keep_releases, 5).to_i
@ -143,6 +138,7 @@ namespace :deploy do
end end
end end
desc 'Log details of the deploy'
task :log_revision do task :log_revision do
on roles(:web) do on roles(:web) do
within releases_path do within releases_path do

View file

@ -1,5 +1,7 @@
namespace :git do namespace :git do
task :prepare do
desc 'Check that the repository exists'
task :check do
on all do on all do
unless test "[ -d #{repo_path} ]" unless test "[ -d #{repo_path} ]"
within deploy_path do within deploy_path do
@ -9,12 +11,14 @@ namespace :git do
end end
end end
desc 'Update the repo and copy to releases'
task :update do task :update do
invoke 'git:reset_to_ref' invoke 'git:reset'
invoke 'git:create_release' invoke 'git:create_release'
end end
task :reset_to_ref do desc 'Update the repo to branch or reference provided provided'
task :reset do
on all do on all do
within repo_path do within repo_path do
execute :git, 'fetch origin' execute :git, 'fetch origin'
@ -23,6 +27,7 @@ namespace :git do
end end
end end
desc 'Copy repo to releases'
task :create_release do task :create_release do
on all do on all do
execute :cp, "-RPp", repo_path, release_path execute :cp, "-RPp", repo_path, release_path