GitLab cicd runner

2 minute read

DIND

ํ˜„์žฌ yml ํŒŒ์ผ ๊ธฐ์ค€์œผ๋กœ ์ œ์ผ ์œ„์— ์žˆ๋Š” image ๊ฐ€ ํ˜„์žฌ build๋  ์ด๋ฏธ์ง€์ด๋ฆ„์ž„

Pytorch Docker image alpine

Alpine Linux ์ด๋ฏธ์ง€ ์ด๊ธฐ ๋•Œ๋ฌธ์— apt-get ์ด ์•„๋‹ˆ๋ผ apt-get update ๋Œ€์‹  apk update
apt-get install ๋Œ€์‹  apk add pkgname ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

Gitlab Runner in Docker Container (Docker in Docker setting)

  1. Run gitlab runner inside Docker Container

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

make docker container for gitlab-runner

docker run ํ• ๋•Œ privileged args๋ฅผ ์ค˜์•ผ์ง€ ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋‚˜์ง€ ์•Š๋Š”๋‹ค.

๋˜ํ•œ config.toml ์•ˆ์—๋„ privileged๋„ true๋ฅผ ์ค˜์•ผ ํ•จ.

์—๋Ÿฌ๋ฉ”์‹œ์ง€: docker: Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•:

docker run -d --name gitlab-runner --privileged \     
     -v /home/yilgukseo/DL/Vision/FridaGAN/gitlab-runner:/etc/gitlab-runner \
     -v /var/run/docker.sock:/var/run/docker.sock \
     gitlab/gitlab-runner:latest 

toml ํŒŒ์ผ์ด ์•„๋ž˜ ์ฒ˜๋Ÿผ๋˜์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— mount๋œ toml ํŒŒ์ผ์—์„œ volumes์— ๊ธฐ์กด์— ์—†๋˜ "/certs/client" ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

[[runners]]
  url = "https://gitlab.com/"
  token = TOKEN
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:19.03.12"
    privileged = true
    disable_cache = false
    volumes = ["/certs/client", "/cache"]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#docker-in-docker-with-tls-enabled

  1. register gitlab-runner inside docker container gitlab-runner register

์œ„ ๋ช…๋ น์–ด๋กœ gitlab-runner๋ฅผ ๋“ฑ๋กํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์„ ๊ฑฐ์นœ๋‹ค.

  • Enter the GitLab instance URL (for example, https://gitlab.com/):
    • https://gitlab.com/
  • Enter the registration token:
    • your token from settings/cicd/runners
  • Enter a description for the runner:
    • your desc
  • Enter tags for the runner (comma-separated):
    • your tag
  • Enter an executor: ssh, docker-ssh+machine, kubernetes, docker, parallels, shell, virtualbox, docker+machine, custom, docker-ssh:
    • docker
  • Enter the default Docker image (for example, ruby:2.6):
    • docker:tagsyouwant
  • message Enter the GitLab instance URL (for example, https://gitlab.com/): https://gitlab.com/ Enter the registration token: {token} Enter a description for the runner: [dffbcd38570c]: jason3 Enter tags for the runner (comma-separated): ceta3 Registering runnerโ€ฆ succeeded runner=abcdefg Enter an executor: ssh, docker-ssh+machine, kubernetes, docker, parallels, shell, virtualbox, docker+machine, custom, docker-ssh: docker Enter the default Docker image (for example, ruby:2.6): docker:latest Runner registered successfully. Feel free to start it, but if itโ€™s running already the config should be automatically reloaded!

์ด ์ƒํƒœ๊ฐ€ ๋˜๊ณ ๋‚˜์„œ web์— ๊ฐ€์„œ settings/cicd/runners ์— ๊ฐ€๋ณด๋ฉด ์ดˆ๋ก๋ถˆ์ด ์ผœ์ ธ ์žˆ์–ด์•ผ ํ•œ๋‹ค.
๋‹ค๋งŒ ์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— ์ข€ ๊ธฐ๋‹ค๋ฆฌ๋ฉด ๋ถˆ์ด ์ผœ์ ธ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

Docker in Docker network

๊ธฐ์กด์˜ unittest ๊ตฌ์„ฑ๋ฐฉ์‹ local ์—์„œ ์ง„ํ–‰ํ•˜๋Š” ๋ฐฉ์‹์ด์–ด์„œ Docker in Docker (a.k.a. DinD) ํ™˜๊ฒฝ์ด ์•„๋‹ˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ปจํ…Œ์ด๋„ˆ๊ฐ„ ์ ‘์†์ด ๊ฐ€๋Šฅํ–ˆ๋‹ค.
ํ•˜์ง€๋งŒ ํ˜„์žฌ๋Š” DinD ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ˜„์žฌ ๊นŒ์ง€ ์•Œ์•„๋ณธ ๋ฐ”๋กœ๋Š” ๋„์ปค ๋„คํŠธ์›Œํฌ๋ฅผ gitlab-runner ๋„์ปค๋‚ด๋ถ€์—์„œ ๊ตฌ์„ฑํ•ด์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ณจ์น˜๊ฐ€

Docker image ๋งจ๋’ค args

๊ธฐ์กด parse_args๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•จ.

docker run --net test_network --rm -e RABBITMQ_ENABLED -e RABBITMQ_HOST -e REDIS_ENABLED -e REDIS_HOST --name $CI_TEST_CONTAINER_NAME $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG --debug --asset-url $CI_TEST_ASSET_URL_BASE --assets $CI_TEST_ASSET_0 --assets $CI_TEST_ASSET_1 --assets $CI_TEST_ASSET_2

  • ENTRYPOINT์•ˆ์— bracket์œผ๋กœ ๊ฐ์‹ธ์ค˜์•ผํ•˜๊ณ  โ€œโ€œ์„ ์‚ฌ์šฉํ•ด์•ผ args๊ฐ€ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•จ.

Appendix

git mv

git mv oldname newname

is just shorthand for:

mv oldname newname
git add newname
git rm oldname

ref: https://stackoverflow.com/questions/1094269/whats-the-purpose-of-git-mv

Leave a comment