-
-
Save corny/7459729 to your computer and use it in GitHub Desktop.
# 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 |
put it inside your actual project
/home/username/mywebsite/lib/capistrano/tasks/git.cap
I'm using 3.0.1 and it's working
I tried putting it in git.cap under /home/username/mywebsite/lib/capistrano/tasks/git.cap as you suggested but it was complaining about the release path already existing.
I then moved this code into my deploy.rb adding it as another task and it worked fine after that. Thanks!
Works for me, thanks a lot!
Great job man, it works like a charm here. So bad that capistrano does not have an way to do it on the configuration.
I will look carefully in the next release pull requests and see if I can help with that.
I cannot get this to work on Cap V3.1.0
It's failing when trying to symlink the release:
Tasks: TOP => git:create_release
(See full trace by running task with --trace)
Anyone have this problem?
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
Thank you for posting this.
I am also trying to support submodules in my capistrano 3 deployment. I have placed the script you created above in /capistrano-3.0.0/lib/capistrano/tasks/git.cap but on deploy it does not seem to pull the submodule. Is there anything else I need to setup for this to work? Thanks so much!