如何设置服务器进行部署并使用Capistrano进行冷部署? [英] How to setup a server for deployment and to do a cold deploy with Capistrano?

查看:171
本文介绍了如何设置服务器进行部署并使用Capistrano进行冷部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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





这是我的场景:


  1. 当运行 deploy:setup 时,Capistrano利用root权限来准备部署的目录结构:



    <$执行deploy:setup
    *执行sudo -psudo password:p $ p> $ cap deploy:setup
    * 2013-02-28 14:50:21 '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]执行命令
    命令在29m处完成s
    *执行sudo -psudo 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]执行命令
    命令完成在11ms


  2. 但在部署: code> Capistrano尝试检出(在本例中为git),并写入 vagrant 用户 - 在 deploy.rb中指定的用户

      $ cap deploy:cold 
    * 2013-02-28 14:50:执行`deploy:cold'
    * 2013-02-28 14:50:47执行`deploy:update'
    ** transaction:start
    * 2013-02-28 14:50 :47执行`deploy:update_code'
    更新所有服务器上的缓存结帐
    在本地执行:git ls-remote git@github.com:mariusbutuc / realtime-faye.git master
    命令完成了我n 2360ms
    *执行if [-d / home / vagrant / example / shared / cached-copy];然后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& amp;& git checkout -q -b deploy a7c05516bc31c2c18f89057c02f84bfad83a6b59; fi
    servers:[example.com]
    [example.com]执行命令
    ** [example.com :: out]致命:无法创建工作树目录' home / vagrant / example / shared / cached-copy':权限被拒绝
    命令在26ms内完成
    *** [部署:update_code]回滚
    *执行rm -rf / home /流浪/示例/释放/ 20130228195049;
    服务器:[example.com]
    [example.com]执行命令
    命令在7ms内完成
    失败:sh -c'if [-d / home / vagrant / example / shared / cached-copy];然后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& amp;& git checkout -q -b deploy a7c05516bc31c2c18f89057c02f84bfad83a6b59; fi'在example.com


  3. 当然,部署:检查报告bares没有惊喜: vagrant 用户无法写入 deploy中创建的目录:setup 因为两个用户属于不同的组 - root:root vagrant:vagrant

      $ cap deploy:check 
    [...]
    以下依赖关系失败,请检查并重试:
    - >您没有写入`/ home / vagrant / example'的权限(example.com)
    - >您没有写入`/ home / (example.com)
    - >`/ home / vagrant / example / shared'不可写(example.com)


这是什么原因,什么先决条件还不满足,所以部署会传递这个问题?

解决方案

deploy:setup task proba bly不应该使用 sudo 创建应用程序目录,因为这可能导致它由 root 所有。



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

  set:use_sudo,false 


What is the proper way to deploy:setup and to do a cold deploy with Capistrano?

Using

this is my scenario:

  1. when running deploy:setup, Capistrano makes use of root privileges to prepare the directory structure for deployment:

    $ 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. yet upon deploy:cold Capistrano attempts to checkout (from git in this case) and write as the vagrant user – the user specified in 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
    

  3. Of course, the deploy:check report bares no surprises: the vagrant user cannot write in the directories created during deploy:setup since the two users belong to different groups – root:root versus 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)
    

What is the reasoning behind this, and what prerequisite is not satisfied yet so the deployment passes this issue?

解决方案

The deploy:setup task probably should not be using sudo to create the app directory, since that is likely causing it to be owned by root.

You can turn that off in your deploy.rb file with:

set :use_sudo, false

这篇关于如何设置服务器进行部署并使用Capistrano进行冷部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆