Skip to content
Snippets Groups Projects
Verified Commit 001300ff authored by Kristian Klausen's avatar Kristian Klausen :tada:
Browse files

gitlab_runner: Fix broken "Running on ..." in the libvirt-executor

The prepare stage runs "echo "Running on $(hostname)...""[1], resulting
in "bash: line 7: hostname: command not found" and it outputting
"Running on ..." as the hostname command is provided by inetutils, which
is not installed.

Fix it by "monkey patching" it to use "hostnamectl hostname" and inject
the hostname with SMBIOS[2][3]. Injecting creds with SMBIOS may also be
useful in the future, e.g. for injecting an ephemeral SSH public key.

[1] https://gitlab.com/gitlab-org/gitlab-runner/-/blob/v17.5.2/shells/bash.go?ref_type=tags#L452-L456
[2] https://systemd.io/CREDENTIALS/
[3] https://github.com/systemd/systemd/pull/30814
parent 2a1a488a
No related branches found
No related tags found
1 merge request!881libvirt-executor improvements
......@@ -69,7 +69,13 @@ prepare() {
run() {
local ip
ip="$(vm_ip "$(vm_name)")"
ssh "${ip}" bash < "${1}" || exit "${BUILD_FAILURE_EXIT_CODE:-1}"
if [[ ${2} == prepare_script ]]; then
# TODO: Get this fixed upstream or perhaps we should just install inetutils?
# https://gitlab.com/gitlab-org/gitlab-runner/-/blob/v17.5.2/shells/bash.go?ref_type=tags#L452-L456
ssh "${ip}" bash < <(sed 's/$(hostname)/$(hostnamectl hostname)/' "${1}") || exit "${BUILD_FAILURE_EXIT_CODE:-1}"
else
ssh "${ip}" bash < "${1}" || exit "${BUILD_FAILURE_EXIT_CODE:-1}"
fi
}
# https://docs.gitlab.com/runner/executors/custom.html#cleanup
......
......@@ -43,7 +43,9 @@ sed 's/^\(GRUB_CMDLINE_LINUX=".*\)"$/\1 lockdown=confidentiality"/' -i mnt/etc/d
arch-chroot mnt /usr/bin/grub-mkconfig -o /boot/grub/grub.cfg
install -d -m0700 mnt/root/.ssh
install -m0600 /etc/libvirt-executor/id_ed25519.pub mnt/root/.ssh/authorized_keys
rm -f mnt/etc/machine-id
# We want to use the transient hostname
# https://github.com/systemd/systemd/pull/30814
rm -f mnt/etc/machine-id mnt/etc/hostname
cp -a mnt/boot/{initramfs-linux-fallback.img,initramfs-linux.img}
......
......@@ -2,8 +2,14 @@
<name>$vm_name</name>
<memory unit='MiB'>{{ gitlab_runner_libvirt_vm_memory }}</memory>
<vcpu>4</vcpu>
<sysinfo type='smbios'>
<oemStrings>
<entry>io.systemd.credential:system.hostname=$vm_name</entry>
</oemStrings>
</sysinfo>
<os>
<type arch='x86_64' machine='q35'>hvm</type>
<smbios mode='sysinfo'/>
</os>
<features>
<acpi/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment