無知

갈 길이 먼 공부 일기

기술 공부/일반 트렌드

DevOps (3) | GitHub Repo Migration

moozii 2022. 4. 4. 21:30

 

배경

프로젝트의 상표권 문제 등으로 기존 운영 Organization을 새로운 이름의 Organization으로 마이그레이션을 해야 하는 상황을 맞이해, 기존에 운영하던 100개 이상의 레포지토리들을 새로운 곳으로 옮겨줘야 하는 문제가 발생했다. 이를 해결하기 위해 깃헙 레포지토리들을 옮기는 방법들에 대해 공부할 겸 포스트를 정리했다. 

 

 

 

 

해결책에 대한 가설

 

Mirroring a Repository @GitHub Docs ​

 

https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository

 

Duplicating a repository - GitHub Docs

Note: If you have a project hosted on another version control system, you can automatically import your project to GitHub using the GitHub Importer tool. For more information, see "About GitHub Importer." Before you can push the original repository to your

docs.github.com

 

다음 문서의 가이드에 따라 git push --mirror 옵션을 활용해볼 예정이다. 

 

 

 

 

가설 검증

우선 전체 Organization에 직접 적용하기 이전에 개인 레포로 복제해보는 검증 작업을 진행해보았다. 

 

git clone --bare https://github.com/spaceone-dev/integration-test.git
간략한 저장소로('integration-test.git') 복제합니다...
remote: Enumerating objects: 179, done.
remote: Counting objects: 100% (179/179), done.
remote: Compressing objects: 100% (91/91), done.
remote: Total 179 (delta 50), reused 144 (delta 39), pack-reused 0
오브젝트를 받는 중: 100% (179/179), 21.72 KiB | 4.34 MiB/s, 완료.
델타를 알아내는 중: 100% (50/50), 완료.

cd integration-test.git
git push --mirror https://github.com/joon0615/migration_validation_integration-test.git
오브젝트 나열하는 중: 179, 완료.
오브젝트 개수 세는 중: 100% (179/179), 완료.
Delta compression using up to 8 threads
오브젝트 압축하는 중: 100% (80/80), 완료.
오브젝트 쓰는 중: 100% (179/179), 21.72 KiB | 21.72 MiB/s, 완료.
Total 179 (delta 50), reused 179 (delta 50), pack-reused 0
remote: Resolving deltas: 100% (50/50), done.
To https://github.com/joon0615/migration_validation_integration-test.git
 * [new branch]      master -> master
 * [new tag]         v1.0.2 -> v1.0.2
 * [new tag]         v1.0.3 -> v1.0.3
 * [new tag]         v1.0.3-dev4 -> v1.0.3-dev4

 

검증 작업 결과 소스코드와 커밋 기록은 성공적으로 복제되었다.

 

그러나, 크게 2가지 문제가 발생했다. 

 

1. 레포지토리 별 About 항목, Description과 Topic이 옮겨지지 않는다. 

2. 레포지토리 별 Issue, PR 등이 옮겨지지 않는다. 

 

 

 

 

대안 탐색

https://docs.github.com/en/get-started/importing-your-projects-to-github/importing-source-code-to-github/importing-a-repository-with-github-importer

 

Importing a repository with GitHub Importer - GitHub Docs

Tip: GitHub Importer is not suitable for all imports. For example, if your existing code is hosted on a private network, our tool won't be able to access it. In these cases, we recommend importing using the command line for Git repositories or an external

docs.github.com

git push --mirror 옵션의 한계를 극복할 다른 레포 복제 수단으로 GitHub Importer를 활용하여 검증을 재차 수행했으나, 위의 문제들은 동일하게 반복되었다. 

 

 

 

 

문제의 우회적 해결

 

About 항목 (Description, Topic) 복제

git push --mirror 옵션 사용 전, 옮길 위치에 신규 레포지토리를 생성해야 하므로, 그 생성 과정에서 기존 레포지토리의 description과 topic 데이터를 api로 가져와 추가하는 방식을 통해 우회적으로 해결 가능하다. 검증 작업을 걸쳐 실현 가능성을 검토해보니 성공적이었으므로, 마이그레이션 작업 시 관련 스크립트를 작성해 자동화하면 될 것으로 예상한다. 

 

우선 description 관련 검증 작업을 진행했다. 

DESCRIPTION=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/spaceone-dev/migration-test-0404 | grep description)
echo $DESCRIPTION
>>> "description": "test repo for migration",

curl -X POST -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/orgs/spaceone-dev/repos \
  -d '{"name":"migration-test-0404", "description":"test repo for migration"}' \
  -u "joon0615:*********************"
{
  "id": 477564217,
  "node_id": "R_kgDOHHcNOQ",
  "name": "migration-test-0404",
  "full_name": "spaceone-dev/migration-test-0404",
  "private": false,
  ...
}

 

참고한 자료는 다음과 같다. 

 

 

다음으로 topic 관련 검증 작업을 진행했다. 

curl -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/spaceone-dev/console/topics
{
  "names": [
    "core",
    "console",
    "spaceone",
    "vue",
    "composition-api",
    "vuejs",
    "dashboard"
  ]

curl -X PUT -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/spaceone-dev/migration-test-0404/topics \
  -d '{"names":["test", "console"]}' \ 
  -u "joon0615:********************"

{
  "names": [
    "test",
    "console"
  ]
}

 

참고한 자료는 다음과 같다. 

 

 

 

Issue, PR 복제

이슈를 옮기는 작업은 크게 2가지 방법이 있을 수 있다. 

 

1. 이슈를 Transfer하는 것이다.

복제가 아닌 바로 옮기는 방식이기 때문에 작업 실패 시 복원 작업의 어려움이 예상된다. 

 

https://docs.github.com/en/issues/tracking-your-work-with-issues/transferring-an-issue-to-another-repository

 

Transferring an issue to another repository - GitHub Docs

To transfer an open issue to another repository, you must have write access to the repository the issue is in and the repository you're transferring the issue to. For more information, see "Repository roles for an organization." Note: You can only transfer

docs.github.com

 

 

2. 기존 레포지토리 이슈를 읽어와 새로운 레포지토리에 새롭게 생성해주는 것이다. [채택]

보다 안전한 방법이지만, 기존 내용의 타임스탬프 등이 어그러질 확률이 있다. 안정성을 중시하기 때문에 2안으로 진행 예정이다. 

 

참고할 자료는 다음과 같다.

 

이슈 및 풀리퀘스트와 관련해서는 한가지 더 고려할 바가 있다. 현재 운영 중인 레포들은 깃헙 프로젝트(베타) 기능으로 보드를 운영 중인데, 이것이 이슈로 연동되어 있다는 특징이 있다. 더군다나 베타 기능이라 API 호출도 안되는 것으로 확인된다. 이는 별도 해결안이 보이지 않아 아마 수동 작업으로 복원하지 않을까 싶다. 

https://docs.github.com/en/rest/reference/projects

 

Projects - GitHub Docs

Projects The Projects API lets you create, list, update, delete and customize projects in a repository. List organization projects Lists the projects in an organization. Returns a 404 Not Found status if projects are disabled in the organization. If you do

docs.github.com