如何设置服务器以进行部署并使用Capistrano进行冷部署?

问题描述 投票:3回答:2

deploy:setup的正确方法是什么deploy:setup和使用Capistrano进行冷部署?

运用

这是我的情景:

  1. 运行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 
  2. 尚未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 
  3. 当然, 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) 

这背后的原因是什么,以及哪些先决条件尚未满足,因此部署通过了这个问题?

ruby-on-rails ruby deployment capistrano
2个回答
1
投票

deploy:setup任务可能不应该使用sudo来创建app目录,因为这可能导致它由root拥有。

您可以在deploy.rb文件deploy.rb其关闭:

set :use_sudo, false

0
投票

由于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

但唯一比解决问题更好的事情就是首先没有它,所以斯图尔特的答案更明智,更优雅。

© www.soinside.com 2019 - 2024. All rights reserved.