공부하기싫어
article thumbnail

목차

     

    현재 노트북을 image build server 로 사용중인데 여기에 gitlab 까지 설치해서 CI 서버로 사용해볼까 한다.

    데스크탑에서 노트북의 gitlab 으로 push 하면 build 결과를 ECR 이나 github 로 push 하게 할 예정

     

    1. GitLab 이란?

    깃랩(GitLab)은 깃랩 사(GitLab Inc.)가 개발한 깃 저장소 및 CI/CD, 이슈 추적, 보안성 테스트 등의 기능을 갖춘 웹 기반의 데브옵스 플랫폼

     

     

    2. GitLab 설치

    https://about.gitlab.com/install/

     

    Download and install GitLab

    Download, install and maintain your own GitLab instance with various installation packages and downloads for Linux, Kubernetes, Docker, Google Cloud and more.

    about.gitlab.com

     

    2.1 GitLab 설치 유형

    • 패키지 설치

    여러 운영체제별로 응용 프로그램처럼 설치할 수 있는 것 같다.

     

    • k8s deployment

    k8s cluster 에서 helm chart 혹은 gitlab operator 로 설치할 수 있다고 한다

     

    • cloud 플랫폼 연동

    aws 관련 설치를 보니 단일 EC2로 설치하는 방법, EKS 에 설치 되는 방법, omnibus 설치 방식 등 클라우드 자원과 쉽게 연동되도록 설치를 지원하는 것 같다.

     

    기타 등등 더있다고 함

     

     

    2.2 GitLab 설치 - docker

    깔끔히 쓰고 지우기 위해 container 를 사용하려고 한다

    package 로 설치해서 오류가 났는데 삭제하는 과정이 너무 귀찮았다

     

    모든 Repository 데이터를 저장할 수 있을 만큼의 여유 공간이 있는 경로에 GitLab 작업 디렉토리 (Working directory)를 생성합니다.

    mkdir gitlab
    cd gitlab
     

    GitLab 데이터를 영속적(Persistent)으로 저장하기 위한 바인드 마운트(Bind mount)용 디렉토리를 생성합니다.

    $ pwd
    /home/cyaninn/gitlab
    $ sudo mkdir data
    $ sudo mkdir logs
    $ sudo mkdir config
     

    GitLab 컨테이너는 호스트 마운트 볼륨을 사용하여 영구 데이터를 저장합니다.

    Directory Container location Usage
    data /var/opt/gitlab 애플리케이션 데이터 저장용
    logs /var/logs/gitlab 로그 저장용
    config /etc/config Gitlab 구성 파일 저장용

     

    gitlab 디렉토리의 소유권을 $USER로 변경합니다.

     

    권한을 변경합니다.

    sudo chmod -R 755 gitlab

     

    • docker compose yaml
    $ vim gitlab-docker-compose.yaml
    version: '3.9'
    
    services:
      gitlab:
        image: 'gitlab/gitlab-ee:latest'
        container_name: gitlab
        restart: always
        hostname: 'gitlab.example.com'
        environment:
          GITLAB_OMNIBUS_CONFIG: |
            external_url 'https://gitlab.example.com'
            gitlab_rails['gitlab_shell_ssh_port'] = 1922
            # Add any other gitlab.rb configuration here, each on its own line
          TZ: 'Asia/Seoul'
        ports:
          - '1980:80'
          - '19443:443'
          - '1922:22'
        volumes:
          - './config:/etc/gitlab'
          - './logs:/var/log/gitlab'
          - './data:/var/opt/gitlab'

     

    위 내용을 추가하고 저장합니다. (hostname external_url은 설치할 서버의 IP 또는 도메인으로 반드시 수정해야 합니다.)

    참고
    라이선스 없이 GitLab Enterprise Edition을 설치하면 Community Edition 인스턴스와 동일한 기능을 모두 사용할 수 있으며, 추가적인 이점도 있습니다.언제든지 유료 기능을 평가하고 싶다면, 새 인스턴스를 설치 및 구성하거나 기존 인스턴스를 업그레이드하지 않고도 이 작업을 수행할 수 있습니다. GitLab 내에서 평가판을 활성화하기만 하면 됩니다. 유료 기능에 만족하지 않으면 평가판이 만료된 후 인스턴스가 자동으로 무료 기능으로 되돌아갑니다.Community Edition에서 Enterprise Edition으로 업그레이드하려면 동일한 버전을 사용하고 있는지 확인하고 종종 다운 타임이 필요한 특정 단계를 따라야 합니다. Enterprise Edition을 사용하면 클릭 한 번으로 유료 기능으로 업그레이드할 수 있습니다. :::

     

    포트 번호때문에 시간을 너무 태웠다

    처음엔 10080, 10443, 10022 로 했었다가 위험한 포트라고 해서 chrome, firefox 에서 접근이 안됬고

    1580, 15443, 1522 로 해도 접속이 안됬었다.

    다른 블로거분이 1980 19443 1922 를 써서 나도 해봤는데 접속이 가능했다.

     

     

    설치 실행

    $ cp gitlab-docker-compose.yaml docker-compose.yaml
    $ tree
    .
    ├── config
    ├── data
    ├── docker-compose.yaml
    ├── gitlab-docker-compose.yaml
    └── logs
    
    3 directories, 2 files
    $ docker-compose up -d

     

     

    3. GitLab 동작 확인

    3.1 UI 접속

    접속 확인
    비밀번호 변경
    비밀번호 변경2

     

     

    3.2 commit/push

    • 프로젝트 생성

     

    • git config

    계정 정보 확인

    git config user.name "myname"
    
    git config user.email "my email"

     

    • git clone , add , commit, push
    # git clone
    > git clone http://192.168.0.115:1980/root/test-project.git
    
    # 새로운 파일 생성 (add-file.py)
    # git add (모든 파일)
    > git add .
    
    # git commit
    > git commit -m "push from desktop"
    [main bb39120] push from desktop
     1 file changed, 1 insertion(+)
     create mode 100644 add-file.py
     
     # git push
    > git push -u 
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 12 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 364 bytes | 364.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    To http://192.168.0.115:1980/root/test-project.git
       0dbc54c..bb39120  main -> main
    Branch 'main' set up to track remote branch 'main' from 'origin'.

     

    • 확인

     

    3.3 pull

    gitlab project 에서 새로운 파일 생성 후 로컬에서 pull

    > dir
     Volume in drive D is 새 볼륨
     Volume Serial Number is 3AB4-407E
    
     Directory of D:\DEV\ethereum_autotrade\Cryptocurrency-autotrade-pyupbit\gitlab-test\test-project
    
    2023-07-16  오전 03:00    <DIR>          .
    2023-07-16  오전 02:56    <DIR>          ..
    2023-07-16  오전 03:01                36 add-file.py
    2023-07-16  오전 02:57             6,277 README.md
    2023-07-16  오전 02:57                15 test.py
                   3 File(s)          6,328 bytes
                   2 Dir(s)  367,116,066,816 bytes free
    >
    > git pull
    remote: Enumerating objects: 4, done.
    remote: Counting objects: 100% (4/4), done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), 331 bytes | 2.00 KiB/s, done.
    From http://192.168.0.115:1980/root/test-project
       bb39120..5fb7af9  main       -> origin/main
    Updating bb39120..5fb7af9
    Fast-forward
     new-file.py | 1 +
     1 file changed, 1 insertion(+)
     create mode 100644 new-file.py
    >
    > dir
    ...
    2023-07-16  오전 03:09    <DIR>          .
    2023-07-16  오전 02:56    <DIR>          ..
    2023-07-16  오전 03:01                36 add-file.py
    2023-07-16  오전 03:09                18 new-file.py
    2023-07-16  오전 02:57             6,277 README.md
    2023-07-16  오전 02:57                15 test.py
    ...

     

    참고

     

    https://about.gitlab.com/install/#official-linux-package

     

    Download and install GitLab

    Download, install and maintain your own GitLab instance with various installation packages and downloads for Linux, Kubernetes, Docker, Google Cloud and more.

    about.gitlab.com

    https://insight.infograb.net/docs/setup/install/install_with_docker_compose/

     

    Docker Compose로 GitLab 설치 | DevSecOps 구축 컨설팅, 교육, 기술지원 서비스 제공

    Ubuntu에 Docker Compose를 사용하여 Omnibus GitLab를 설치할 수 있습니다.

    insight.infograb.net

     

    'IT etc > Gitlab' 카테고리의 다른 글

    GitLab-Runner CI 구축 demo  (0) 2023.07.16