views:

370

answers:

1

I recently turned a couple of my plugins into submodules and realized that when you "git clone" a repository, the submodule directory will be empty. This makes sense for co-developers to initialize their submodules and update.

However, when I deploy with capistrano the submodule code will obviously not be deployed which causes problems. I could go into the release branch and init and update the module there, but that is obviously not an ideal solution.

Does anyone have suggestions about how to handle this? Is it as simple as a capistrano task?

I am a bit of a noob on the production side of things.

Thank you!

+3  A: 

According to this recent thread, capistrano should be able to init and update your submodules:

set :git_enable_submodules,1

in config/deploy.rb should be enough, if your .gisubmodule entries are up to date.
You may need to patch Capistrano (lib/capistano/recipes/deploy/scm/git.rb) to make sure your submodules get included though.

    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


If you have nested submodules, you need:

gem sources -a http://gems.github.com
$ sudo gem install morhekil-capistrano-deepmodules

Just require it at your deployment config:

require '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.

VonC