Packer/Qemu in CI/CD


I am building Ubuntu Server images with packer and qemu.
Everything works fine when done in local: build is OK, I can mount and run the built image.

Next step was to automatize the build from a GitLab CI/CD.

I use the hashicorp/docker in which I added “qemu qemu-img qemu-system-x86_64”.
I exposed all ports range needed by packer (VNC + ssh).

When I run the CI/CD, packer is able to run the boot commands.

I have been able to redirect some logs from qemu by using “-serial stdio” and I’m sure that qemu is starting well and i can see the echo of boot command from grub shell prompt.

However, last command is a boot command that run the linux kernel.
After running this command, packer is stuck waiting for ssh and I have no more logs from qemu.
I already tried to increase the ssh timeout but still the same.

I suppose something goes wrong when starting kernel.
But how to debug when you dont have any clues as I’m not able to grab the kernel logs ?

Found why it was not working:
Qemu was using tcg rather than kvm because kvm was not available on CI/CD runner.

With tcg, build can take very long time.

If I increase the ssh timeout, connection is properly established after 3 hours.

So, the question is: how to enable kvm on my CICD environement (using AWS runners)…