Created
November 14, 2013 01:31
-
-
Save corny/7459729 to your computer and use it in GitHub Desktop.
Capistrano 3 with Git Submodules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
I get this to work on Cap v3.2
The config worked for me on Capistrano v.3.2.1 after a few tweaks:
# Overwrite the 'deploy:updating' task.
Rake::Task["deploy:updating"].clear_actions
namespace :deploy do
desc 'Copy repo to releases, along with submodules'
task updating: :'git:update' do
on roles(:all) do
with fetch(:git_environmental_variables) do
within repo_path do
# We'll be using 'git clone' instead of 'git archive' (what Capistrano uses), since the latter doesn't fetch submodules.
# Use --recursive to fetch submodules as well.
execute :git, :clone, '-b', fetch(:branch), '--recursive', '.', release_path
# Delete .git* files. We don't need them, and they can be a security threat.
execute "find #{release_path} \\( -name '.git' -o -name '.gitignore' -o -name '.gitmodules' \\) -exec rm -rf {} \\; > /dev/null 2>&1", raise_on_non_zero_exit: false
end
end
end
end
end
I added this git.cap and it worked like a charm, however I then had to add
after "deploy", "deploy:restart"
As deploy:restart stopped being invoked by default after git.cap was introduced
Did I miss something?
@liviucmg thanks i added your script directly in my deploy.rb and it works perfectly !
check out this gem: https://github.com/ekho/capistrano-git-submodule-strategy
Thank you. After deployed I found I 'cd' to the directory of submodule and found that 'git branch' point to no branch. So I have to add another task to force it checkout to master branch. Any ideas?
desc 'Checkout master'
task :checkout_master do
on roles(:app) do |host|
within current_path do
execute "cd #{app_path}/current/public/pages && git checkout master && cd ../../"
end
end
end
I got NameError: uninitialized constant Capistrano::Git
in Capistrano 3.6.0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I cannot get this to work on Cap V3.1.0
It's failing when trying to symlink the release:
Anyone have this problem?