2009-06-04 67 views
13

我最近把我的一些插件变成了子模块,并意识到当你“克隆”一个仓库时,子模块目录将是空的。这对于合作开发者初始化其子模块和更新是有意义的。你如何处理部署rails子应用程序的应用程序?

但是,当我部署capistrano时,子模块代码显然不会引起问题。我可以进入发布分支并在那里初始化和更新模块,但这显然不是一个理想的解决方案。

有没有人有关于如何处理这个问题的建议?这与卡皮斯特拉诺的任务一样简单吗?

我是一个在生产方面的小事。

谢谢!

回答

12

this recent thread,Capistrano的应该能够初始化和更新您的子模块:

set :git_enable_submodules,1 

在配置/ deploy.rb应该够了,如果你的.gitmodules条目是最新的。
您可能需要to patch Capistrano (lib/capistano/recipes/deploy/scm/git.rb)以确保您的子模块包含在内。

def checkout(revision, destination) 
     git  = command 

     branch = head 

     fail "No branch specified, use for example 'set :branch, \"origin/master\"' in your deploy.rb" unless branch 

     if depth = configuration[:git_shallow_clone] 
     execute = "#{git} clone --depth #{depth} #{configuration[:repository]} #{destination} && " 
     else 
     execute = "#{git} clone #{configuration[:repository]} #{destination} && " 
     end 

     execute += "cd #{destination} && #{git} checkout -b deploy #{branch}" 

     if submodules = configuration[:git_enable_submodules] 
     execute += " && git-submodule init &&" 
     execute += "git-submodule update" 
     end 

     execute 
    end 

如果你有nested submodules,您需要:

gem sources -a http://gems.github.com 
$ sudo gem install morhekil-capistrano-deepmodules 

只是要求它在您的部署配置:

需要 'Capistrano的/ deepmodules'

宝石会自动处理所有其他的事情。
您可以从您的配置中删除:git_enable_submodules,gem不关注它 - 如果您需要它,您已经说过要启用子模块。

还有一个要注意的细节 - 目前只有gem支持远程缓存策略。这意味着你必须添加到您的config以下行:

set :deploy_via, :remote_cache 

它使远程缓存,它真的是你想反正做的事情 - 有很多子模块和其它的部署大量的代码库如果你没有服务器端缓存,东西真的很麻烦。

5

set :git_enable_submodules, 1它自己没有这个选项不工作:

set :deploy_via, :remote_cache` 

这似乎没有在任何地方记录和我花了一段时间才能找出。无论如何,即使没有子模块,也总是有好的选择。

5

对于this commit,Capistrano支持Git子模块和-recursive选项。要启用Git的子模块的支持,添加到您的deploy.rb文件:

set :git_enable_submodules, true

如果您使用recursive Git submodules,添加此还有:

set :git_submodules_recursive, true