deploy:setup
使用 Capistrano 进行冷部署的正确方法是什么?
使用
- 这个
deploy.rb
- Capistrano v2.14.2
- Vagrant 虚拟化我的服务器,
这是我的场景:
运行时
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 git@github.com: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 git@github.com: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 git@github.com: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
root:root
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)
这背后的原因是什么,什么先决条件尚未满足,所以部署通过了这个问题?