如何使用子模块部署rails应用程序?

Ton*_*ony 13 git deployment plugins capistrano git-submodules

我最近将一些插件转换为子模块,并意识到当你"git clone"一个存储库时,子模块目录将为空.这对于共同开发人员初始化他们的子模块和更新是有意义的.

但是,当我使用capistrano部署时,子模块代码显然不会被部署,从而导致问题.我可以进入发布分支并初始化并更新那里的模块,但这显然不是一个理想的解决方案.

有没有人有关于如何处理这个问题的建议?它是否像capistrano任务一样简单?

在生产方面,我有点像菜鸟.

谢谢!

Von*_*onC 12

根据最近的这个帖子,capistrano应该能够初始化和更新你的子模块:

set :git_enable_submodules,1
Run Code Online (Sandbox Code Playgroud)

如果你的.gitmodules条目是最新的,在config/deploy.rb中应该足够了.
您可能需要修补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
Run Code Online (Sandbox Code Playgroud)

如果您有嵌套的子模块,则需要:

gem sources -a http://gems.github.com
$ sudo gem install morhekil-capistrano-deepmodules
Run Code Online (Sandbox Code Playgroud)

只需在部署配置中使用它:

需要'capistrano/deepmodules'

宝石将自动处理所有其余的事情.
你可以:git_enable_submodules从你的配置中删除,宝石不理会它 - 如果你需要它,你已经说过你想要启用子模块.

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

set :deploy_via, :remote_cache
Run Code Online (Sandbox Code Playgroud)

它支持远程缓存,它实际上是你想要做的事情 - 如果没有服务器端缓存,部署包含大量子模块和其他东西的大型代码库真的是一个麻烦的经历.


Zub*_*bin 5

set :git_enable_submodules, 1 如果没有这个选项,它自己没有用:

set :deploy_via, :remote_cache`
Run Code Online (Sandbox Code Playgroud)

这似乎没有在任何地方记录,并花了我一段时间才弄明白.无论如何,即使没有子模块,通常也可以使用该选项.


Stu*_*t M 5

通过此提交,Capistrano支持Git子模块和烘焙的--recursive选项.要启用Git子模块支持,请将其添加到您的deploy.rb文件中:

set :git_enable_submodules, true

如果你使用递归的Git子模块,也可以添加它:

set :git_submodules_recursive, true