diff --git a/README.md b/README.md index 7a1c9742..55428f61 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Where calling on the same task name, executed in order of inclusion ## Console -Execute arbitrary remote commands as `deploy_user` +Execute arbitrary remote commands $ cap staging console diff --git a/lib/capistrano/dsl.rb b/lib/capistrano/dsl.rb index 3fc68b40..0d875a6e 100644 --- a/lib/capistrano/dsl.rb +++ b/lib/capistrano/dsl.rb @@ -20,10 +20,6 @@ module Capistrano I18n.t(*args, scope: :capistrano) end - def deploy_user - fetch(:deploy_user) - end - def scm fetch(:scm) end diff --git a/lib/capistrano/tasks/bundler.rake b/lib/capistrano/tasks/bundler.rake index c104ad6f..9b5e3be2 100644 --- a/lib/capistrano/tasks/bundler.rake +++ b/lib/capistrano/tasks/bundler.rake @@ -2,10 +2,8 @@ namespace :deploy do after :update, :bundle do on all do - as deploy_user do - within release_path do - execute :bundle, "--gemfile #{release_path}/Gemfile --deployment --binstubs #{shared_path}/bin --path #{shared_path}/bundle --without development test cucumber" - end + within release_path do + execute :bundle, "--gemfile #{release_path}/Gemfile --deployment --binstubs #{shared_path}/bin --path #{shared_path}/bundle --without development test cucumber" end end end diff --git a/lib/capistrano/tasks/console.rake b/lib/capistrano/tasks/console.rake index bb6de5a7..5c14e198 100644 --- a/lib/capistrano/tasks/console.rake +++ b/lib/capistrano/tasks/console.rake @@ -10,9 +10,7 @@ task :console do else begin on all do - as deploy_user do - execute command - end + execute command end rescue => e puts e diff --git a/lib/capistrano/tasks/deploy.rake b/lib/capistrano/tasks/deploy.rake index 65751254..82a75980 100644 --- a/lib/capistrano/tasks/deploy.rake +++ b/lib/capistrano/tasks/deploy.rake @@ -1,7 +1,5 @@ namespace :deploy do task :started do - invoke 'deploy:check:user' - invoke 'deploy:check:permissions' invoke 'deploy:ensure:directories' invoke "#{scm}:prepare" end @@ -27,36 +25,18 @@ namespace :deploy do end namespace :check do - task :user do - on all do - unless test("getent passwd \"#{deploy_user}\" > /dev/null") - error t('error.user.does_not_exist', user: deploy_user) - end - end - end - task :permissions do - on all do - unless test("sudo su #{deploy_user} -c whoami > /dev/null") - error t('error.user.cannot_switch', user: deploy_user) - end - end - end end namespace :ensure do task :directories do on all do unless test "[ -d #{shared_path} ]" - as deploy_user do - execute :mkdir, '-p', shared_path - end + execute :mkdir, '-p', shared_path end unless test "[ -d #{releases_path} ]" - as deploy_user do - execute :mkdir, '-p', releases_path - end + execute :mkdir, '-p', releases_path end end end @@ -65,65 +45,55 @@ namespace :deploy do namespace :symlink do task :release do on all do - as deploy_user do - execute :rm, '-rf', current_path - execute :ln, '-s', release_path, current_path - end + execute :rm, '-rf', current_path + execute :ln, '-s', release_path, current_path end end task :shared do # configuration exists on all do - as deploy_user do - fetch(:linked_files).each do |file| - unless test "[ -f #{shared_path}/#{file} ]" - # create config file - end + fetch(:linked_files).each do |file| + unless test "[ -f #{shared_path}/#{file} ]" + # create config file end end end # configuration is symlinked on all do - as deploy_user 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 + 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 end # tmp/log/public folders exist in shared on all do - as deploy_user do - fetch(:linked_dirs).each do |dir| - dir = File.join(shared_path, dir) - unless test "[ -d #{dir} ]" - execute :mkdir, '-p', dir - end + fetch(:linked_dirs).each do |dir| + dir = File.join(shared_path, dir) + unless test "[ -d #{dir} ]" + execute :mkdir, '-p', dir end end end # tmp/log/public folders are symlinked on all do - as deploy_user do - fetch(:linked_dirs).each do |dir| - target = File.join(release_path, dir) - source = File.join(shared_path, dir) - unless test "[ -L #{target} ]" - if test "[ -f #{target} ]" - execute :rm, '-rf', target + fetch(:linked_dirs).each do |dir| + target = File.join(release_path, dir) + source = File.join(shared_path, dir) + unless test "[ -L #{target} ]" + if test "[ -f #{target} ]" + execute :rm, '-rf', target end execute :ln, '-s', source, target - end end end end @@ -133,12 +103,10 @@ namespace :deploy do namespace :web do task :ensure do on roles(:web) do - as deploy_user do - within shared_path do - file = File.join(shared_path, maintenance_page) - if test "[ -f #{shared_path}/#{file} ]" - execute :rm, file - end + within shared_path do + file = File.join(shared_path, maintenance_page) + if test "[ -f #{shared_path}/#{file} ]" + execute :rm, file end end end @@ -147,46 +115,38 @@ namespace :deploy do task :disable do on all do - as deploy_user do - within shared_path do - execute :touch, maintenance_page - end + within shared_path do + execute :touch, maintenance_page end end end task :normalise_assets do on roles(:web) do - as deploy_user do - within release_path do - assets = %{public/images public/javascripts public/stylesheets} - execute :find, "#{assets} -exec touch -t #{asset_timestamp} {} ';'; true" - end + 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 on all do - as deploy_user do - count = fetch(:keep_releases, 5).to_i - releases = capture("ls -xt #{releases_path}").split.reverse - if releases.length >= count - info "keeping #{count} of #{releases.length} deployed releases" - directories = (releases - releases.last(count)).map { |release| - File.join(releases_path, release) }.join(" ") - execute :rm, '-rf', directories - end + count = fetch(:keep_releases, 5).to_i + releases = capture("ls -xt #{releases_path}").split.reverse + if releases.length >= count + info "keeping #{count} of #{releases.length} deployed releases" + directories = (releases - releases.last(count)).map { |release| + File.join(releases_path, release) }.join(" ") + execute :rm, '-rf', directories end end end task :log_revision do on roles(:web) do - as deploy_user do - within releases_path do - execute %{echo "#{revision_log_message}" >> #{revision_log}} - end + within releases_path do + execute %{echo "#{revision_log_message}" >> #{revision_log}} end end end diff --git a/lib/capistrano/tasks/git.rake b/lib/capistrano/tasks/git.rake index b063b043..673a6631 100644 --- a/lib/capistrano/tasks/git.rake +++ b/lib/capistrano/tasks/git.rake @@ -3,9 +3,7 @@ namespace :git do on all do unless test "[ -d #{repo_path} ]" within deploy_path do - as deploy_user do - execute :git, :clone, fetch(:repo), repo_path - end + execute :git, :clone, fetch(:repo), repo_path end end end @@ -18,20 +16,16 @@ namespace :git do task :reset_to_ref do on all do - as deploy_user do - within repo_path do - execute :git, 'fetch origin' - execute :git, "reset --hard origin/#{fetch(:branch)}" - end + within repo_path do + execute :git, 'fetch origin' + execute :git, "reset --hard origin/#{fetch(:branch)}" end end end task :create_release do on all do - as deploy_user do - execute :cp, "-RPp", repo_path, release_path - end + execute :cp, "-RPp", repo_path, release_path end end end