From 42f67e3ba34b972e2bc771a5ef669bf0af17f462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Wed, 8 Jul 2020 08:49:40 +0200 Subject: [PATCH] Use CUSTOM_ENV_CI_JOB_IMAGE The CUSTOM_ENV_CI_JOB_IMAGE variable contains the value of the "image" key set for a given GitLab CI job. Use that instead of the job name for determining the QCOW2 image to use, so that defining GitLab CI jobs using the libvirt/QEMU custom executor becomes a bit more similar in spirit to defining jobs using the Docker executor. --- libvirt-qemu/README.md | 9 --------- libvirt-qemu/executor.sh | 17 ++--------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/libvirt-qemu/README.md b/libvirt-qemu/README.md index e42c26e..5f440a9 100644 --- a/libvirt-qemu/README.md +++ b/libvirt-qemu/README.md @@ -89,15 +89,6 @@ libvirt domains (over SSH). redirects COM1 to a file which can be inspected on the host in case of boot issues. -- [GitLab Runner Docker executor][3] uses the `image` keyword for - determining which Docker image to use. The contents of that keyword - are not exposed as an environment variable by the [GitLab Runner - Custom executor][4] and thus it cannot be used for determining the - operating system image to use. Instead, the latter is extracted from - the job name. The QCOW2 image file path is derived from the detected - operating system name and release (see the `do_prepare()` function in - `executor.sh` for hints on expected file naming). - ## QCOW2 Image Synchronization Whenever [GitLab Runner Docker executor][3] runs a GitLab CI job, it diff --git a/libvirt-qemu/executor.sh b/libvirt-qemu/executor.sh index 0b1a823..ed5688a 100755 --- a/libvirt-qemu/executor.sh +++ b/libvirt-qemu/executor.sh @@ -18,10 +18,6 @@ CONFIG_PATH="/etc/gitlab-runner/executor-libvirt-qemu.conf" # shellcheck source=executor.conf.sample . "${CONFIG_PATH}" -CENTOS_RELEASE="$(expr "${CUSTOM_ENV_CI_JOB_NAME}" : ".*:el\([6-8]\)\(:\|$\)" || :)" -OPENBSD_RELEASE="$(expr "${CUSTOM_ENV_CI_JOB_NAME}" : ".*:openbsd\([0-9][0-9.]*\)\(:\|$\)" || :)" -FREEBSD_RELEASE="$(expr "${CUSTOM_ENV_CI_JOB_NAME}" : ".*:freebsd\([0-9][0-9.]*\)\(:\|$\)" || :)" - BASE_IMAGE_DIR="${BASE_DIR}/qcow2" RUNNER_NAME="runner-${CUSTOM_ENV_CI_JOB_ID}" DOMAIN_DEFINITION_PATH="${BASE_DIR}/${RUNNER_NAME}.xml" @@ -50,18 +46,9 @@ do_config() { } do_prepare() { - if [ -n "${CENTOS_RELEASE}" ]; then - BASE_IMAGE_PATH="$(readlink -f "${BASE_IMAGE_DIR}/centos-${CENTOS_RELEASE}-x86_64")" - elif [ -n "${FREEBSD_RELEASE}" ]; then - BASE_IMAGE_PATH="$(readlink -f "${BASE_IMAGE_DIR}/freebsd-${FREEBSD_RELEASE}-x86_64")" - elif [ -n "${OPENBSD_RELEASE}" ]; then - BASE_IMAGE_PATH="$(readlink -f "${BASE_IMAGE_DIR}/openbsd-${OPENBSD_RELEASE}-x86_64")" - else - fatal_error "Unable to extract OS to use from job name (${CUSTOM_ENV_CI_JOB_NAME})" - fi - + BASE_IMAGE_PATH="$(readlink -f "${BASE_IMAGE_DIR}/${CUSTOM_ENV_CI_JOB_IMAGE}")" if [ ! -f "${BASE_IMAGE_PATH}" ]; then - fatal_error "Base image ${BASE_IMAGE_PATH} does not exist" + fatal_error "Base image ${CUSTOM_ENV_CI_JOB_IMAGE} does not exist" fi cp "${DOMAIN_DEFINITION_TEMPLATE_PATH}" "${DOMAIN_DEFINITION_PATH}" -- GitLab