capistrano v3部署git存储库及其子模块 [英] capistrano v3 deploy git repository and its submodules
问题描述
使用capistrano v2子模块可以通过使用以下选项包含在部署中:
With capistrano v2 submodules can be includes in the deploy by using option:
set :git_enable_submodules, 1
在v3中,这似乎不起作用。仍然支持此选项还是有新的方法可以达到相同的目标?
In v3 this does not seem to work. Is this option still supported or is there a new way to reach the same goal?
推荐答案
如Capistrano源码所示代码 https://github.com/capistrano/ capistrano / blob / master / lib / capistrano / tasks / git.rake#L34 和 https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/git.rake#L56 它使用 git archive
将代码检出到发布目录中。
As you can see in the Capistrano source code https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/git.rake#L34 and https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/git.rake#L56 it uses git archive
to check out the code into the release directory.
代码在此处复制:
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会忽略它们。
From that we can ascertain that submodules are not supported. As the commands to clone or initialize submodules are never issued, and git-archive ignores them.
已决定(不包括子模块)(来源:Capistrano作者)开箱即用作为构建它所需要的挂钩,如果您需要的话,编写一个附加任务很简单,该任务以适合您的方式执行检出/更新子模块所需的工作。 Capistrano v2子模块的支持通常会给人们带来意想不到的后果。
The decision was made (source: Capistrano author here) not to include submodules "out of the box" as the hooks needed to build this in, if you need it are already there, and it's trivial to write an add-on task that does what you need to checkout/update submodules in a way that works for you. The Capistrano v2 submodule support often had unexpected consequences for people.
请牢记这一点。可能值得加入 update
,在更新完成后初始化和更新子模块,并研究增强 git-archive的方法
做您需要的事。
With that in mind. It might be worth to hooking into update
, to initialize and update your submodules after the update is finished, and examining ways to augment git-archive
do do what you need.
这篇关于capistrano v3部署git存储库及其子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!