gpt4 book ai didi

git - 您如何处理使用子模块部署 Rails 应用程序?

转载 作者:IT王子 更新时间:2023-10-29 00:41:26 26 4
gpt4 key购买 nike

我最近将我的几个插件变成了子模块,并意识到当你“git clone”一个仓库时,子模块目录将是空的。这对于合作开发者初始化他们的子模块和更新是有意义的。

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

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

我在生产方面有点菜鸟。

谢谢!

最佳答案

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

set :git_enable_submodules,1

如果您的 .gitmodules 条目是最新的,那么在 config/deploy.rb 中就足够了。
您可能需要 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'

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.

关于git - 您如何处理使用子模块部署 Rails 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/953658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com