Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
05-16 20:20
관리 메뉴

nomad-programmer

[DevOps/Docker] Docker를 이용한 로컬 환경에서 GitLab-CE 서버 구축 (with docker-compose) 본문

DevOps/Docker

[DevOps/Docker] Docker를 이용한 로컬 환경에서 GitLab-CE 서버 구축 (with docker-compose)

scii 2020. 12. 8. 18:00

버전 관리 서버를 private 하게 내부에서 관리할 필요가 있다는 판단하여 docker를 가지고 GitLab 서버를 구축하였다. 구축 과정을 블로그에 남긴다.

DB서버를 사용하는 내부 서버가 있다. 그곳에다 GitLab서버를 구축하려고하였다. 그래서 다른것 하나 생각치않고 docker부터 떠올렸다. 이유는 해당 서버에 DB서버가 구축되어 있기 때문에 GitLab서버를 그대로 설치해버리면 기존에 사용하던 시스템이 망가질 우려가 있었기 때문이다. 

따라서 기존의 시스템에 전혀 영향이 가지 않게끔 도커를 이용하여 GitLab 서버를 설치하였다.

hub.docker.com/r/gitlab/gitlab-ce

 

Docker Hub

 

hub.docker.com


GitLab 서버 설치

gitlab 서버 설치에 사용한 이미지는 Docker Hub에서 제공하는 이미지를 사용하였다.

docker-compose를 사용한 gitlab 서버 설치의 공식 가이드는 아래의 링크에서 볼 수 있다.

docs.gitlab.com/omnibus/docker/README.html#install-gitlab-using-docker-compose

 

GitLab Docker images | GitLab

GitLab Docker images The GitLab Docker images are monolithic images of GitLab running all the necessary services in a single container. If you instead want to install GitLab on Kubernetes, see GitLab Helm Charts. Find GitLab’s official Docker image at: T

docs.gitlab.com

나 또한 gitlab 서버 설치할 때 공식 가이드를 참고하여 설치하였다. 내가 작성한 docker-compose.yml 파일의 내용은 아래와 같다.

  • hostname : 설치할 서버의 IP 혹은 호스트명을 입력한다.
  • ports : 8829 -> 80, 4443 -> 443, 2224 -> 22 로 매핑시켰다. 이유는 혹시 모를 중복되어지는 포트가 있을 수 있기 때문이다. 그리고 해당 서버에서 벌써 22번 포트를 사용하고 있었기에 ssh 포트를 변경하면서 나머지도 변경하였다.
  • external_url : 'http://호스트명:포트번호' 이런식으로 입력한다. 이 주소는 추후 gitlab에서의 clone을 이용할 때 사용되어지는 주소이다. 포트번호를 적지 않으면 gitlab에서 포트번호가 보이지 않게 되어 clone할 때 매번 포트 번호를 적어줘야하는 귀찮은 일이 발생하므로 필히 적어주는 것이 좋을 것이다.
  • gitlab_rails['gitlab_shell_ssh_port'] : 이 값에 새로운 ssh 포트 값을 입력하였다.
  • nginx['listen_port'] : external_url 옵션에 포트번호가 들어가는데 이 옵션이 빠진다면, gitlab 접속이 불가능할 것이다. 그러므로 nginx의 포트를 지정해주었다.
  • nginx['client_max_body_size'] : 만약 큰 용량의 파일을 올릴 수 있다면 용량을 크게 잡는다. 한번에 올릴 수 있는 용량의 크기를 정하는 옵션이다.
  • volumes : gitlab 서버 컨테이너를 삭제하여도 기존의 쌓였던 데이터들을 고스란히 보관하기 위하여 volumes 옵션을 주었다.
  • volumes - backups : 이것은 추후 gitlab 서버 데이터의 백업 및 복구를 편하게 하기 위하여 설정한 것이다.

위의 파일을 작성했다면 다음의 명령으로 gitlab 서버 컨테이너를 실행시킨다.

$ docker-compose up -d

참고로 gitlab 서버가 정지되었을 경우 아래의 명령처럼 gitlab 서버 컨테이너를 실행시키면 된다.

$ docker start gitlab

 


GitLab 이미지 Update

gitlab의 버전을 업데이트할 때는 gitlab 컨테이너를 제거하고, gitlab 도커 이미지를 업데이트 한 후 그 이미지로 컨테이너를 만들면 된다. 

// 도커 컨테이너 정지
$ docker container stop gitlab

// 혹은 아래와 같이 docker-compose로 컨테이너를 볼륨과 함께 정지 후 제거
$ docker-compose -f <docker-compose.yml 경로> down -v


// 도커 이미지 제거
$ docker image rm gitlab

// gitlab 최신버전 이미지 가져오기
$ docker image pull gitlab/gitlab-ce:latest

// gitlab 실행
$ docker-compose up -d

하지만 docker-compose.yml 파일을 작성했다면 아래와 같이 간단한 방법으로 update를 할 수 있다.

// docker-compose.yml 파일 위치로 이동 후

// gitlab update
$ docker-compose pull

// gitlab 재실행
$ docker-compose up -d

// 혹은, 컨테이너를 완전하게 삭제 후 실행
$ docker-compose up -d --force-recreate

이메일 발송 설정

이메일을 설정해 놓으면 사용자가 비밀번호를 분실했을 경우, 비밀번호 재설정을 이메일로 받아 볼 수 있다. 이런 설정을 하려면 gitlab 컨테이너에 접속하여 설정 파일을 수정해야 한다.

// gitlab 컨테이너 접속
$ docker container exec -it gitlab /bin/bash

// 설정 파일 수정
$ vim /etc/gitlab/gitlab.rb

아래의 공식 가이드 문서에 가면 본인이 원하는 이메일 설정 방법이 자세히 나와 있으므로 그것을 보고 따라하면 되겠다.

docs.gitlab.com/omnibus/settings/smtp.html

 

SMTP settings | GitLab

SMTP settings If you would rather send application email via an SMTP server instead of via Sendmail, add the following configuration information to /etc/gitlab/gitlab.rb and run gitlab-ctl reconfigure. cautionYour smtp_password should not contain any Strin

docs.gitlab.com

이메일 설정을 모두 마쳤다면 다음과 같은 명령을 통해 변경된 설정을 적용하자.

// /etc/gitlab/gitlab.rb 파일을 변경한 후에는 항상 다음의 명령을 통해 변경 사항을 적용시켜줘야 한다.

gitlab-ctl reconfigure

GitLab 서버 Backup

/var/opt/gitlab/backups 디렉토리를 공유 디렉토리로 매핑시켰다. 그것은 gitlab 서버 복원을 편하게 하기 위함이다. 

백업된 gitlab 데이터 파일을 /var/opt/gitlab/backups 디렉토리 즉, 현재 셋팅해서는 ~/Documents/gitlab/backups 디렉토리에 넣고 아래의 명령을 실행하면 gitlab 데이터가 복원된다.

docker exec -it <name of="" container=""> gitlab-rake gitlab:backup:restore

백업에 관련된 공식 문서는 아래의 링크를 참고하면 된다.

docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-docker-image-and-gitlab-helm-chart-installations

 

Back up and restore GitLab | GitLab

Back up and restore GitLab GitLab provides Rake tasks for backing up and restoring GitLab instances. An application data backup creates an archive file that contains the database, all repositories and all attachments. You can only restore a backup to exact

docs.gitlab.com

참고로, 실행중인 gitlab 서버 컨테이너 백업/복구의 명령은 다음과 같다.

// gitlab 서버 데이터 백업 명령어
docker container exec -t <컨테이너 이름> gitlab-backup create

// gitlab 서버 데이터 복구 명령어
docker exec -it <컨테이너 이름> gitlab-backup restore

 

Comments