로컬 머신에 GitLab Runner를 도입하여 GitLab에서 CI/CD하는 방법
소개
하고 싶은 것은 제목대로.
공식 문서 를 보면 알겠다고 말하고 싶지만, 조금 고전했기 때문에 메모.
실은 로컬 머신이 아니라 클라우드상의 가장 기계 등에 넣는 경우도 이 방법으로 갈 수 있지만, 자신이 로컬 머신에 넣은 것과 로컬 머신에 넣는 패턴이 많다고 생각했기 때문에 이 타이틀로 했다.
환경
준비
1. Docker 환경 준비
OS에 맞게 Docker for Mac, Docker for Windows 등 설치한다.
여기는 여러가지 자료가 인터넷에 떨어지고 있기 때문에 구구를 원한다.
참고
* Docker를 Mac에 설치
* Docker for Windows 설치
* Install Docker Engine on Ubuntu
2. GitLab Runner 설정
공식 문서에는 로컬 파일 시스템을 마운트하는 방법 과 Docker Volume을 사용하는 방법 의 2개가 있지만, 후자를 사용하기로 했다.
이하 로컬 머신에서 커맨드를 실행한다.
2-1. config에 대한 볼륨을 만듭니다.
docker volume create gitlab-runner-config
2-2. GitLab Runner의 컨테이너 시작
docker run -d --name gitlab-runner --restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v gitlab-runner-config:/etc/gitlab-runner \
gitlab/gitlab-runner:latest
2-3. 시작한 컨테이너 등록
이것을 각 GitLab 프로젝트마다 실시한다.
2-3-1. 이것을 실행
docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:latest register
2-3-2. 사용 중인 GitLab의 URL 입력
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
2-3-3. GitLab 프로젝트의 토큰 입력
토큰은 GitLab 프로젝트
Settings->CI/CD->Runners
에서 확인할 수 있다.Settings
는 강한 권한이 없으면 열람할 수 없기 때문에 주의.Please enter the gitlab-ci token for this runner
xxx
2-3-4. Runner 설명 작성
Please enter the gitlab-ci description for this runner
[hostname] my-runner
2-3-5. Runner에 연결할 태그를 쉼표로 구분하여 지정
Please enter the gitlab-ci tags for this runner (comma separated):
my-tag,another-tag
2-3-6. Runner Executer 지정
이번에는
docker
를 선택했다.Docker 이외에서도 실행할 수 있는 것 같다.
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
docker
2-3-7. 기본 이미지 지정
이번에는
alpine:latest
Please enter the Docker image (eg. ruby:2.6):
alpine:latest
2-3-8. Runner가 등록되었는지 확인한다(2020/08/21 11:25 갱신)
GitLab 프로젝트
Settings->CI/CD->Runners->Runners activated for this project
확인
Runner 상세 페이지로 이동하여 IP 주소가 로컬 컴퓨터의 IP 주소와 동일한지 확인합니다.

3. .gitlab-ci.yml 설정
적절한 분기에
.gitlab-ci.yml
를 만듭니다.쓰는 방법은 공식 문서 이나 구글 선생님을 참조해 주었으면 한다.
gitlab-ci.yml
image: python:latest
stages:
- test
unittest:
stage: test
script:
- echo "hoge"
4. 적당히 커밋을 푸시한다
푸시한 커밋을 보면 CI 결과가 표시된다.

결론
GitLab Runner를 로컬 컴퓨터에서 실행할 수있었습니다.
다음은 AWS의 액세스 키를 GitLab Runner에서 사용하는 방법이나 쓰고 싶다.
참고
Reference
이 문제에 관하여(로컬 머신에 GitLab Runner를 도입하여 GitLab에서 CI/CD하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kabik/items/10d152e0183a1cf55d23텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)