Skip to content

Add libvirt backend - #6985

Open
hasufell wants to merge 27 commits into
woodpecker-ci:mainfrom
hasufell:libvirt
Open

hasufell wants to merge 27 commits into
woodpecker-ci:mainfrom
hasufell:libvirt

Conversation

@hasufell

@hasufell hasufell commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2302

Depends on:

Relevant libvirt tickets (mostly affecting bhyve backend):

Notes on AI use:

  • AI was not used for code generation

TODO:

  • documentation
  • test multiple VM workflow on linux
  • fix SIGTERM propagation

@hasufell
hasufell marked this pull request as draft August 10, 2026 06:29
@hasufell

hasufell commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor Author

There's several caveats:

How to connect to the machine

There's at least 3 methods:

  1. connect to a serial console: awful, because you're sending bytes to a console, not actually executing a command... so you have to deal with escaping hell
  2. by talking to a qemu-guest agent running inside the VM: this limits us to qemu and is discouraged by libvirt upstream as a "backdoor"
  3. via ssh

I picked option 3... which means the user has to set up working ssh inside the VM. There's two ways to do the ssh connection: by inspecting a network interface inside the VM and getting the IP... or by using the libvirt NSS method, which sets up domain names equivalent to the VM name (more elegant)

The user also has to configure the following in sshd_config:

AcceptEnv *

Shared disk

If we want to execute multiple steps and retain the working directory/checkout, we need to have a disk that is shared across VMs. Unfortunately, mounting a host folder doesn't work consistently across platforms and hypervisors, so the best method is to require the user to provide a disk and a configuration.

However, the guest operating system needs to know how to mount the disk, so we also need to assign e.g. a serial number.

Windows prerequisites for mounting

To be able to mount the shared disk on windows, we need the following.

Disable UAC remote token filtering:

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" `
    -Name "LocalAccountTokenFilterPolicy" -Value 1 -PropertyType DWord -Force

Set your network to private:

Set-NetConnectionProfile -InterfaceIndex <index> -NetworkCategory Private

Start WinRM service:

winrm quickconfig

Ephemeral VMs

This supports fully ephemeral VMs: the disks of the "base VMs" are copied. For qemu disks, it is zero-cost copy thanks to qcow2. For raw disks we need to copy the whole file.

@hasufell

Copy link
Copy Markdown
Contributor Author

Example workflow:


when:
  - platform: freebsd/amd64
  - event: push
  - event: manual

skip_clone: true

steps:
 - name: build
   image: win10
   commands:
     - Write-Host "Hello, World!"
     - Write-Host "Hello, World2"
     - Set-Content -Path ".\hello.txt" -Value "hello"
     - Get-ChildItem
   backend_options:
     libvirt:
       ephemeral: true
       shared_disk: &shared_disk
         uuid: "BHYVE-ABCDEF-CAFE"
         disk_config: |
           <disk type='file'>
             <serial>BHYVE-ABCDEF-CAFE</serial>
             <driver name='file' type='raw'/>
             <source file='/var/lib/libvirt/images/win10-shared.img'/>
             <target dev='sdb' bus='sata'/>
           </disk>
       ssh_config:
         username: root
         password: root
         timeout: 2m
         hostname: win10
 - name: build
   image: win11
   commands:
     - Write-Host "Hello, World2!"
     - Get-Content -Path ".\hello.txt"
     - Get-ChildItem
   backend_options:
     libvirt:
       ephemeral: true
       shared_disk: *shared_disk
       ssh_config:
         username: root
         password: root
         timeout: 2m
         hostname: win11

@qwerty287 qwerty287 added feature add new functionality build CI pipeline related backend new backend and removed build CI pipeline related labels Aug 10, 2026
@qwerty287

Copy link
Copy Markdown
Contributor

Thanks!
Your two windows PRs will hopefully get reviewed soon, I cannot really help there as I never used woodpecker on windows.

Just a question towards this new backend: As there were quite some people asking for this, I think it's a good idea to get that into the core repo. However, I do not think any of us maintainers will use it, so we depend on contributions from libvirt users like you. This also means if other people open PRs for this backend we will ping you and ask to review - is that fine for you?

@hasufell

Copy link
Copy Markdown
Contributor Author

This also means if other people open PRs for this backend we will ping you and ask to review - is that fine for you?

Yes.

@hasufell
hasufell force-pushed the libvirt branch 2 times, most recently from fe597b4 to b1788a6 Compare August 10, 2026 13:23
Comment thread pipeline/backend/libvirt/libvirt.go Resolved
@6543

6543 commented Aug 24, 2026

Copy link
Copy Markdown
Member

your pull got conflicts - just merge main in :)

and https://ci.woodpecker-ci.org/repos/3780/pipeline/37299 ... still i know it is WIP ... just some notes i saw

@hasufell
hasufell marked this pull request as ready for review August 24, 2026 10:48
@hasufell

Copy link
Copy Markdown
Contributor Author

I think this is now ready for review... documentation is still missing, but the implementation now works.

I'm not sure how to assist reviewers here... it requires a lot of knowledge of:

  1. libvirt and its portability issues
  2. ssh and its portability issues
  3. windows and its quirks

If any decision/pattern feels odd, then please raise it, so I can explain and add an inline comment. It's also possible I forgot some of the decisions along the way when experimenting with different approaches. Most things that look weird are most likely there for portability reasons (e.g. AcceptEnv * in ssh not working reliably).

I tried to keep the changes to the other backends to a minimum, but the script generation did change.

@hasufell

Copy link
Copy Markdown
Contributor Author

Also, I rebased, so it's possible I messed something up.

Comment thread pipeline/backend/common/script_posix.go Resolved
@hasufell
hasufell force-pushed the libvirt branch 2 times, most recently from 23a9169 to ea4208e Compare August 25, 2026 06:27
@qwerty287

Copy link
Copy Markdown
Contributor

Thanks, is there a reason to downgrade so many dependencies?

@hasufell

Copy link
Copy Markdown
Contributor Author

Thanks, is there a reason to downgrade so many dependencies?

Not at all. That's probably just me struggling with go tooling. It's been 8 years since I did go.

@6543

6543 commented Nov 10, 2026

Copy link
Copy Markdown
Member
image

@woodpecker-bot

Copy link
Copy Markdown
Contributor

Surge PR preview deployment succeeded. View it at https://woodpecker-ci-woodpecker-pr-6985.surge.sh

Comment thread go.mod
github.com/google/go-github/v93 v93.0.0
github.com/hashicorp/go-hclog v1.6.3
github.com/hashicorp/go-plugin v1.8.0
github.com/jakobii/syncx v0.3.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well this repo is archived and migrated ...

Comment thread go.mod
codeberg.org/6543/go-yaml2json/v2 v2.0.0
codeberg.org/6543/xyaml/v2 v2.0.1
codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v4 v4.0.0
darvaza.org/x/sync v0.6.1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a second sync lib ... can we stay at one

@6543

6543 commented Nov 10, 2026

Copy link
Copy Markdown
Member

the "relevant libvirt tickets" are now all closed 🎉 ...

... I did not dig deep into the impl. jet just the buildsystem etc...

@6543

6543 commented Nov 12, 2026

Copy link
Copy Markdown
Member

@hasufell i have addressed the build issue ... can you look into the sync dependency issues...

Comment thread Makefile Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend new backend feature add new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants