Skip to content
Snippets Groups Projects

gitlab_runner: Add VM based executor (libvirt-executor)

Merged Kristian Klausen requested to merge klausenbusk/infrastructure:custom-executor into master
1 file
+ 7
5
Compare changes
  • Side-by-side
  • Inline
@@ -56,16 +56,18 @@ wait_for_vm_shutdown() {
# Create a updated VM image with the required tools
create_vm_template() {
# Download from arch-boxes when
# https://gitlab.archlinux.org/archlinux/arch-boxes/-/merge_requests/172 is in
# FIXME: Download from arch-boxes when [1] is in
# [1] https://gitlab.archlinux.org/archlinux/arch-boxes/-/merge_requests/172
local vm_name="libvirt_executor_vm_template_$(date +%s)_tmp"
cp Arch-Linux-x86_64-cloudimg-20210815.31636.qcow2 "${LIBVIRT_DEFAULT_POOL_PATH}/${vm_name}.qcow2"
qemu-img resize "${LIBVIRT_DEFAULT_POOL_PATH}/${vm_name}.qcow2" 10G
local image_path="${LIBVIRT_DEFAULT_POOL_PATH}/${vm_name}.qcow2"
trap "rm -f ${image_path}" EXIT
curl -sSf "${MIRROR}/images/v20210815.31636/Arch-Linux-x86_64-cloudimg-20210815.31636.qcow2" --output "${image_path}"
qemu-img resize "${image_path}" 10G
# TODO remove exit 1 andre steder
trap "virsh destroy ${vm_name}; virsh undefine ${vm_name} --remove-all-storage; exit 1" EXIT
virt-install --name "${vm_name}" \
--cloud-init user-data=$PWD/user-data \
--disk path="${LIBVIRT_DEFAULT_POOL_PATH}/${vm_name}.qcow2",device=disk \
--disk path="${image_path}",device=disk \
--os-type Linux \
--os-variant archlinux \
--network network=default,filterref.filter=clean-traffic \
Loading