728x90
GitLab Runner 설치 및 등록하기
GitLab Runner 설치하기(컨테이너)
- docker 명령어
docker run -d \
--name gitlab-runner \
--restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
- docker compose 명령어
vim docker-compose.yml
version: '3.8'
services:
gitlab-runner:
image: gitlab/gitlab-runner:latest
restart: always
container_name: gitlab-runner
hostname: gitlab-runner
volumes:
- /usr/share/zoneinfo/Asia/Seoul:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock
- ./gitlab-runner/config:/etc/gitlab-runner
networks:
- gitlab_net
networks:
gitlab_net:
name: gitlab_net
GitLab Runner 등록하기
GitLab Runner를 GitLab에 등록
GitLab에서 관리자로 로그인한 후에 Settings > CI/CD > Runners
GitLab gitlab-runner 정보 확인하기
- url : https://gitlab.example.com:8443
- token : glrt-sSn3asdLcCt-cuzocNk_
GitLab Runner 설정
- 대화형 프로세스 시작
docker compose exec -it gitlab-runner bash
gitlab-runner register
$ gitlab-runner register
Runtime platform arch=amd64 os=linux pid=41 revision=81ab07f6 version=16.10.0
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.example.com:8443
Enter the registration token:
glrt-sSn3asdLcCt-cuzocNk_
Verifying runner... is valid runner=sSn3asdLc
Enter a name for the runner. This is stored only in the local config.toml file:
[gitlab-runner]:
Enter an executor: kubernetes, docker-autoscaler, custom, docker, docker-windows, docker+machine, instance, shell, ssh, parallels, virtualbox:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"
- 비대화형 프로세스 시작
docker exec -it gitlab-runner gitlab-runner register \
--non-interactive \
--url "https://gitlab.example.com:8443/" \
--registration-token "YOUR_REGISTRATION_TOKEN" \
--executor "docker" \
--docker-image alpine:latest \
--description "Docker Runner" \
--tag-list "docker,linux,x86"
- config.toml 확인
cat /etc/gitlab-runner/config.toml
$ cat /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "gitlab-runner"
url = "https://gitlab.example.com:8443"
id = 2
token = "glrt-sSn3asdLcCt-cuzocNk_"
token_obtained_at = 2024-03-29T03:15:25Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "shell"
[runners.cache]
MaxUploadedArchiveSize = 0
GitLab Runner 시작하기
gitlab-runner start
$ gitlab-runner start
Runtime platform arch=amd64 os=linux pid=69 revision=81ab07f6 version=16.10.0
GitLab Runner 정보 확인하기
gitlab-runner verify
$ gitlab-runner verify
Runtime platform arch=amd64 os=linux pid=102 revision=81ab07f6 version=16.10.0
Running in system-mode.
There might be a problem with your config based on jsonschema annotations in common/config.go (experimental feature):
jsonschema: '/runners/0/Monitoring' does not validate with https://gitlab.com/gitlab-org/gitlab-runner/common/config#/$ref/properties/runners/items/$ref/properties/Monitoring/$ref/type: expected object, but got null
Verifying runner... is valid runner=sSn3asdLc
GitLab gitlab-runner 목록
gitlab-runner list
.gitlab-ci.yml 파일 편집
stages:
- build
- test
- deploy
build-job:
stage: build
script:
- echo "안녕하세요, $GITLAB_USER_LOGIN님!"
- echo $(date '+%Y-%m-%d %H:%M:%S') > /tmp/build_$(date '+%Y%m%d_%H%M%S').txt
tags:
- shell
test-job1:
stage: test
script:
- echo "테스트 작업을 시작합니다."
- echo $(date '+%Y-%m-%d %H:%M:%S') > /tmp/test_$(date '+%Y%m%d_%H%M%S').txt
tags:
- shell
test-job2:
stage: test
script:
- echo "테스트 작업을 시작합니다. test-job1보다 시간이 더 소요될 것입니다."
- echo "test-job1보다 20초 더 오래 걸리는 작업을 수행합니다."
- echo $(date '+%Y-%m-%d %H:%M:%S') > /tmp/test_$(date '+%Y%m%d_%H%M%S').txt
- sleep 20
tags:
- shell
deploy-staging:
stage: deploy
script:
- echo "$CI_COMMIT_BRANCH 브랜치로부터 스테이징 환경으로 배포 작업을 수행합니다."
- echo $(date '+%Y-%m-%d %H:%M:%S') > /tmp/deploy_$(date '+%Y%m%d_%H%M%S').txt
only:
- main
tags:
- shell
deploy-production:
stage: deploy
script:
- echo "$CI_COMMIT_BRANCH 브랜치로부터 프로덕션 환경으로 수동 배포 작업을 수행합니다."
- echo $(date '+%Y-%m-%d %H:%M:%S') > /tmp/deploy_$(date '+%Y%m%d_%H%M%S').txt
when: manual
only:
- main
tags:
- shell
728x90
'리눅스' 카테고리의 다른 글
[draft] fping 명령어 (0) | 2024.04.25 |
---|---|
Git 경고 메시지 "LF will be replaced by CRLF the next time Git touches it" 해결 방법 (0) | 2024.04.01 |
GitLab을 Docker Compose를 사용하여 올리는 방법 (0) | 2024.03.28 |
우분투에서 Certbot을 사용하여 Let's Encrypt SSL 인증서를 생성하는 방법 (0) | 2024.03.28 |
Portainer를 설치하고 컨테이너를 관리하는 방법 (0) | 2024.03.27 |