更改存储库 URL 后 Capistrano 部署失败

发布于 2024-12-19 03:33:08 字数 351 浏览 4 评论 0原文

我通过 Git 存储库中的 capistrano 进行了简单的部署。起初,我从 GitHub 进行部署,一切正常。但后来我将存储库移至 BitBucket,现在我发现

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

,问题就会消失

set :deploy_via, :remote_cache

一旦我更改为

set :deploy_via, :copy

,但这并不能解决问题,它只是绕过了它。有什么方法可以告诉 capistrano 删除旧的缓存吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

朮生 2024-12-26 03:33:08

Capistrano 2.X

使用新地址删除并重新克隆存储库:

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

修改 config/deploy.rb 以使用新存储库:

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

再次部署:

cap deploy

Capistrano 3.X

  1. 删除$deploy_to/repo目录
  2. 修改您的config/deploy.rb(与2.X相同)
  3. cap部署

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
卖梦商人 2024-12-26 03:33:08

我得说我不确定,因为我无法测试这一点,但这应该可行:

cap deploy:cleanup -s keep_releases=0

因为它会擦除服务器上的每个版本(缓存)。

显然,您还需要删除 shared/cached-copy,因为根据下面的评论,上面的 Capistrano 调用似乎没有清除它。

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.

陌上青苔 2024-12-26 03:33:08

Capistrano 2 及更低版本 通过

SSH 连接到您的服务器并更新部署文件夹的 ./shared/cached-copy/.git/config 中的存储库,或者仅删除 ./shared/cached-copy

Capistrano 3 及更高版本

通过 SSH 连接到您的服务器并更新部署文件夹的 ./repo/config 中的存储库。

检查在存储库更改后修复 Capistrano 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

淡写薰衣草的香 2024-12-26 03:33:08

我通过 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"

它使部署速度变慢了一些,因此一旦您确信所有部署目标都已赶上,就值得将其删除。

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.

三生池水覆流年 2024-12-26 03:33:08

您需要更改 /shared/cached-copy 文件夹中的 git origin

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

尝试cap production deploy

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

七月上 2024-12-26 03:33:08

最简单的方法是将存储库 URL 更改为网络服务器上的共享/缓存复制目录中的 .git/config 中的新 URL。然后就可以像往常一样进行正常部署了。

The most simple way is just changing the repo url to the new one in .git/config in the shared/cached-copy directory on the webserver. Then you can do a normal deploy as usual.

九局 2024-12-26 03:33:08

取决于您的版本 Capistrano 3 与它的老祖先不同:

在此处阅读我的原始答案以及如何解决类似问题 使用 git 更改存储库时出现 Capistrano 错误

Depends on your version Capistrano 3 is different from it's older ancestors:

Read my original answer here and how to fix similar issues Capistrano error when change repository using git

浪漫人生路 2024-12-26 03:33:08

如果您需要执行大量存储库,您可能需要为其添加一个任务。

对于 capistrano 3,您可以在deploy.rb 中添加此任务

desc "remove remote git cache repository"
  task :remove_git_cache_repo do
      on roles(:all) do
    execute "cd #{fetch(:deploy_to)} && rm -Rf repo"
  end
end

,然后为每个阶段运行一次:

cap testing remove_git_cache_repo

If you need to do a lot of repo's you might want to add a task for it.

For capistrano 3 you add this task in your deploy.rb

desc "remove remote git cache repository"
  task :remove_git_cache_repo do
      on roles(:all) do
    execute "cd #{fetch(:deploy_to)} && rm -Rf repo"
  end
end

And then run it once for every stage:

cap testing remove_git_cache_repo
以歌曲疗慰 2024-12-26 03:33:08

这是这个答案所讨论的 Capistrano 3 版本。在每台服务器上执行答案建议的操作可能会很乏味。

因此,将其放入 deploy.rb 中,然后运行 ​​cap;部署:fix_repo_origin

namespace :deploy do
  desc 'Fix repo origin, for use when changing git repo URLs'
  task :fix_repo_origin do
    on roles(:web) do
      within repo_path do
        execute(:git, "remote set-url origin #{repo_url}")
      end
    end
  end
end

Here's the Capistrano 3 version of what this answer talks about. It might be tedious to do what the answer suggests on each server.

So drop this in deploy.rb and then run cap <environment> deploy:fix_repo_origin

namespace :deploy do
  desc 'Fix repo origin, for use when changing git repo URLs'
  task :fix_repo_origin do
    on roles(:web) do
      within repo_path do
        execute(:git, "remote set-url origin #{repo_url}")
      end
    end
  end
end
请远离我 2024-12-26 03:33:08

对于 Capistrano 3.0+

  1. 更改 config/deploy.rb 中的存储库 URL

  2. 更改上的 your_project/repo/config 文件中的存储库 URL服务器。

For Capistrano 3.0+

  1. Change the repository URL in your config/deploy.rb

  2. Change the repository URL in the your_project/repo/config file on the server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文