Custom executor에서 libvirt 사용하기
libvirt를 사용하여 Custom executor 드라이버로 각 작업마다 새 디스크와 VM을 생성하고 삭제하는 방법을 설명합니다.
libvirt 를 사용하면 Custom executor 드라이버가 실행하는 모든 작업에 대해 새 디스크와 VM을 생성하고, 작업 완료 후 디스크와 VM을 삭제합니다. 이 문서는 libvirt 설정 방법은 다루지 않습니다. 해당 내용은 범위를 벗어나기 때문입니다. 다만, 이 드라이버는 GCP Nested Virtualization 을 사용하여 테스트되었으며, 여기에는 브리지 네트워킹이 포함된 libvirt 설정 방법 에 대한 세부 정보도 포함되어 있습니다. 이 예제는 libvirt 설치 시 제공되는 default 네트워크를 사용하므로 해당 네트워크가 실행 중인지 확인하세요. 이 드라이버는 각 VM이 고유한 IP 주소를 가져야 GitLab Runner가 SSH로 접속하여 명령을 실행할 수 있으므로 브리지 네트워킹이 필요합니다. SSH 키는 다음 명령어 를 사용하여 생성할 수 있습니다. 매 빌드마다 의존성을 다운로드하지 않기 위해 기본 디스크 VM 이미지를 생성합니다. 다음 예제에서는 virt-builder 를 사용하여 디스크 VM 이미지를 생성합니다. virt-builder debian-12 \ --size 8G \ --output /var/lib/libvirt/images/gitlab-runner-base.qcow2 \ --format qcow2 \ --hostname gitlab-runner-bookworm \ --network \ --install curl \ --run-command 'curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | bash' \ --run-command 'curl -s "https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh" | bash' \ --run-command 'useradd -m -p "" gitlab-runner -s /bin/bash' \ --install gitlab-runner,git,git-lfs,openssh-server \ --run-command "git lfs install --skip-repo" \ --ssh-inject gitlab-runner:file:/root/.ssh/id_rsa.pub \ --run-command "echo 'gitlab-runner ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers" \ --run-command "sed -E 's/GRUB_CMDLINE_LINUX=\"\"/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/' -i /etc/default/grub" \ --run-command "grub-mkconfig -o /boot/grub/grub.cfg" \ --run-command "echo 'auto eth0' >> /etc/network/interfaces" \ --run-command "e
