GitLab CLI Tool (GLab) 설치 및 사용하기
GLab 은 GitLab 의 기능을 웹브라우저를 통하지 않고도 터미널에서 사용할 수 있게 해주는 GitLab CLI 도구입니다.
GitLab API 를 이용하여 프로젝트, 이슈, 병합 요청 등을 터미널에서 쉽게 관리하고 조작할 수 있습니다.
본 매뉴얼 내용은 Ubuntu 22.04 환경에서 테스트 되었습니다.
- GitLab CE 설치 : https://sysdocu.tistory.com/1892
- GitLab CLI : https://gitlab.com/gitlab-org/cli
1. GLab 설치
(Client PC 에서)
작성일 기준 GLab 배포 버전은 1.36.0 을 설치 합니다.
- 버전 정보 : https://gitlab.com/gitlab-org/cli/-/releases
- 우분투 환경이므로 deb 파일을 다운로드, 설치합니다.
# wget https://gitlab.com/gitlab-org/cli/-/releases/v1.36.0/downloads/glab_1.36.0_Linux_x86_64.deb
# dpkg -i glab_1.36.0_Linux_x86_64.deb
추후 사용을 위해 gitlab-runner 바이너리 파일도 다운로드 합니다.
gitlab-runner 는 GitLab CI/CD 를 실행하기 위한 러너 서비스를 관리하기 위한 명령어입니다.
# curl -L --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64"
# chmod 755 /usr/local/bin/gitlab-runner
2. 로그인
1) HTTPS 활성화
(GitLab Server 에서)
GitLab 에서 Let's Encrypt 를 이용해 SSL 인증서를 다운로드 받고 자동으로 HTTPS 포트를 열 수 있습니다.
GitLab 설정 파일을 열고 아래 옵션을 활성화 한다음 값을 입력해줍니다.
# vi /etc/gitlab/gitlab.rb
... external_url 'https://git.sysdocu.kr' # 이곳을 반드시 https 로 고쳐야 합니다. ... letsencrypt['enable'] = true letsencrypt['contact_emails'] = ['root@sysdocu.kr'] letsencrypt['auto_renew_hour'] = 12 letsencrypt['auto_renew_minute'] = 10 letsencrypt['auto_renew_day_of_month'] = "*/7" ... |
변경된 설정을 적용하면 HTTPS 포트가 오픈됩니다.
# gitlab-ctl reconfigure
# netstat -nltp |grep 443
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 238181/nginx: maste
2) 로그인
(Client PC 에서)
GitLab 서버에 인증을 받아야 이용이 가능합니다.
# glab auth login
? What GitLab instance do you want to log into? [Use arrows to move, type to filter]
gitlab.com
> GitLab Self-hosted Instance
여기에서 키보드 방향키를 위, 아래로 이동할 수 있습니다. 'GitLab Self-hosted Instance' 를 선택합니다.
GitLab hostname 입력란에 연결하려는 GitLab 호스트명을 입력합니다.
API hostname 입력란에 연결하려는 API 호스트명을 입력합니다.
로그인 방식을 묻는데, 여기에서 Token 을 선택합니다.
개인 액세스 토큰을 생성할 수 있는 URL 이 출력되는데, 웹브라우저로 접속하여 토큰을 생성하고 복사합니다.
> https://git.sysdocu.kr/-/user_settings/personal_access_tokens?scopes=api,write_repository
'Add new token' 클릭 > Token name 입력하고, 테스트중이므로 하단의 Select scopes 는 모두 체크하고 토큰을 생성합니다.
그러면, 토큰이 생성되며 'Your new project access token' 항목 보이고, 눈 모양 옆의 아이콘을 클릭하면 토큰이 클립보드에 복사됩니다.
다시 CLI 로 돌아옵니다.
토큰을 붙여넣고, git 과 API 프로토콜의 연결 방식은 HTTPS 를 선택합니다.
전체적인 로그인 절차는 아래와 같습니다.
# glab auth login
? What GitLab instance do you want to log into? GitLab Self-hosted Instance
? GitLab hostname: git.sysdocu.kr
? API hostname: git.sysdocu.kr
- Logging into git.sysdocu.kr
? How would you like to login? Token
Tip: you can generate a Personal Access Token here https://git.sysdocu.kr/-/profile/personal_access_tokens?scopes=api,write_repository
The minimum required scopes are 'api' and 'write_repository'.
? Paste your authentication token: **************************
? Choose default git protocol HTTPS
? Choose host API protocol HTTPS
- glab config set -h git.sysdocu.kr git_protocol https
✓ Configured git protocol
- glab config set -h git.sysdocu.kr api_protocol https
✓ Configured API protocol
✓ Logged in as root
root 사용자로 로그인 성공 했습니다.
3. 사용 예
간단한 몇개의 명령을 예시로 제공합니다.
아래 내용 외에 더 자세한 명령은 공식 Documents 를 참고하세요.
[에러] --------------------
예제 명령 수행시 직접 구축한 GitLab 서버가 아닌 gitlab.com 을 참조하게 될 경우
GET https://gitlab.com/api/v4/user: 401 {message: 401 Unauthorized}
아래와 같이 현재 인증된 GitLab 호스트를 출력해보고,
# glab auth status
설정 파일을 열어 기본 설정값을 수정하고, 필요없는 호스트를 삭제합니다.
# vi .config/glab-cli/config.yml
- 수정할 곳 : 위 전체 옵션
ㄴ git_protocol: https
ㄴ host: git.sysdocu.kr
- 삭제할 곳 : 아래 hosts 항목의 gitlab.com 도메인 영역
----------------------------
1) GitLab 리포지토리를 로컬에 복제
# glab repo clone {user}/{repository}
2) GitLab 리포지토리의 이슈 목록 표시
# glab issue list
3) GitLab 리포지토리의 파이프라인 목록 표시
# glab pipeline list
4) GitLab 리포지토리의 머지 리퀘스트(MR) 목록 표시
# glab mr list
5) GitLab 리포지토리에 새 릴리스 생성
# glab release create v1.0
6) GitLab 리포지토리의 레이블 목록 표시
# glab label list
7) GLab 구성 변경
# glab config set editor vim
8) GitLab 스니펫 관리를 위한 명령
# glab snippet create -f file.txt
9) GLab 명령어에 대한 도움말 표시
# glab help
'리눅스 > PaaS' 카테고리의 다른 글
Ubuntu 22.04 에서 Gogs 설치 및 설정하기 (0) | 2024.02.05 |
---|---|
Ubuntu 22.04 단일 서버 K3S Cluster 에서 Korifi 설치하기 (0) | 2024.01.25 |
Ubuntu 22.04 에서 GitLab CE (Community Edition) 설치 및 사용하기 (0) | 2024.01.19 |
Kind Cluster + Korifi 설치 스크립트로 환경 구성시 CF 로 배포되는 앱 CPU Limit 제한 설정하기 (0) | 2024.01.16 |
Kubernetes 에서 Cloud Foundry Service 대체 구성하기 (0) | 2023.12.27 |