capistrano v3部署git存储库及其子模块

时间:2013-10-16 12:16:01

标签: capistrano git-submodules

使用capistrano v2子模块可以通过使用选项包含在部署中:

set :git_enable_submodules, 1

在第3版中,这似乎不起作用。这个选项是否仍然受支持,或者是否有新方法可以达到同一目标?

4 个答案:

答案 0 :(得分:2)

事实证明,很难挂钩任何capistrano的git任务(因为它们在设置阶段之前不存在)。此外,git archive不以任何方式提供对子模块的支持,因此必须完全替换该部分。

由于显而易见的原因,复制和粘贴也不是一种选择。

所以我写了这个简单的宝石,可以取代git scm。它使用类似于capistrano 2的方法,通过使用子模块克隆repo。它非常简单,足以实现我们的目标。我怀疑子模块的用法并不多(如果人们试图避免并发症)。

https://github.com/juanibiapina/capistrano-scm-gitsubmodules

让我知道它是否对你有帮助。

更新:

此模块已被capistrano 3.1.0弃用。请改为尝试:https://gist.github.com/stevenscg/8176735

答案 1 :(得分:2)

新的Pull Request“828”正试图再次实施: https://github.com/capistrano/capistrano/pull/828

正如@coffeeaddict所讨论的,这个Commit是你需要在本地部署的代码的一部分,直到它与capistrano本身捆绑在一起。请注意,您需要Capistrano> = 3.1.0才能使用该代码。

还有另一个Gist建议修复上述策略的一些问题。

答案 2 :(得分:2)

在capistrano 3.1.x及更高版本中,您可以实施自己的SCM策略。有一个可用的gem有助于git子模块,请参阅:https://github.com/i-ekho/capistrano-git-submodule-strategy

注意:如果您已尝试使用默认的git策略,则可能会遇到repo文件夹的问题。只需转到服务器上的deploy目录并将其删除,然后再次运行cap deploy进行修复。

答案 3 :(得分:0)

正如您在Capistrano源代码https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/git.rake#L34https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/git.rake#L56中所看到的,它使用git archive将代码签出到发布目录中。

代码转载于此:

desc 'Clone the repo to the cache'
task clone: :'git:wrapper' do
  on roles :all do
    if test " [ -f #{repo_path}/HEAD ] "
      info t(:mirror_exists, at: repo_path)
    else
      within deploy_path do
        with git_environmental_variables do
          execute :git, :clone, '--mirror', repo_url, repo_path
        end
      end
    end
  end
end
desc 'Update the repo mirror to reflect the origin state'
task update: :'git:clone' do
  on roles :all do
    within repo_path do
      execute :git, :remote, :update
    end
  end
end
desc 'Copy repo to releases'
task create_release: :'git:update' do
  on roles :all do
    with git_environmental_variables do
    within repo_path do
      execute :mkdir, '-p', release_path
      execute :git, :archive, fetch(:branch), '| tar -x -C', release_path
    end
  end
 end

由此我们可以确定不支持子模块。由于永远不会发出克隆或初始化子模块的命令,git-archive会忽略它们。

做出决定(来源:Capistrano作者在这里)不要包含“开箱即用”的子模块,因为需要它来构建它,如果你需要它已经存在,并且编写一个附加组件是微不足道的以适合您的方式执行检查/更新子模块所需的任务。 Capistrano v2子模块支持通常会给人们带来意想不到的后果。

考虑到这一点。可能值得挂钩update,在更新完成后初始化和更新子模块,并检查增强git-archive的方法来做你需要的事情。

相关问题