如何处理带有子模块的 Rails 应用程序部署?

发布于 2024-07-24 04:39:58 字数 263 浏览 10 评论 0原文

我最近将几个插件转换为子模块,并意识到当您“git克隆”存储库时,子模块目录将为空。 这对于联合开发人员初始化其子模块和更新是有意义的。

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

有人对如何处理这个问题有建议吗? 它像 capistrano 任务一样简单吗?

我在生产方面有点菜鸟。

谢谢你!

I recently turned a couple of my plugins into submodules and realized that when you "git clone" a repository, the submodule directory will be empty. This makes sense for co-developers to initialize their submodules and update.

However, when I deploy with capistrano the submodule code will obviously not be deployed which causes problems. I could go into the release branch and init and update the module there, but that is obviously not an ideal solution.

Does anyone have suggestions about how to handle this? Is it as simple as a capistrano task?

I am a bit of a noob on the production side of things.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ζ澈沫 2024-07-31 04:39:58

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

set :git_enable_submodules,1

:如果您的 .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

如果您有嵌套子模块< /strong>,您需要:

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

只需在部署配置中要求它:

require 'capistrano/deepmodules'

gem 会自动处理剩下的所有事情。
您可以从配置中删除 :git_enable_submodules,gem 不会注意到它 - 如果您需要它,您已经在说您想要启用子模块。

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

set :deploy_via, :remote_cache

它启用了远程缓存,而且这确实是您想要做的事情 - 如果您没有服务器端缓存,那么部署包含大量子模块和其他内容的大型代码库确实是一种麻烦的体验。

According to this recent thread, capistrano should be able to init and update your submodules:

set :git_enable_submodules,1

in config/deploy.rb should be enough, if your .gitmodules entries are up to date.
You may need to patch Capistrano (lib/capistano/recipes/deploy/scm/git.rb) to make sure your submodules get included though.

    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

If you have nested submodules, you need:

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

Just require it at your deployment config:

require 'capistrano/deepmodules'

The gem will take care of all the rest automatically.
You can delete :git_enable_submodules from your config, the gem pays no attention to it - if you’re requiring it you’re already saying that you want to enable submodules.

And one more detail to pay attention to - at the moment only remote cache strategy is supported by the gem. It means that you MUST add to your config the following line:

set :deploy_via, :remote_cache

It enables the remote cache and it’s really the thing you want to do anyway - deploying large codebases with a lot of submodules and other stuff is really a troublesome experience if you have no server-side cache of it.

冷默言语 2024-07-31 04:39:58

如果没有这个选项,set :git_enable_submodules, 1 本身就不起作用:

set :deploy_via, :remote_cache`

这似乎没有在任何地方记录下来,我花了一段时间才弄清楚。 无论如何,即使没有子模块,拥有该选项通常也很好。

set :git_enable_submodules, 1 on it's own didn't work without this option:

set :deploy_via, :remote_cache`

This didn't appear to be documented anywhere and took me a while to figure out. It's generally good to have that option anyway, even without submodules.

傲性难收 2024-07-31 04:39:58

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

set :git_enable_submodules, true

如果您使用 递归 Git 子模块,也添加以下内容:

set :git_submodules_recursive, true

With this commit, Capistrano has support for both Git submodules and the --recursive option baked in. To enable Git submodules support, add this to your deploy.rb file:

set :git_enable_submodules, true

And if you use recursive Git submodules, add this as well:

set :git_submodules_recursive, true

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文