인프라

docker gitlab / gitlab-runner 설치

소행성왕자 2023. 2. 8. 10:26

목적

gitlab 설치

docker pull gitlab/gitlab-ce
docker run --detach \
--hostname 220.72.212.xxx \
--publish 4443:443 --publish 80:80 --publish 2222:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest



gitlab-runner CI/CD 작동중 220.72.212.247:8080 오류가 발생하여 80 포트 사용

root 비번

cd /srv/gitlab/config

cat initial_root_password

웹브라우져에서 gitlab 접속 
http://220.72.212.xxx/
gitlab 접속 안될때 5분후에 다시 접속 (좀 느림)

https://docs.gitlab.com/ee/install/docker.html

gitlab-runner 설치

docker pull gitlab/gitlab-runner:latest

컨테이너 실행

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 \
  --network apm_each_apm_net \
  gitlab/gitlab-runner:latest
  
  
  
  -network apm_each_apm_net  docker-compose 와 같은 네트워트 사용
  
 네트워크 조회
 docker network ls

컨테이너 접속

docker exec -it gitlab-runner bash

gitlab-runner register

gitlab-runner register
.. 배포 설정

 

gitlab Setting > CI/CD 설정

vi .gitlab-ci.yml

deploy-to-server:
   stage: deploy
   only:
     - main
   script:
     - echo 'hello world!'
     - cd /home/gitlab-runner
     - touch gen_empty_file

   tags:
     - deploy

 

gitlab-runner 서비스 시작

백그라운드 시작

gitlab-runner start

현재세션 시작

gitlab-runner run

 

Listing Runners

To list the configured runners, use the list command.

bash
docker exec -it gitlab-runner gitlab-runner list

Typical output might look something like this:

[cofor@localhost docker]$ docker exec -it gitlab-runner gitlab-runner list
Runtime platform                                 arch=amd64 os=linux pid=231 revision=f86890c6 version=15.8.1
Listing configured runners                  ConfigFile=/etc/gitlab-runner/config.toml
45b291b659e2                                  Executor=shell Token=F2uszkafiS14kYUY6RZV URL=http://220.72.212.xxx/

 

Stopping, Starting and Restarting the Runners

You can stop the runners using the stop command.

bash
docker exec -it gitlab-runner gitlab-runner stop

And start them using the start command.

bash
docker exec -it gitlab-runner gitlab-runner start

You can perform both actions in sequence with the restart command.

bash
docker exec -it gitlab-runner gitlab-runner restart

https://datawookie.dev/blog/2021/03/install-gitlab-runner-with-docker/

https://docs.gitlab.com/runner/install/docker.html

 

Run GitLab Runner in a container | GitLab

Documentation for GitLab Community Edition, GitLab Enterprise Edition, Omnibus GitLab, and GitLab Runner.

docs.gitlab.com