简体   繁体   English

使用Capistrano进行部署

[英]Deploying with Capistrano

I am using Ruby on Rails 3.0.9 and I trying to setup the Capistrano gem (following the Agile Web Development with Rails book - Fourth Edition). 我正在使用Ruby on Rails 3.0.9,并尝试设置Capistrano gem(遵循带有Rails敏捷Web开发书-第四版)。 I setup git and all related directories\\files on the remote machine (it works) and all "basic" things related to Capistrano. 我在远程计算机上安装了git以及所有相关的目录\\文件(可以正常工作)以及与Capistrano相关的所有“基本”内容。 Now if I run from my local machine the following commands those work as expected: 现在,如果我从本地计算机运行以下命令,这些命令将按预期工作:

cap deploy:setup
# ...

cap deploy:check
# ...
# You appear to have all necessary dependencies installed

At this time on the server machine in my project directory I have the following directories (created by Capistrano): 此时,在我的项目目录中的服务器计算机上,我具有以下目录(由Capistrano创建):

<my_project_dir>/releases
<my_project_dir>/shared

Nothing more . 没什么了

What I should do now? 我现在该怎么办? For example, have I to upload all my application file from my local machine to the remote machine? 例如,是否将所有应用程序文件从本地计算机上载到远程计算机?

PS: I also setup my Apache2 server to point to the <my_project_dir>/current/public directory but Capistrano didn't create that folder. PS:我还将我的Apache2服务器设置为指向<my_project_dir>/current/public目录,但Capistrano并未创建该文件夹。


UPDATE for @Alex @Alex的 更新

If I run the cap deploy command I get the following: 如果运行cap deploy命令,则会得到以下信息:

  * executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote root@<SERVER_IP_ADDRESS>:/git/<my_project_name>.com.git master"
    command finished in 3086ms
  * executing "if [ -d /srv/www/<my_project_name>.com/shared/cached-copy ]; then cd /srv/www/<my_project_name>.com/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 36ccf7b6f63041ee8dcdf4ca0a7c0b10dbc8bad1 && git clean -q -d -x -f; else git clone -q root@<SERVER_IP_ADDRESS>:/git/<my_project_name>.com.git /srv/www/<my_project_name>.com/shared/cached-copy && cd /srv/www/<my_project_name>.com/shared/cached-copy && git checkout -q -b deploy 36ccf7b6f63041ee8dcdf4ca0a7c0b10dbc8bad1; fi"
    servers: ["<SERVER_IP_ADDRESS>"]
    [<SERVER_IP_ADDRESS>] executing command
 ** [<SERVER_IP_ADDRESS> :: err] Host key verification failed.
 ** [<SERVER_IP_ADDRESS> :: err] fatal: The remote end hung up unexpectedly
    command finished in 396ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /srv/www/<my_project_name>.com/releases/20110820175634; true"
    servers: ["<SERVER_IP_ADDRESS>"]
    [<SERVER_IP_ADDRESS>] executing command
    command finished in 353ms
failed: "sh -c 'if [ -d /srv/www/<my_project_name>.com/shared/cached-copy ]; then cd /srv/www/<my_project_name>.com/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 36ccf7b6f63041ee8dcdf4ca0a7c0b10dbc8bad1 && git clean -q -d -x -f; else git clone -q root@<SERVER_IP_ADDRESS>:/git/<my_project_name>.com.git /srv/www/<my_project_name>.com/shared/cached-copy && cd /srv/www/<my_project_name>.com/shared/cached-copy && git checkout -q -b deploy 36ccf7b6f63041ee8dcdf4ca0a7c0b10dbc8bad1; fi'" on <SERVER_IP_ADDRESS>

Note : failed: ... on the last line. 注意failed: ...在最后一行。 What is the problem? 问题是什么?

Because your git repo is on the deployment server itself, Capistrano has same difficulties. 因为您的git repo在部署服务器本身上,所以Capistrano也有同样的困难。 Simply set the deploy_via variable to :copy in your deploy.rb to fix: 只需设置deploy_via变量:copy你的deploy.rb来解决:

set deploy_via :copy
 [<SERVER_IP_ADDRESS>] executing command 

** [ :: err] Host key verification failed. ** [:: err]主机密钥验证失败。 ** [ :: err] fatal: The remote end hung up unexpectedly ** [::错误]致命:远端意外挂断

In my case, this was caused by having my git repo set up with an ssh URL. 就我而言,这是由我的git repo设置了ssh URL引起的。

I was able to solve this issue by logging into the host via ssh, then executing 'ssh ', then accepting the host key. 我可以通过ssh登录到主机,然后执行“ ssh”,然后接受主机密钥来解决此问题。

You can do a couple of things: 您可以做几件事:

  • cap deploy:setup This will setup any dirs, symlinks, etc that capistrano needs cap deploy:setup这将设置capistrano需要的所有目录,符号链接等
  • cap deploy:check This will make sure everything is set up for cap cap deploy:check这将确保所有内容都已设置为cap
  • cap deploy:cold This deploys and starts up all the configured daemons (eg mongrel, apache, whatever you're using) cap deploy:cold这将部署并启动所有已配置的守护程序(例如,mongrel,apache,无论您使用什么)

You have to perform cap deploy:cold for the first time and then onwards use cap deploy or cap deploy:migrations to deploy the app. 您必须第一次执行cap deploy:cold ,然后再使用cap deploycap deploy:migrations来部署应用程序。

These commands can either copy the code to the production server from local machine or even from the remote git repository. 这些命令可以将代码从本地计算机甚至从远程git存储库复制到生产服务器。

Look at the configuration options here: http://help.github.com/deploy-with-capistrano/ 在此处查看配置选项: http : //help.github.com/deploy-with-capistrano/

The above commands will also create the symlink <my_project_dir>/current for you 上面的命令还将为您创建符号链接<my_project_dir>/current

The above error indicates that your server is not able to clone the git repository from github. 上面的错误表明您的服务器无法从github克隆git存储库。 Generate a SSK key pair in the server machine using app user and upload the public key to the github deploy keys.. 使用应用程序用户在服务器计算机上生成一个SSK密钥对,并将公共密钥上载到github部署密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM