Reputation: 4907
I am deploying a web app with the following specific task under lib/capistrano/setup.rake file:
69 desc "Publish git commit log to changelog.txt"
70 task :publish_changelog do
71 on roles(:web) do
72 log = "#{deploy_to}/current/public/changelog.txt"
73 execute "echo '============ Last deployed on' `date` ============\n > #{log}"
74 execute "echo >> #{log}"
75 execute "cd #{deploy_to}/current && git log --since=\"10 days ago\" >> #{log}"
76 end
77 end
I understand that this is a specific task only to my app, but the problem that I am having is that when I try to run this command, it breaks because after I deploy my application, Capistrano removes the .git directory on my application located on the server role(:web).
The command above works only if the application under role (:web) is a git repository. Essentially, what this means is that I have to ssh into the web server, remove the application "current" that previously was a git repository and then proceed to clone it again. Once that is done, running the above Capistrano task works. Why is that so? I must be missing something.
Here is what I have deduced. When I deploy a Capistrano app, Capistrano must be replacing my "current" with the git directory and pasting over a new one effectively removing the .git direcoty. Although Capistrano creates a shared and releases directory, it has to be pasting over my current one. Is this what Capistrano does? A lead to go on would be appreciated. I'm trying to decide if the command needs to be rewritten or if I need to somehow configure Capistrano. Thanks.
Upvotes: 1
Views: 881
Reputation:
Capistrano keeps the cloned repository in #{deploy_to}/repo
. There's a nice path variable for that: repo_path
.
Notice a git repository at that path is actually a "bare repo".
Having it this way makes sense performance-wise because repo is cloned to this path only once. After that, the repo is only updated which is faster, especially for large repos. Cloning a git repository to current_path
on each deploy would take longer.
That said, here's the stripped down version of your task that should work:
desc "Publish git commit log to changelog.txt"
task :publish_changelog do
on roles(:web) do
within repo_path do
execute :git, :log, "--since='1100 days ago'"
end
end
end
Upvotes: 3