태그 보관물: repo

Bare git으로 부터 source code 복사하기

Android에 기반한 project를 repo로 mirror로 만들때는 –mirror option을 주어서 bare git을 만든다(지난 posting 참조). 만약 이렇게 만들어진 bare repository로 부터 일반적인 형태의 source repository를 생성하려 한다면 어떻게 해야 할까? 이 posting에서는 git-daemon등을 설치 하지 않고 local에 있는 bare git으로 부터 source 구조를 만들어 내는 방법을 설명한다.

Repo Init

$ repo init help
Usage: repo init -u url [options]

repo init 명령을 수행할 때 -u 뒤에 url을 적어준다. 일반적으로 이 부분에 ‘git://’이나 ‘ssh://’ protocol로 시작하는 주소를 적지만 우리가 하려는 것은 file 복사 이므로 ‘file://’을 적어서 repo init을 수행한다.

$ repo init -u file://PATH_TO_MIRROR -b BRANCH -m MANIFEST_XML

놀랍게도(!) init이 수행되면서 .repo directory가 생성된다.

Fetch Address 수정

.repo/manifests에서 fetch address를 가지고 있는 xml file을 찾아서 접근 address를 file경로로 수정한다.

  <!-- 
  <remote name="REMOTE_NAME" fetch="ssh://SERVER_IP" review="REVIEW_ADDRESS:8080"/> 
  -->
  <remote name="REMOTE_NAME" fetch="file://<path_to_mirror>/" review="REVIEW_ADDRESS:8080"/>

init이 완료 되고 난 후에는 일반적인 것과 같이 repo sync 명령어를 수행하면 된다. file://로 수정한 xml file들을 원래 상태로 되돌리는 건 다들 아실테고 … 😉

Repo mirroring

한국과 미국 처럼 거리상으로 멀리 떨어져 있는 경우, 한쪽에서 source를 sync하기 위해서는 시간이 너무 많이 걸린다. Mirror를 설정하고 주기적으로 source를 sync 해 오도록 하면 시간과 load를 줄일 수 있다. 다음은 Ubuntu 10.04 LTS 기준으로한 repo mirror server 설정방법에 대해 설명한다.

1. Git daemon 설정
: xinetd를 설치하고 git-daemon을 설정한다.

$> sudo apt-get install xinetd
$>sudo vi /etc/xinetd.d/git-daemon

service git
{
        disable = no
        type            = UNLISTED
        port            = 9418
        socket_type     = stream
        wait            = no
        user            = nobody
        server          = /usr/bin/git
        server_args     = daemon --inetd --export-all --base-path=/public/gitmirrors/
        log_on_failure  += USERID
}
$> sudo /etc/init.d/xinetd restart
혹은
$> sudo service xinetd restart

 

2. Mirror repository 만들기
: 외부에서 접근할 공간을 생성하고 mirror를 만든다.

$>sudo mkdir -p /public/gitmirrors/
$>chmod 777 /public/gitmirrors/
$>mkdir /public/gitmirrors/PROJECT_TOP_DIR
$>cd  /public/gitmirrors/PROJECT_TOP_DIR
$>repo init -u ssh://USER_ID@SERVER_ADDRESS_AND_PORT/platform/manifest.git -b <BRANCH_NAME> --mirror
$>repo sync

 

3. Fetching address 변경
: manifest.git을 변경시켜서 새로운 branch로 server에 push 한다.

먼저 manifest.git을 cloning 해오자

$> mkdir ~/temp/manifest
$> cd ~/temp/manifest
$> git clone /public/gitmirrors/PROJECT_TOP_DIR/platform/manifest.git

default.xml의 fetch address를 변경해서 mirror에서 받아오도록 수정한다.

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remote name=REMOTE_NAME fetch="git://MIRROR_SERVER_ADDR/PROJECT_TOP_DIR" review=REVIEW_SITE_ADDR />

...

수정된 default.xml을 새로운 branch에 push 한다.

$>git checkout -b  MIRROR_BRANCH_NAME
$>git add .
$>git commit -m "Updated fetch URL to mirror"
$>git push origin MIRROR_BRANCH_NAME

 

4. Client에서 mirror로 부터 source sync 하기

repo init할때 mirror branch를 명시한다.

$> repo init -u git://MIRROR_SERVER_ADDR/PROJECT_TOP_DIR/platform/manifest.git -b MIRROR_BRANCH_NAME
$> repo sync

 

5. 주기적인 sync를 위한 crontab과 sync script 작성

$> crontab -e
# m h  dom mon dow   command

# 매시 00분 마다 repo sync를 수행
0 * * * * ~/bin/cron_repo_sync.sh

repo sync script
: 호출될 때마다 mirror directory에 있는 내용들을 본국에서 송환해 온다.

#!/bin/bash
# cron repo sync script.
# Syncs all mirrors under the PUBLIC_REPO_DIRS_ROOT. - skywriter

PUBLIC_REPO_DIRS_ROOT="/public/gitmirrors/"
REPO_PATH="/usr/local/bin/repo"

sync_cmd="$REPO_PATH sync -j20"
repodirs=`ls ${PUBLIC_REPO_DIRS_ROOT}`

echo "start syncing"
for repodir in $repodirs
do
  echo "syncing [$repodir] at `date`"
  cd ${PUBLIC_REPO_DIRS_ROOT}$repodir/
  $sync_cmd 2>&1
done
echo "done at `date`"