Git,Bluehost以及Capistrano

February 18, 2009

昨天配置好了用GIT以及Capistrano在Bluehost上发布Rails应用的自动发布,感觉还不错,一点点记录如下:

1. Bluehost上的Rails是用的fcgi,不是Mongrel。所以要在.htaccess里面加上fcgi的handler:

AddHandler fcgid-script .fcgi

以及

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

2. 正如这篇文章里所说,如果在Windows下开发,别忘了改首行:

dispatch.fcgi和dispatch.rb(在publice目录下)的首行。

因为BlueHost下是虚拟的unix系统,所以要改成#!/usr/bin/ruby

(如果在windows下开发的程序,用户常会忘了把首行改成unix下ruby的路径)

3. 如何在Bluehost上安装GIT?答案在这里

    注意的是因为Bluehost的防火墙的原因,GitHub的URL无法访问,比如

git://github.com/bsag/tracks.git

    就是无法访问的,不过可以把git改成http就ok了。

http://github.com/bsag/tracks.git

4. Capistrano基本上按照官网的文档一步一步走就OK了。要注意的是:

    如果你在windows下开发而git又没有放到path里面的话,走到 cap deploy:update 这一部可能出现错误。在GIT Bash里面进行就不会出错了。另外,在deploy.rb里面要多写如下一些:

set :branch, "master"  #因为GITHub的原因

namespace :deploy do
  desc "This is here to overide the original :restart"
  task :restart, :roles => :app do
    # do nothing but overide the default
    # Bluehost的fcgi模式不需要重启Mongrel
  end

  # 不想把database.yml放到scm中去
  # 从Advanced Rails Recipes里面找到的。
  task :copy_database_configuration do
    production_db_config = "~/rails/production.database.yml"
    run "cp #{production_db_config} #{release_path}/config/database.yml"
  end
  after "deploy:update_code" , "deploy:copy_database_configuration"

  # 修改public和tmp两个目录的权限
  #(好像Capistrano把log目录做了符号链接,所以没加log)
  task :change_dir_permissions do
    run "chmod -R 755 #{release_path}/public"
    run "chmod -R 755 #{release_path}/tmp"
  end
  after "deploy:symlink", "deploy:change_dir_permissions"
end

posted in Notes by cowoo

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org