Deploying a git submodule with Capistrano 3

2019-05-26 19:08发布

问题:

My project repo includes Wordpress as a git submodule. When deploying via Capistrano 3, the submodule directory is barren.

project
--wordpress
--images

I am using git and :deploy_via, :remote_cache

How can I tell Capistrano to also deploy the submodule?

回答1:

I found a great script from corny that overrides the git task in Capistrano.

Place this script in lib/capistrano/tasks/git.cap and use cap stage deploy as normal.

https://gist.github.com/corny/7459729

# Save this file as lib/capistrano/tasks/git.cap

namespace :git do
  desc 'Copy repo to releases'
  task create_release: :'git:update' do
    on roles(:all) do
      with fetch(:git_environmental_variables) do
        within repo_path do
          execute :git, :clone, '-b', fetch(:branch), '--recursive', '.', release_path
        end
      end
    end
  end
end


回答2:

Probably duplicated with capistrano v3 deploy git repository and its submodules.

In capistrano 3.1.x and later you can implement your own SCM strategy. There is an available gem that helps with git submodule, please see: https://github.com/i-ekho/capistrano-git-submodule-strategy.

NOTE: you may have problem with the repo folder if you already tried with the default git strategy. Simply go to the deploy directory and remove it and then run cap deploy again to fix it.