Programing

저장소 URL을 변경 한 후 Capistrano 배포가 실패 함

lottogame 2020. 10. 21. 07:39
반응형

저장소 URL을 변경 한 후 Capistrano 배포가 실패 함


Git 저장소에서 capistrano를 통한 간단한 배포가 있습니다. 처음에는 GitHub에서 배포했지만 모든 것이 잘 작동했습니다. 하지만 저장소를 BitBucket으로 옮겼습니다.

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

내가 변하면 문제는 사라진다

set :deploy_via, :remote_cache

...에

set :deploy_via, :copy

그러나 그것은 문제를 해결하지 않고 우회 할뿐입니다. 카피 스트라 노에게 이전 캐시를 삭제하라고 말할 수있는 방법이 있습니까?


나는 이것을 테스트 할 수 없었기 때문에 확실하지 않다고 말해야하지만 이것은 작동해야합니다.

cap deploy:cleanup -s keep_releases=0

서버에서 모든 릴리스 (캐시)를 삭제하기 때문입니다.

shared/cached-copy아래 주석에 따라 위의 Capistrano 호출에 의해 정리되지 않는 것 같기 때문에 분명히 제거해야 합니다.


카피 스트라 노 2.X

새 주소를 사용하여 저장소를 삭제하고 다시 복제하십시오.

cd $deploy_to/shared
rm -rf cached-copy
git clone ssh://git@example.org/new/repo.git cached-copy

config/deploy.rb새 저장소를 사용하도록 수정하십시오 .

set :repository, "ssh://git@example.org/new/repo.git"
set :scm, :git
set :deploy_via, :remote_cache

다시 배포 :

cap deploy

카피 스트라 노 3.X

  1. $deploy_to/repo디렉토리 제거
  2. 수정 config/deploy.rb(2.X와 동일)
  3. cap deploy

Capistrano 2 이하

서버에 SSH ./shared/cached-copy/.git/config하고 배포 폴더 의 저장소를 업데이트 하거나./shared/cached-copy

Capistrano 3 이상

서버에 SSH ./repo/config하고 배포 폴더 의 저장소를 업데이트 합니다.

저장소 변경 후 Capistrano 3 배포 수정 확인


나는 다음과 같이 이것을 해결했다 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"

배포 속도가 약간 느리기 때문에 모든 배포 대상이 따라 잡았다 고 생각되면 제거하는 것이 좋습니다.


/ shared / cached-copy 폴더 에서 git 출처 를 변경해야 합니다.

cd /var/www/your-project/production/shared/cached-copy
git remote remove origin
git remote add origin git@bitbucket.org:/origin.git

캡 프로덕션 배포 시도


가장 간단한 방법은 웹 서버의 shared / cached-copy 디렉토리에있는 .git / config에서 repo url을 새 URL로 변경하는 것입니다. 그런 다음 평소와 같이 일반 배포를 수행 할 수 있습니다.


버전에 따라 Capistrano 3은 이전 조상과 다릅니다.

여기에서 내 원래 답변을 읽고 git을 사용하여 저장소를 변경할 때 Capistrano 오류 와 유사한 문제를 해결하는 방법


리포지토리를 많이해야하는 경우 작업을 추가 할 수 있습니다.

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

이 답변이 말하는 내용 의 Capistrano 3 버전은 다음과 같습니다 . 대답이 각 서버에서 제안하는 것을 수행하는 것은 지루할 수 있습니다.

그러니 이것을 deploy.rb넣고 실행하십시오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

Capistrano 3.0 이상

  1. config / deploy.rb에서 저장소 URL을 변경하십시오.

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

참고URL : https://stackoverflow.com/questions/8358238/capistrano-deploy-fails-after-i-changed-the-repository-url

반응형