최근 회사에서 Credential 내역이 노출되어 보안 위협이 된 사례가 발생을 하였다.


즉, 아이디/패스워드, AWS 토큰 값들을 소스파일 안에 적어놓고

그것을 그대로 commit 하여 push 까지 해버린 것이다.



그래서, 소스코드에 이러한 Credential 정보가 들어있는지 점검하는 것을 강화하였다.

자동으로 분석하도록 한 것이다.



문제는 이러한 Credential 정보가 들어있는 파일을 발견했을 때

개발자들이 어떻게 조치를 취해야하는지에 대한 가이드가 부재하고 있다는...





1. 기본 배경


    - 개발자들이 특정 API 사용을 위한 인증 정보를 파일에 적어놓고 무심코 commit을 했을 경우를 전제 해보자

    - 즉, 아래 그림과 같이 "commit D"에 token 값이 있다는 것을 발견한 것이다!!!



2. 최악의 해결 방법


    - Credential 정보가 발견되었다는 경고를 받은 개발자는 당황한 나머지 아래와 같이 작업을 할 수 있다.


    - 설마! 라고 하지만 정말로 저렇게 할 수 있다 !!!

    - 위와 같이 하면 "commit E"에서는 Credential 정보가 안보이지만, "commit D"로 checkout을 하면 볼 수 있게 되기에 해결책이 아니다 !!!!!




3. 기본적인 해결 방법


    - 실습을 위해 아래와 같이 실제 commit들을 만들어보았다.



    - 마지막 commit인 "2651682"에서 Credential 정보가 발견되었을 경우에 대한 대처법을 알아보자.


$ git clone git@github.com:whatwant/whatwant.git

Cloning into 'whatwant'...

remote: Enumerating objects: 8, done.

remote: Counting objects: 100% (8/8), done.

remote: Compressing objects: 100% (4/4), done.

Receiving objects: 100% (11/11), done.

Resolving deltas: 100% (2/2), done.

remote: Total 11 (delta 2), reused 8 (delta 2), pack-reused 3



$ cd whatwant/



$ git log --oneline

2651682 (HEAD -> master, origin/master, origin/HEAD) write token in no002.txt

a2004f0 add no002.txt

93afc28 add no001.txt

2b73c6e Initial commit



$ git reset --hard HEAD^

HEAD is now at a2004f0 add no002.txt



$ git log --oneline

a2004f0 (HEAD -> master) add no002.txt

93afc28 add no001.txt

2b73c6e Initial commit



$ git push origin master

To github.com:whatwant/whatwant.git

 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'git@github.com:whatwant/whatwant.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.



$ git push -f origin master

Total 0 (delta 0), reused 0 (delta 0)

To github.com:whatwant/whatwant.git

 + 2651682...a2004f0 master -> master (forced update)


    - 위와 같이 진행하고 commit 현황을 보면 "2651682" commit이 사라진 것을 볼 수 있다.



    - 아래 그림과 같이 표현할 수 있을 것이다



    - "git reset"은 매우 위험한 명령이기에 그냥 push를 하고자 하면 reject을 당한다! 그래서 "-f" 옵션을 통해 force 실행해야 한다!!!



4. 특정 파일의 이력을 모두 삭제하는 방법


    - 이번 포스팅을 하게 된 이유이다 !!!



    - 위와 같이 commit들이 있다고 해보자. 그림으로 표현하면 아래와 같다.



    - 즉, 예전에 이미 Credential 정보를 넣었는데... 불행하게도 뒤늦게 (이미 commit들이 쌓이고 난 뒤에) Credential 정보를 발견하게 된것이다.

    - 문제가 된 파일과 관련된 모든 이력을 지워보자.


$ git clone git@github.com:whatwant/whatwant.git

Cloning into 'whatwant'...

remote: Enumerating objects: 9, done.

remote: Counting objects: 100% (9/9), done.

remote: Compressing objects: 100% (7/7), done.

Receiving objects: 100% (13/13), done.

Resolving deltas: 100% (3/3), done.

remote: Total 13 (delta 3), reused 7 (delta 1), pack-reused 4



$ cd whatwant/



$ git log --oneline

d81bb67 (HEAD -> master, origin/master, origin/HEAD) add no003.txt

df3c9e0 write token in no002.txt

ea11c2d add no002.txt

83bc6a8 add no001.txt

2b73c6e Initial commit


$ git filter-branch --tree-filter "rm -f no002.txt" HEAD

Rewrite d81bb67affec459cd3e25fa57b98cf64a1bf05be (3/5) (1 seconds passed, remaining 0 predicted)

Ref 'refs/heads/master' was rewritten



$ ls -al

total 9

drwxr-xr-x 1 chani 197121  0 11월  9 20:41 ./

drwxr-xr-x 1 chani 197121  0 11월  9 20:40 ../

drwxr-xr-x 1 chani 197121  0 11월  9 20:41 .git/

-rw-r--r-- 1 chani 197121  0 11월  9 20:40 no001.txt

-rw-r--r-- 1 chani 197121  0 11월  9 20:40 no003.txt

-rw-r--r-- 1 chani 197121 10 11월  9 20:40 README.md



$ git log --oneline

69c84e3 (HEAD -> master) add no003.txt

94413d9 write token in no002.txt

1a2d568 add no002.txt

83bc6a8 add no001.txt

2b73c6e Initial commit



$ git push origin master

To github.com:whatwant/whatwant.git

 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'git@github.com:whatwant/whatwant.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.



$ git push -f origin master

Counting objects: 4, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (4/4), done.

Writing objects: 100% (4/4), 515 bytes | 515.00 KiB/s, done.

Total 4 (delta 1), reused 0 (delta 0)

remote: Resolving deltas: 100% (1/1), done.

To github.com:whatwant/whatwant.git

 + d81bb67...69c84e3 master -> master (forced update)


    - 실제 commit이 어떻게 되어있는지 확인해 보자.



    - 무엇이 바뀌었는지 그림으로 확인해 보자.



    - 위의 방법은 문제가 발생한 파일과 관련한 내용을 전체 히스토리에서 삭제를 하는 것이다.

      → 그렇기 때문에, 영향을 받은 commit을 보면 앞의 commit 까지 포함이 된다.





※ 주의사항


    - 문제가 발생한 정확한 위치를 찾기가 어렵기 때문에 문제가 발생한 파일을 전체 history에서 삭제를 해버리는 방식이다.

      → 해당 파일에 Credential 정보 외의 내역도 있고 이에 대한 내용도 중요하다고 하면 문제가 있을 수 있는 방법이라는 말이다.


    - 그리고, 기존 commit ID 값도 변경이 된다.

      → commit ID 이력을 관리하고 있는 상황인 경우 문제가 있을 수 있다는 말이다.




이러한 번거로움을 피하기 위해서는 애초에 Credential 정보를 파일안에 기재하는 일이 없어야 하겠다.



반응형


회사에서 repo를 사용해야할 개발팀이 Windows 환경에서 개발을 한단다. 이런...

Windows는 테스트 환경도 마땅치 않은데...


그나마 다행인 것은 친절하게도 Windows 환경에서

repo를 사용할 수 있도록 노력을 해주는 사람들이 이미 있다는 것이다 ~ !!! 쌩유 !!!


    ▷ https://github.com/esrlabs/git-repo


이하 내용은 MS Windows 7 64bit 환경에서 테스트 되었다.



1. Precondition


    ① git

        - 여러 종류의 SW가 존재하지만, 표준 제품(?)으로 설치하자 !!!

        ▷ https://git-scm.com/download/

        - 설치는 기본 설정값으로 진행하되 아래 부분은 조금만 신경쓰자





        - 특히 아래와 같이 Enable symbolic links 항목을 꼭 체크하자



    ② Python

        - repo는 python으로 작성된 스크립트이므로, 당연하게도 python이 설치되어 있어야 한다

        ▷ https://www.python.org/downloads/

        - Python 3에서도 실행이 되지만, 아직은 호환성을 고려했을 때 2.7 버전으로 설치하자


        - 가능한 기본 설정값으로 설치를 진행하자



2. Install


    ▷ Ubuntu 환경에서와 마찬가지로 2가지 방법으로 설치 진행할 수 있다.


    (방법 1) curl

        - 평범한(?) 방법이다~


$ cd ~

$ mkdir ./bin

$ curl https://raw.githubusercontent.com/esrlabs/git-repo/stable/repo > ./bin/repo

$ curl https://raw.githubusercontent.com/esrlabs/git-repo/stable/repo.cmd > ./bin/repo.cmd

$ export PATH=$PATH:~/bin


    (방법 2) git clone

        - git으로 존재하는 배포판인데, git clone을 해야지.... ^^


$ cd ~

$ git clone https://github.com/esrlabs/git-repo.git

$ cd ./git-repo

$ git checkout -b stable origin/stable

$ export PATH=$PATH:~/git-repo


    (공통) PATH

        - 영구적으로 실행 경로를 등록하기 위해서 아래와 같이 해보자


$ cd ~

$ nano ./.bashrc


        - 각자 필요한 경로로 작성하면 된다


export PATH=$PATH:~/bin

export PATH=$PATH:~/git-repo



3. How to #1


    □ precondition

        - git을 사용하기 위한 사용자 정보 입력과 작업 공간(directory)를 만들고 시작하자 (기본 경로는 필자 개인 취향이다)


$ cd /srv/workspace

$ mkdir ./whatwant

$ cd ./whatwant


$ git config --global user.name "whatwant"

$ git config --global user.email "whatwant@gmail.com"


    ① init

        - 작업 공간(directory)을 작업하기 위한 상태로 만드는 과정이다


$ repo init -u https://github.com/whatwant-school/manifest --no-clone-bundle


    ② sync

        - 실제 사용할 repository를 가져오는 과정이다


$ repo sync --no-clone-bundle




반응형


long, long time ago ...

필자가 안드로이드 플랫폼과 토발즈 형님의 Git에 한참 빠져있을 때 알게된 repo라는 희한한(?) 도구 !!


안드로이드 플랫폼이 여러개의 repo로 구성되어 공개되다보니,

한 번에 내려받기에 불편함이 많았고, 그래서 google 님께서 만들어 배포한 repo라는 도구.



여러 개의 repository로 구성된 프로젝트를 위해서 git 에서는 submodule이라는 기능을 지원해주고 있다.

최근에 많이 좋아졌다고는 하는데... 개인적으로 안좋아한다. 너무 어렵고 햇갈려서..... ㅠㅠ


그렇다고 해서 repo가 사용하기에 엄청 쉬운 것은 아니지만

그래도 개인적으로는 다수의 repository를 관리하는 용도로는 괜찮은 도구라고 생각된다.


아래 참고자료를 바탕으로 한 번 정리해보겠다.


▷ 소스코드 URL : https://gerrit.googlesource.com/git-repo/

▷ 가 이 드  URL : https://source.android.com/setup/develop/repo

▷ 설치방법 URL : https://source.android.com/setup/build/downloading#installing-repo


매뉴얼과는 조금 진행 방식에서 차이가 날 수는 있다.

필자 회사 사정상.... curl 등을 통한 외부와의 연결(?)이 수월하지 않기에...

별도의 온라인(?) 없이 편하게 사용할 수 있는 방향으로.... ^^



이하 내용은 Ubuntu 14.04 64bit 환경에서 테스트 되었습니다.



1. Precondition


    ① git

        - 당연하게도 git은 미리 설치가 되어있어야 한다.


$ sudo apt-get install git



    ② bundle

        - repo에서는 git 기능 中 bundle이라는 것을 사용한다. 일단, 이런게 있다라는 것만 알아두면 된다

        - 참고 : https://git-scm.com/book/ko/v2/Git-%EB%8F%84%EA%B5%AC-Bundle



    ③ proxy

        - proxy를 사용하는 network 상황이라고 하면, 다음과 같이 설정이 되어 있어야 한다


export HTTP_PROXY=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port>

export HTTPS_PROXY=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port>



2. Install


    ▷ repo를 설치하는 경로는 각자 알아서 하면 되지만, 필자의 경우 개인적인 취향으로 "/srv/install/repo/" 경로로 잡았다.

    ▷ 아래 두가지 방법 中 개인적인 취향에 따라 선택하면 된다.


    (방법1) curl

        - 일반적으로 알려진 방법으로써 대부분 이렇게 가이드 되고 있다.

        - curl을 이용해서 다운로드 받은 후, 실행권한 주고, 경로에 추가해서 어디서나 실행할 수 있도록 하는 방법이다.


$ cd /srv/install/repo/

$ curl https://storage.googleapis.com/git-repo-downloads/repo > ./repo

$ chmod a+x ./repo

$ export PATH=/srv/install/repo:$PATH


    (방법2) git clone

        - 그냥 repo 프로젝트를 그대로 다운로드 받아서 사용하는 방법이다.

        - repo 업그레이드 같은 것을 할 때 유리할지도... ?!


$ cd /srv/install/

$ git clone https://gerrit.googlesource.com/git-repo

$ cd ./git-repo

$ git checkout -b stable origin/stable

$ export PATH=/srv/install/git-repo:$PATH



3. manifest


    ▷ 여러 repository들에 대한 정보를 관리하기 위한 파일이 바로 manifest 파일이다.

    ▷ 필요한 정보를 저장하는 방법을 알아보자.


    □ sample

        - repo의 가장 표본이 되는 android 에서 사용되는 manifest 파일의 일부를 아래와 같이 뽑아보았다.


<?xml version="1.0" encoding="UTF-8"?>

<manifest>

    <remote  name="aosp"  fetch=".."   review="https://android-review.googlesource.com/" />

    <default revision="master"   remote="aosp"   sync-j="4" />

    <project path="build/make" name="platform/build" groups="pdk" >

      <copyfile src="core/root.mk" dest="Makefile" />

      <linkfile src="CleanSpec.mk" dest="build/CleanSpec.mk" />

    </project>

    <project path="build/blueprint" name="platform/build/blueprint" groups="pdk,tradefed" />

</manifest>


    ① <remote />

        - 가장 중요한 기본적인 프로젝트 정보를 적는 곳이다.

            . name : remote 별칭

            . fetch : repository들을 받아올 server 정보

            . review : review를 요청할 server 정보


    ② <default />

        - 뒤에 나올 project에서 사용될 기본 설정값을 적는 곳이다.

            . revision : default branch name

            . remote : default remote name

            . sync-j : repository 정보를 내려받을 때, 동시에 몇 개씩 할 것인지...


    ③ <project />

        - 개별 repository에 관련된 정보를 적는 곳이다.

            . name : server 에서 repository 경로

            . path : local에 실제 저장될 경로

            . group : repository들을 묶음으로 관리하기 위한 별칭

            . revision : sync 한 뒤에 HEAD가 될 commit id


    ④ <copyfile />

        - 파일 복사가 필요한 경우에 사용할 수 있다.

            . src : 복사할 원본 파일 경로

            . dest : 복사될 타켓 파일 경로


    ⑤ <linkfile />

        - 링크 파일 생성이 필요한 경우에 사용할 수 있다.

            . src : 링크될 원본 파일 경로

            . dest : 타겟 링크 파일 경로



4. how to #1


    ▷ 모든 명령어(옵션?)를 공부한다는 것은 말도 안되는 것이고... 몇 가지 시나리오를 가지고 따라해봐야 할텐데 ... 일단 한 번 


    □ precondition

        - git을 사용하기 위한 사용자 정보 입력과 작업 공간(directory)를 만들고 시작하자 (기본 경로는 필자 개인 취향이다)


$ cd /srv/workspace

$ mkdir ./whatwant

$ cd ./whatwant


$ git config --global user.name "whatwant"

$ git config --global user.email "whatwant@gmail.com"


    ① init

        - 작업 공간(directory)을 작업하기 위한 상태로 만드는 과정이다


$ repo init -u https://github.com/whatwant-school/manifest --no-clone-bundle


        - 뒤의 "--no-clone-bundle" 옵션을 빼도 실행에는 지장이 없지만, 에러 메시지 보기 싫어서 넣었다.

        - 'repo init'을 실행하게 되면, git-repo repository를 clone 받게 되는데...

          회사에서는 이 부분을 좀 수정해야할 수도 있을 것 같다. 나중에 하게 되면 그 때 다시 포스팅을~^^


    ② sync

        - 실제 사용할 repository를 가져오는 과정이다


$ repo sync --no-clone-bundle


        - 자꾸 "--no-clone-bundle" 옵션을 넣는 것도 귀찮으니... 회사에서는 이 부분도 기본값을 수정하면 편할 것 같다는 느낌이...




이번 포스팅은 여기까지만 ... 뒷 부분 이야기는 필요에 따라서 ... ^^


반응형


Git에 대해서 공부하다보면, 조금 답답한 것 중 하나가 용어 정리를 해주지를 않는다는 점이다.
그런 것 중 하나가 바로 [ Fast-Forward ]라는 용어다.


이 블로그에 포스팅하고 있는 내용들 모두 마찬가지이지만,
특히 이번 블로그는 절대적으로 개인적인 의견과 함께 개인적으로 정리한 내용이다.
즉, 완전 거짓말일 수 있다는 말이다. 꼭 참고하길 바란다!!! (책임지지 않아요~)



1. 합치자고~

     - Git에서 이루어지는 merge 방법은 다음의 세가지 타입이 있다.
          ▷ 3-way merge
          ▷ fast-forward merge
          ▷ cherry-pick

     - 명령어로 따지면 다음 3가지 방법이 있다.
          ▷ merge
          ▷ rebase
          ▷ cherry-pick



2. 명령어와 방식의 구분

     - 각 명령어와 merge 방식의 관계는 다음과 같다.

  merge rebase cherry-pick
3-way merge O X X
fast-forward merge O O X
cherry-pick X X O

 


     - 즉, merge 명령을 통해서는 상황에 따라 "3-way merge"가 이루어질 수도 있고,
       "fast-forward merge"가 이루어질 수도 있다.

     - rebase 명령의 경우에는 기본적으로 "fast-forward merge"가 이루어진다.
     - cherry-pick 명령은 "cherry-pick"을 위한 명령이다.




3. fast-forward merge

     - fast-forward의 본래 뜻은...!? 앞으로 감다!!! 즉, FF 버튼이나 FFWD 버튼이 바로 이것이다.
     - fast-forward merge가 이루어지는 경우는 두 가지이다.

          ▷ merge 상황에서 merge를 하는 branch에서 별도의 commit이 없는 경우
          ▷ rebase를 수행하는 경우

 


4. 3-way merge

     - 일반적인 merge 상황에서 git은 기본적으로 3-way merge를 수행한다. 
     - 양쪽 브랜치에 commit이 있는 상황에서 merge를 하면 merge commit과 함께 합쳐지는 것이다.

 

5. cherry-pick merge

     - 특정 commit만을 반영하고 싶은 경우이다. 
     - 양쪽 브랜치에 commit이 있는 상황에서 merge를 하면 merge commit과 함께 합쳐지는 것이다.

 

정말 옛날에 작성해놓고 keep 하고 있는 포스팅인데...

자세한 설명은 다음 기회에 하기로 하고... 그냥 발행한다 ^^

(잠자고 있는 포스트 발행하기 프로젝트 중이라서... ㅋㅋ)

 

반응형

Global 적으로 가장 많은 사용자를 갖고 있다는 Linux Mint 환경에서
무언가를 테스트해보기 위해서 작업을 하다가...

갑작스레 최신 Git을 설치해보고 싶어서 진행을 해봤다.

 


1. 필수 패키지 설치
   - Linux Mint 라고 해도 결국은 Debian 기반의 Ubuntu 친구들이다. 다를 것이 없다.


 

$ sudo apt-get install make libcurl4-gnutls-dev libexpat1-dev gettext zlib1g-dev libssl-dev asciidoc xmlto autoconf

 

 

2. 다운로드

$ cd /srv/install/git

$ wget http://www.kernel.org/pub/software/scm/git/git-2.1.2.tar.gz
$ tar zxvf git-2.1.2.tar.gz
$ cd git-2.1.2/


3. 빌드

$ make configure
$ ./configure --prefix=/usr/local
$ make all doc
$ sudo make install install-doc install-html

   - 설치가 잘 되었는지 확인을 해보기 위해서 버전 확인을 해보자.

$ git --version



GIT 자동완성을 지원하기 위해서는...

   - https://www.whatwant.com/entry/Git-명령어-자동-완성-기능-Source-설치-時

 


우리 모두 Git으로 행복한 형상관리를...



반응형

오랜만에 새로운 Ubuntu 버전과 Git 버전을 가지고 설치를 진행해보았다.
달라진 것은 없다.



1. 필수 패키지 설치

$ sudo apt-get install make libcurl4-gnutls-dev libexpat1-dev gettext zlib1g-dev libssl-dev asciidoc xmlto autoconf

 

 

2. 다운로드

$ cd /srv/install/git

$ wget http://www.kernel.org/pub/software/scm/git/git-2.1.0.tar.gz
$ tar zxvf git-2.1.0.tar.gz
$ cd git-2.1.0/


3. 빌드

$ make configure
$ ./configure --prefix=/usr/local
$ make all doc
$ sudo make install install-doc install-html

   - 설치가 잘 되었는지 확인을 해보기 위해서 버전 확인을 해보자.

$ git --version



GIT 자동완성을 지원하기 위해서는...

   - http://whatwant.tistory.com/478


우리 모두 Git으로 행복한 형상관리를...

반응형

Git의 데이터들을 다루기 위해서 Python을 이용해서 스크립트를 종종 만들고 있다.

지금까지는 subprocess를 사용해서
외부 명령어(git)를 실행하고 그 결과를 String으로 받아서 파싱하는 방식으로 만들었는데...
(혼자서 나만의 Git Class를 만들어서, 쿵짝쿵짝... ^^)


Python Library로 제공되는 것이 있지 않을까 좀 찾아보았더니... 당연히(?) 있다!

GitPython 0.3.2 RC1 (Python Git Library) : 2011-07-06
   https://pypi.python.org/pypi/GitPython/0.3.2.RC1

Package Documentation
   GitPython is a python library used to interact with Git repositories.

Author                            : Sebastian Thiel, Michael Trier
Documentation                : GitPython package documentation
Home Page                     : http://gitorious.org/projects/git-python/
License                          : BSD License
Requires                         : gitdb (>=0.5.1)
Package Index Owner      : Sebastian.Thiel, mtrier
Package Index Maintainer : Sebastian.Thiel
DOAP record                   : GitPython-0.3.2.RC1.xml

gitdb 0.5.4 (Git Object Database) : 2011-07-05
   https://pypi.python.org/pypi/gitdb

Package Documentation
   GitDB is a pure-Python git object database

Author                       : Sebastian Thiel
Documentation           : gitdb package documentation
Home Page                : https://github.com/gitpython-developers/gitdb
License                     : BSD License
Requires                    : async (>=0.6.1), smmap (>=0.8.0)
Package Index Owner : Sebastian.Thiel
DOAP record              : gitdb-0.5.4.xml


Ubuntu를 사용하게 되면 정말 편리한 점 중에서 한 가지가 바로 Package 관리인데...
주어진대로 사용을 하면 편리하지만, 직접 설치해서 뭔가 하려하면 오히려 번거로운 부분도 많다.

Python도 마찬가지인데 Python과 관련된 전부를 다운로드 받아서 직접 설치한 것이 아니라면
그 외 나머지들도 그냥 패키지로 설치하는 것이 편리하다.

위의 라이브러리들도 마찬가지인데...
이미 Python을 Ubuntu에서 제공하는 패키지로 설치해서 사용하고 있기에,
그냥 Ubuntu에서 제공해주는 패키지로 설치를 해보려고 했는데...

아래와 같이 하면 설치는 되는데... Ubuntu 버전에 따라 제공하는 버전이 다르다.

$ sudo apt-get install python-git

현재(2014.06) 제공하는 버전은 아래와 같다.

 Version  Release   python-git version 
 14.04  Trusty Tahr  0.3.2~RC1-3 
 13.10  Saucy Salamander  0.3.2~RC1-2 
 13.04  Raring  0.3.2~RC1-1
 12.04  Precise Pangolin  0.1.6-1
 10.04  Lucid Lynx  0.1.6-1 

위와 같이 설치하면 편하기는 하지만, 쓸데없는(?) 부가 패키지들도 같이 설치를 한다.

$ sudo apt-get install python-git
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다      
상태 정보를 읽는 중입니다... 완료
다음 패키지를 더 설치할 것입니다:
  git git-man liberror-perl libjs-jquery python-async python-gitdb python-smmap
제안하는 패키지:
  git-daemon-run git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-bzr
  git-cvs git-mediawiki git-svn javascript-common
다음 새 패키지를 설치할 것입니다:
  git git-man liberror-perl libjs-jquery python-async python-git python-gitdb python-smmap
0개 업그레이드, 8개 새로 설치, 0개 제거 및 0개 업그레이드 안 함.
3,780 k바이트 아카이브를 받아야 합니다.
이 작업 후 23.5 M바이트의 디스크 공간을 더 사용하게 됩니다.
계속 하시겠습니까? [Y/n]

특히 git과 관련한 패키지들도 설치를 하게 되는데, git을 source로 직접 설치한 경우 불필요하고 번거롭기만 하다.


그러면, python-git을 개별 설치하려면 어떻게 해야할까?!
원하는 최신 버전으로 설치하기 위해서는 다음과 같이 수행하자.

$ sudo apt-get install python-setuptools python-dev
$ sudo easy_install GitPython

간단하다.
현재(2014.06) 설치되는 버전은 '0.3.2~RC1'이다.



잘 동작하는지 테스트를 해보기 위해서는 다음과 같이 해보자.



아래 샘플 코드로 돌려보자~

#!/usr/bin/python
# -*- coding: utf-8 -*-

import git
import os
import sys
import time

if __name__ == "__main__":

        #for i in range(len(sys.argv)):
        #       print "sys.argv[%d] = '%s'" % (i, sys.argv[i])

        #repo = git.Repo.clone_from( URL_SOURCE, PATH_TARGET )


        if len(sys.argv) < 2:
                sys.exit('Usage: %s repository-name' % sys.argv[0])

        if not os.path.isdir(sys.argv[1]):
                sys.exit('ERROR: Repository %s was not found!' % sys.argv[1])


        PATH_TARGET = sys.argv[1]
        repo = git.Repo( PATH_TARGET )

        for remote in repo.remotes:
                print "[ " + str(remote) + " branches ]"

                for branch in getattr(repo.remotes, str(remote)).refs:
                        print " " + str(branch).replace( str(remote)+"/", "" )

                        for commit in repo.iter_commits(branch, max_count=3):

                                print ""
                                print "         Commit          : ", commit
                                print "         Author          : ", commit.author, ", (",
                                print time.asctime(time.gmtime(commit.authored_date)), ")"
                                print "         Committer       : ", commit.committer, ", (",
                                print time.asctime(time.gmtime(commit.committed_date)), ")"
                                print "         Encoding        : ", commit.encoding
                                print "         Summary         : ", commit.summary
                                print "         Delta LOC       : ", commit.stats.total['lines'], " (+",
                                print commit.stats.total['insertions'], ", -",
                                print commit.stats.total['deletions'], ")"
                                #print commit.stats.files
                                #print "                Message         : ", commit.message
                                #print "                Parents         : ", commit.parents

        print ""

        print "[ Local branches ]"
        for branch in repo.branches:
                print " " + str(branch)

                #commits = list( repo.iter_commits(branch, max_count=10) )

                for commit in repo.iter_commits(branch, max_count=3):

                        print ""
                        print "         Commit          : ", commit
                        print "         Author          : ", commit.author, ", (",
                        print time.asctime(time.gmtime(commit.authored_date)), ")"
                        print "         Committer       : ", commit.committer, ", (",
                        print time.asctime(time.gmtime(commit.committed_date)), ")"
                        print "         Encoding        : ", commit.encoding
                        print "         Summary         : ", commit.summary
                        print "         Delta LOC       : ", commit.stats.total['lines'], " (+",
                        print commit.stats.total['insertions'], ", -",
                        print commit.stats.total['deletions'], ")"
                        #print commit.stats.files
                        #print "                Message         : ", commit.message
                        #print "                Parents         : ", commit.parents


공식 매뉴얼과 가이드는 다음에서 확인할 수 있다.

   http://pythonhosted.org/GitPython/0.3.2/tutorial.html
   http://pythonhosted.org/GitPython/0.3.2/reference.html

반응형

GitHub는 무료로 서비스를 해주지만, 해당 서비스를 내 서버에서 운영할 수는 없다.
물론 돈을 주면 가능하긴 하다지만... 저렴한 인생으로써는...^^

그래서 찾아보던 중 오픈소스 프로젝트로 진행중인 GitLab을 알게 되었다.
설치 과정이 단순하진 않지만... 나만의 GitHub 구축을 위해서 !!!


공식 홈페이지에 설치 가이드가 너무나 잘 나와 있다.
   - https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md


앞에서 작성한 포스트를 참고해도 좋다.
   - http://whatwant.tistory.com/332



01. 필수 패키지 설치

$ sudo apt-get install build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils



02. Git 설치

   - http://whatwant.tistory.com/658


03. Ruby 설치

$ sudo su -
$ curl -L https://get.rvm.io | sudo bash -s stable
$ source /etc/profile
$ rvm install 2.0.0
$ rvm use 2.0.0
$ rvm --default use 2.0.0 

 

$ nano /etc/environment

 

PATH="......:/usr/local/rvm/bin"

 

$ gem install bundler --no-ri --no-rdoc



04. 계정 만들기

$ adduser --disabled-login --gecos 'GitLab' git



05. GitLab-Shell 설치하기

$ cd /home/git

$ sudo -u git -H git clone http://github.com/gitlabhq/gitlab-shell.git -b v1.7.9

$ cd gitlab-shell

$ sudo -u git -H cp config.yml.example config.yml
$ sudo -u git -H nano config.yml

 

...
gitlab_url: "http://localhost/"
...

 

$ sudo su - git
$ cd /home/git/gitlab-shell
$ ./bin/install



08. Database

   - 필자의 취향으로 일단 PostgreSQL로 진행해보자.

$ sudo apt-get install postgresql libpq-dev

$ sudo -u postgres psql -d template1

 

# CREATE ROLE git LOGIN ENCRYPTED PASSWORD 'password' NOINHERIT VALID UNTIL 'infinity';
# CREATE DATABASE gitlabhq_production OWNER git;
# \q


   - 접속이 잘 되는지 테스트 함 해보자.

$ sudo -u git -H psql -d gitlabhq_production



09. GitLab 다운로드

$ cd /home/git
$ sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git -b 6-3-stable gitlab

 


10. GitLab 환경 설정

$ cd /home/git/gitlab

$ sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml


   - 도메인을 지정하고 싶으면 다음처럼 수정 작업을 하면 된다.

$ sudo -u git -H nano config/gitlab.yml


...
   host: localhost
...


   - 권한 조정이 필요하다.

$ sudo chown -R git log/
$ sudo chown -R git tmp/
$ sudo chmod -R u+rwX  log/
$ sudo chmod -R u+rwX  tmp/


   - satellites를 위한 디렉토리를 하나 생성하고, 필요한 디렉토리를 만들자.

$ sudo -u git -H mkdir /home/git/gitlab-satellites


   - 필요한 디렉토리를 추가로 더 만들자.

$ cd /home/git/gitlab

$ sudo -u git -H mkdir tmp/pids/
$ sudo -u git -H mkdir tmp/sockets/
$ sudo chmod -R u+rwX  tmp/pids/
$ sudo chmod -R u+rwX  tmp/sockets/

$ sudo -u git -H mkdir public/uploads
$ sudo chmod -R u+rwX  public/uploads


   - 엄청 귀찮넹... 스크립트로 만들어서 제공하지....

   -  Unicorn 환경 설정을 진행하자.

$ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb


   - 고성능이 필요하면 cluster mode를 활성화 하자. 방법은 간단하다 ?!

$ sudo -u git -H nano config/unicorn.rb


   - worker_processes를 3으로 변경하면 된다 ?!

...
worker_processes 2
...


   - 이번에는 Rack attack config를 진행하자.

$ sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb


   - rack attack middleware를 설정하고 싶으면 다음과 같이 하자.

$ sudo -u git -H nano config/application.rb


   - 주석처리된 부분을 찾아서 주석 표시를 지우면 된다고 한다. (뭘 하는지는 아직 모르겠다.)

...
   # config.middleware.use Rack::Attack
...



11. 기본 사용자 설정

   - Git 사용자 설정을 하자.

$ sudo -u git -H git config --global user.name "GitLab"
$ sudo -u git -H git config --global user.email "gitlab@whatwant.com"
$ sudo -u git -H git config --global core.autocrlf input


   - 위 설정은 다음의 설정에서도 적용이 필요하다.

$ sudo -u git -H nano config/gitlab.yml



12. Database 환경 파일 설정

   - PostgreSQL을 사용하는 경우이다.

$ sudo -u git cp config/database.yml.postgresql config/database.yml


   - git 계정에서만 읽어볼 수 있게 하기 위한 권한 설정을 하자.

$ sudo -u git -H chmod o-rwx config/database.yml



13. Install Gems

$ sudo su - git
$ cd /home/git/gitlab
$ bundle install --deployment --without development test mysql aws



14. Database 생성

$ sudo su - git
$ cd /home/git/gitlab
$ bundle exec rake gitlab:setup RAILS_ENV=production


   - 설치과정 끝에 나오는 메시지를 잘 확인해야 한다.

...
Administrator account created:

login............admin@local.host
password.....5iveL!fe



15. Init Script 설정하기

$ cd /home/git/gitlab
$ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
$ sudo chmod +x /etc/init.d/gitlab
$ sudo update-rc.d gitlab defaults 21



16. log 관리하기

$ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab



17. 환경 설정이 잘 되었는지 점검

   - 환경 설정이 잘 되었는지 확인을 해야하는데...
   - 우선 우리는 기본 설정값과 다른 git 경로부터 수정하고 확인을 하자.

$ sudo -u git nano config/gitlab.yml

 

...
git:
   bin_path: /usr/local/bin/git
...


   - git 경로를 제대로 적어주고나서 환경 설정 값들을 확인해보자.
 

$ sudo su - git
$ cd /home/git/gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production

 


18. 시작

   - 이후 부터는 재부팅 될 때 자동으로 실행이 되겠지만, 지금은 직접 한 번 실행을 해보자.

$ sudo service gitlab start

 

Starting the GitLab Unicorn web server...
Starting the GitLab Sidekiq event dispatcher...
The GitLab Unicorn webserver with pid 1478 is running.
The GitLab Sidekiq job dispatcher with pid 1506 is running.
GitLab and all its components are up and running.



19. 상태 점검

   - green으로 나오면 좋은 것이다 ^^

$ sudo su - git
$ cd /home/git/gitlab
$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production



20. Nginx


http://tuwlab.com/10476
http://kkame.kr/106
http://blog.naver.com/PostView.nhn?blogId=delltin&logNo=90184174945

   - 개인적으로 Apache2의 대용품(?)으로 좋아하다가 요즘은 살짝 관심을 끊은 Nginx ... ^^
   - GitLab은 공식적으로 웹서버로 Nginx를 추천한다고 한다.

$ sudo apt-get install nginx


   - 설정도 진행을 하자.

$ sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
$ sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab


   -  수정할 것도 있다.

$ sudo nano /etc/nginx/sites-available/gitlab

 

...
   server_name localhost;
...


   - 재시작 !

$ sudo service nginx restart



21. 사이트 테스트

   - [ http://localhost/ ] 접속


   - ID / Password = [ admin@local.host / 5iveL!fe ]


   - 패스워드 재설정 창이 나온다.
   - 여기에서 재설정을 하면 다시 로그인 창이 나온다. 다시 로그인을 하면 된다.


   - 드디어 제대로 된 화면이 나왔다 !!!



헥헥... 너무 힘들다.... 이거, 반드시 스크립트 제공해줘야 한다 !!!

여하튼 일단 페이지 빵! 뜨는 것 까지는 성공~

반응형

+ Recent posts