Capistrano deploy fails after I changed the repository URL

17,355

Solution 1

I gotta say I’m not sure, since I haven’t been able to test this but this should work:

cap deploy:cleanup -s keep_releases=0

Since it wipes every release (cache) from the server.

Apparently you will also need to remove shared/cached-copy, because this doesn’t seem to be cleaned by the Capistrano call above according to the comment below.

Solution 2

Capistrano 2.X

Delete and re-clone the repo using the new address:

cd $deploy_to/shared
rm -rf cached-copy
git clone ssh://[email protected]/new/repo.git cached-copy

Modify your config/deploy.rb to use the new repo:

set :repository, "ssh://[email protected]/new/repo.git"
set :scm, :git
set :deploy_via, :remote_cache

Deploy again:

cap deploy

Capistrano 3.X

  1. Remove the $deploy_to/repo directory
  2. Modify your config/deploy.rb (same as 2.X)
  3. cap deploy

Solution 3

Capistrano 2 and below

SSH to your server and update the repo in ./shared/cached-copy/.git/config of the deployment folder, or just remove the ./shared/cached-copy

Capistrano 3 and above

SSH to your server and update the repo in ./repo/config of the deployment folder.

Check Fixing Capistrano 3 deployments after a repository change

Solution 4

I solved this with the following in deploy.rb:

namespace :deploy do
  task :cope_with_git_repo_relocation do
    run "if [ -d #{shared_path}/cached-copy ]; then cd #{shared_path}/cached-copy && git remote set-url origin #{repository}; else true; fi"
  end
end
before "deploy:update_code", "deploy:cope_with_git_repo_relocation"

It makes deploys a little slower, so it's worth removing once you're comfortable that all your deploy targets have caught up.

Solution 5

You need to change git origin in your /shared/cached-copy folder

cd /var/www/your-project/production/shared/cached-copy
git remote remove origin
git remote add origin [email protected]:/origin.git

try cap production deploy

Share:
17,355
Jakub Arnold
Author by

Jakub Arnold

Experienced software engineer with a background in machine learning and computer science and over 7 years of commercial practice of software development, looking to work on production quality software.

Updated on June 06, 2022

Comments

  • Jakub Arnold
    Jakub Arnold almost 2 years

    I have a simple deployment via capistrano from a Git repository. At first I was deploying form GitHub, everything worked just fine. But then I moved my repository to BitBucket and now I'm getting

    fatal: Could not parse object '9cfb...'.
    

    The problem goes away once I change

    set :deploy_via, :remote_cache
    

    to

    set :deploy_via, :copy
    

    but that doesn't fix the problem, it only bypasses it. Is there any way I can tell capistrano to just drop the old cache?

  • Jakub Arnold
    Jakub Arnold over 12 years
    This didn't solve the problem entirely, but once I removed shared/cached-copy, it deploys just fine now.
  • JD.
    JD. over 11 years
    It did not work for me, either, but Jakub's comment here did.
  • nil
    nil over 11 years
    you can just change the url of origin remote to your new repo address in the shared/cached-copy directory.
  • Kenny Lövrin
    Kenny Lövrin almost 11 years
    I'd say this is the better answer. If you delete all releases you are essentially in bad shape if your new deploy fails and you cannot roll back. I also think it is worth noting that cloning the repo manually is only needed to add the host to the known hosts. If it already is added then the deploy will work (so essentially the same thing as when setting up capistrano for the first time, checking out the repo anywhere works just to get it added)
  • Justin Tanner
    Justin Tanner almost 11 years
    @KennyLövrin yes cloning the repo anywhere will get your host into the known hosts, but aif you have :remove_cache set you need something in the cached-copy directory or capistrano won't deploy.
  • eveevans
    eveevans almost 11 years
    the answer only delete all releases on server (including current). The best answer (if you have remote cache active) is that of Jakub Arnold.
  • Fred Oliveira
    Fred Oliveira over 10 years
    Keep in mind that capistrano 3.1 uses shared/repo instead of shared/cached-copy so this answer, while almost correct, should be updated.
  • Roxas Shadow
    Roxas Shadow over 9 years
    In capistrano 3.2.1 I solved removing the $deploy_to/repo folder since I cannot found any repo folder in shared.
  • sixty4bit
    sixty4bit over 9 years
    where are all these directories? I'm having a similar problem in a Rails 3.2 app and have no idea what's going on. I develop on OS X and have no trouble deploying but my coworker, who is using a nitrous.io linux box, is getting errors on deploy that the repo can't be found despite the git remote being set and the master branch being up to date
  • hemc4
    hemc4 over 9 years
    This link Worked, shared/cached-copy and deploy:cleanup doesn't work with capistrano 3
  • Rodrigo Zurek
    Rodrigo Zurek about 9 years
    add jakub comment to the answer, it solves the issue
  • csch
    csch almost 9 years
    Since Capistrano 3 you have to delete /repo instead of shared/cached-copy. Edit: See Justin Tanner's answer
  • Brettski
    Brettski over 8 years
    This is the better answer
  • ppires
    ppires over 8 years
    It's not necessary to delete the entire repo folder, just edit repo/config and change the repo URL to the new one.
  • ObjectNameDisplay
    ObjectNameDisplay over 7 years
    Justin Tanner's answer doesn't require removing old releases and is simpler.
  • gl03
    gl03 about 7 years
    This is quite dangerous if your deploy fails, since no rollback will be possible and you'll be crying at a blank screen where your website was. (empirically tested)
  • a2f0
    a2f0 over 6 years
    I was able to get by without, git clone ssh://[email protected]/new/repo.git cached-copy, working solution, though thanks 👍
  • mmike
    mmike over 6 years
    nice solution. let's say that ./repo/config -> path_to_your_repo/repo/config (it's not clear for beginning)