deploy:setup
的正确方法是什么deploy:setup
和使用Capistrano进行冷部署?
运用
deploy.rb
这是我的情景:
运行deploy:setup
,Capistrano利用root权限为部署准备目录结构:
$ cap deploy:setup * 2013-02-28 14:50:21 executing `deploy:setup' * executing "sudo -p 'sudo password: ' mkdir -p /home/vagrant/example /home/vagrant/example/releases /home/vagrant/example/shared /home/vagrant/example/shared/system /home/vagrant/example/shared/log /home/vagrant/example/shared/pids" servers: ["example.com"] [example.com] executing command command finished in 29ms * executing "sudo -p 'sudo password: ' chmod g+w /home/vagrant/example /home/vagrant/example/releases /home/vagrant/example/shared /home/vagrant/example/shared/system /home/vagrant/example/shared/log /home/vagrant/example/shared/pids" servers: ["example.com"] [example.com] executing command command finished in 11ms
尚未deploy:cold
Capistrano尝试签出(在这种情况下从git)并写为vagrant
用户 - 在deploy.rb
指定的用户:
$ cap deploy:cold * 2013-02-28 14:50:47 executing `deploy:cold' * 2013-02-28 14:50:47 executing `deploy:update' ** transaction: start * 2013-02-28 14:50:47 executing `deploy:update_code' updating the cached checkout on all servers executing locally: "git ls-remote [email protected]:mariusbutuc/realtime-faye.git master" command finished in 2360ms * executing "if [ -d /home/vagrant/example/shared/cached-copy ]; then cd /home/vagrant/example/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard a7c05516bc31c2c18f89057c02f84bfad83a6b59 && git clean -q -d -x -f; else git clone -q [email protected]:mariusbutuc/realtime-faye.git /home/vagrant/example/shared/cached-copy && cd /home/vagrant/example/shared/cached-copy && git checkout -q -b deploy a7c05516bc31c2c18f89057c02f84bfad83a6b59; fi" servers: ["example.com"] [example.com] executing command ** [example.com :: out] fatal: could not create work tree dir '/home/vagrant/example/shared/cached-copy'.: Permission denied command finished in 26ms *** [deploy:update_code] rolling back * executing "rm -rf /home/vagrant/example/releases/20130228195049; true" servers: ["example.com"] [example.com] executing command command finished in 7ms failed: "sh -c 'if [ -d /home/vagrant/example/shared/cached-copy ]; then cd /home/vagrant/example/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard a7c05516bc31c2c18f89057c02f84bfad83a6b59 && git clean -q -d -x -f; else git clone -q [email protected]:mariusbutuc/realtime-faye.git /home/vagrant/example/shared/cached-copy && cd /home/vagrant/example/shared/cached-copy && git checkout -q -b deploy a7c05516bc31c2c18f89057c02f84bfad83a6b59; fi'" on example.com
当然, deploy:check
报告不容错过: vagrant
用户无法写入deploy:setup
期间创建的目录deploy:setup
因为这两个用户属于不同的组 - root:root
vs vagrant:vagrant
:
$ cap deploy:check [...] The following dependencies failed. Please check them and try again: --> You do not have permissions to write to `/home/vagrant/example'. (example.com) --> You do not have permissions to write to `/home/vagrant/example/releases'. (example.com) --> `/home/vagrant/example/shared' is not writable (example.com)
这背后的原因是什么,以及哪些先决条件尚未满足,因此部署通过了这个问题?
deploy:setup
任务可能不应该使用sudo
来创建app目录,因为这可能导致它由root
拥有。
您可以在deploy.rb
文件deploy.rb
其关闭:
set :use_sudo, false
由于Capistrano中没有组设置,我的解决方法是扩展这样的设置,例如:
set :user, 'vagrant'
set :group, 'vagrant'
然后在运行deploy:setup
之后创建一个“修复”所有权的任务:
after "deploy:setup", :setup_ownership
task :setup_ownership do
run "#{sudo} chown -R #{user}:#{group} #{deploy_to} && chmod -R g+s #{deploy_to}"
end
但唯一比解决问题更好的事情就是首先没有它,所以斯图尔特的答案更明智,更优雅。