Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is capistrano using git clone always

I have some basic issues with capistrano deployment. First of all, I need to know whether capistrano is using git clone even for the second or third when the git repo is already existing. Is there any issue if it uses git pull? I have added set :deploy_via, :remote_cache in my capfile. I am asking this because I tried adding a new file in the path in the server, and not in the git repo as it was a server specific file. The next time I deployed using capistrano, the file disappeared. It seems like capistrano is using git clone even when a git repo is already created. Why cant capistrano use git pull to update the code?

like image 604
rubyprince Avatar asked Apr 07 '26 16:04

rubyprince


1 Answers

Capistrano creates a new subdirectory in realeases for each release like this

horse:releases xxx$ ls -lart
total 0
drwxrwxr-x  22 xxx  staff  748 Jun 26 20:08 20120626180809
drwxrwxr-x  22 xxx  staff  748 Jun 26 20:11 20120626181103
drwxrwxr-x  22 xxx  staff  748 Jun 26 20:29 20120626182908
drwxrwxr-x  22 xxx  staff  748 Jun 26 20:34 20120626183442
drwxrwxr-x  22 xxx  staff  748 Jun 26 20:35 20120626183525
drwxrwxr-x   8 xxx  staff  272 Jun 27 13:11 .
drwxrwxr-x  22 xxx  staff  748 Jun 27 13:11 20120627111102
drwxrwxr-x   5 xxx  staff  170 Jun 27 13:11 ..

and then simply sets a symlink to the current release like this

horse:deployed xxx$ ls -lart
total 8
drwxrwxr-x  4 xxx  staff  136 Jun 26 19:51 ..
drwxrwxr-x  7 xxx  staff  238 Jun 26 20:22 shared
drwxrwxr-x  8 xxx  staff  272 Jun 27 13:11 releases
lrwxrwxr-x  1 xxx  staff   70 Jun 27 13:11 current -> /Users/xxx/RailsDeployment/server/deployed/releases/20120627111102

This way, rollback of the deployment on the server is really easy as you just have to change the symlink back to the last (working) deployment, but as a new complete subdir is created each time it makes sense using git clone instead of git pull.

If you want to have server-specific files, you have to add a capistrano deploy task to your config/deploy.rb file to copy it from somewhere else outside the app directory (typically the shared subfolder). The reason for this is that the deployment should be fully automatic and document all necessary steps in an automated procedure, and not depend on files on the server that were put there manually as this is the first step to a snowflake server. So, if you need a file that is not part of your git repository, as typically something containing production passwords, you need to change config/deploy.rb to copy this file to where you need it. To see how to do this look at the copy_db_credentials tasks in my deploy.rb:

namespace :deploy do
  desc "cause Passenger to initiate a restart"
  task :restart do
    run "touch #{current_path}/tmp/restart.txt" 
  end
  desc "Copies database credentials"
  task :copy_db_credentials do
    run "cp #{shared_path}/credentials/database.yml #{current_path}/config/database.yml"
  end

  desc "reload the database with seed data"
  task :seed do
    run "cd #{current_path}; rake db:seed RAILS_ENV=#{rails_env}"
  end
end
after :deploy, "deploy:copy_db_credentials"
after "deploy:update_code", :bundle_install
desc "install the necessary prerequisites"
task :bundle_install, :roles => :app do
  run "cd #{release_path} && bundle install"
end
like image 104
bento Avatar answered Apr 09 '26 12:04

bento



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!