代码之家  ›  专栏  ›  技术社区  ›  Tony

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

  •  13
  • Tony  · 技术社区  · 16 年前

    我最近把几个插件变成了子模块,我意识到当你“git克隆”一个存储库时,子模块目录将是空的。这对于共同开发人员初始化子模块和更新是有意义的。

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

    有人对如何处理这个有什么建议吗?这是一个简单的卡皮斯特拉诺任务吗?

    我在制作方面有点笨手笨脚。

    谢谢您!

    3 回复  |  直到 13 年前
        1
  •  12
  •   Stuart M    13 年前

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

    set :git_enable_submodules,1
    

    在config/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
    

    它启用了远程缓存,而且它确实是您无论如何都想做的事情——如果您没有它的服务器端缓存,部署带有大量子模块和其他东西的大型代码库确实是一种麻烦的体验。

        2
  •  5
  •   Zubin    15 年前

    set :git_enable_submodules, 1 就其本身而言,没有这个选择就不起作用:

    set :deploy_via, :remote_cache`
    

    这似乎没有记录在案,我花了一段时间才弄清楚。不管怎样,即使没有子模块,拥有这个选项通常也很好。

        3
  •  5
  •   Stuart M    13 年前

    this commit ,capistrano同时支持git子模块和--recursive选项。要启用Git子模块支持,请将其添加到 deploy.rb 文件:

    set :git_enable_submodules, true

    如果你使用 recursive Git submodules ,同时添加:

    set :git_submodules_recursive, true