Search code examples
gitdeploymentcapistranogit-submodulescapistrano3

Deploying a git submodule with Capistrano 3


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?


Solution

  • 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