Software

We Just Wanted to Build Some Software

How a workstation-bound CI runner evolved into an autonomous, resource-efficient software delivery platform — with KVM, Forgejo, Docker, a rather particular firewall, and the occasional misplaced backslash.

In August, I wrote an article called We Just Wanted to Deploy a PHP Website.

What started as a relatively modest modernization of our deployment process at Neoground turned into a small software supply chain. We separated application builds from production, introduced standardized Docker-based build environments, packaged applications into verified release artifacts, and integrated the whole process with our existing infrastructure management tooling.

It worked beautifully.

There was, however, one rather interesting architectural compromise: our CI infrastructure lived on my Windows workstation, inside a Debian VM running in VMware Workstation.

At the time, I had deliberately decided against running a KVM-based virtual machine on my Linux server. The additional networking and security considerations seemed disproportionate to the actual workload.

Nearly four months later, I spent an evening implementing precisely the architecture I had previously rejected.

And I am rather pleased with the result.

The original decision was not wrong

One of the more fascinating aspects of engineering is that a perfectly reasonable decision can become an inconvenient one without anything fundamentally breaking.

The original CI machine was straightforward. Start VMware, boot Debian, let the Forgejo runner connect, execute the queued workflows, and shut it down when finished.

For occasional website deployments, that was entirely adequate.

But our use of CI grew. More projects acquired their own workflows. Desktop applications started producing installers automatically. Our PHP build environments evolved. Artifact-based deployment became increasingly attractive for applications running on different machines.

The workstation-bound nature of the runner gradually became an unnecessary dependency.

There were also some less elegant operational details. Updating the guest, maintaining Docker, rebuilding our build environments and dealing with accumulated storage all required some degree of manual intervention.

At one point, the Debian guest reported approximately 12 GB of filesystem usage, while its collection of VMDK files occupied 33 GB on my workstation.

Apparently, deleting data and actually getting one's storage back are two rather different concepts in virtualization.

Nothing was particularly broken. But the infrastructure was no longer quite as pleasant as the software delivery process it supported.

There was already a perfectly capable server

My main Linux server runs continuously anyway.

It hosts a fairly diverse collection of important services: application runtimes, databases, file storage, development environments, automation systems, monitoring, weather station infrastructure, media services and various other things accumulated over years of engineering and curiosity.

It also has spare computing capacity.

Our CI workload is not particularly demanding in aggregate. We do not execute dozens of parallel builds every hour. There might be a handful of builds throughout the day, followed by hours of inactivity.

Renting another VPS would certainly work. But dedicating another permanently running machine somewhere in a data center to a workload that could easily fit within existing resources seemed somewhat redundant.

The more interesting question was whether I could make CI coexist with the existing infrastructure without compromising its security, reliability or resource availability.

The answer was, unsurprisingly, virtualization.

The answer to making that virtualization pleasant to operate was considerably more interesting.

A small, disposable CI appliance

The new infrastructure is based entirely on the existing Debian 13 server and its native virtualization capabilities.

The resulting architecture looks approximately like this:

Physical Linux server
│
├── Existing infrastructure and applications
│
└── QEMU / KVM / libvirt
    │
    └── Dedicated CI virtual machine
        │
        ├── Debian 13
        ├── Forgejo runner
        ├── Docker Engine
        │   ├── PHP 8.5 build environment
        │   ├── PHP 8.6 build environment
        │   ├── Electron build environment
        │   └── Temporary job and service containers
        │
        └── Automated maintenance

The entire virtual machine is provisioned through Ansible.

Starting with an official Debian cloud image, the role creates the writable QCOW2 disk, configures the virtual network, installs the firewall policy, generates the cloud-init configuration, creates the VM and waits for it to become accessible.

Ansible then connects to the guest and installs the actual CI infrastructure.

There is no traditional operating system installation. No ISO to boot, no installer to navigate, no manually configured network interface.

Debian is already installed in the cloud image. Cloud-init handles its individual configuration, and Ansible handles everything that turns a generic Debian machine into our CI appliance.

The distinction is quite elegant:

  • Libvirt defines the virtual hardware.
  • Cloud-init establishes the initial operating system configuration.
  • Ansible establishes the desired operational state.
  • Forgejo provides the actual workload.

The machine itself has become replaceable.

If I want to change the configuration, I change the infrastructure repository. If I want to recreate the machine entirely, I explicitly request that through Ansible.

There is very little reason to treat the VM as a particularly valuable object in its own right.

CI is still arbitrary code execution

One of the architectural requirements from August remained unchanged.

A CI runner should not live within the same trust boundary as important production infrastructure.

A build job might appear innocent enough. It checks out a repository, installs some dependencies, compiles a few things and produces a package.

But underneath that pleasant abstraction, it executes arbitrary code.

Composer packages can execute scripts. JavaScript dependencies can execute scripts. Third-party actions execute code. Build tools execute code. A sufficiently unfortunate dependency compromise can transform an otherwise ordinary build into a rather different workload.

And then there is Docker.

Access to the Docker socket is effectively administrative access to the machine running the Docker daemon. That is particularly relevant to our setup because we use CI itself to rebuild and maintain our Docker-based CI environments.

I am comfortable granting that level of authority within a dedicated, replaceable CI machine.

I am considerably less comfortable granting it on the server that hosts important applications, databases, files and various other parts of my digital existence.

The VM therefore has its own dedicated virtual network, with NAT provided by libvirt and additional restrictions enforced through nftables on the hypervisor.

The intended network policy is relatively simple:

Route Rule
CI → Public internet Allowed
CI → Private networks Blocked
CI → Hypervisor services Blocked by default
Host → CI administration Allowed
Unsolicited inbound traffic Blocked

The guest can use the necessary DHCP and DNS services, communicate with Forgejo, retrieve dependencies, and transfer release artifacts to authorized external destinations.

It cannot simply start exploring the surrounding private infrastructure.

Importantly, these restrictions exist outside the virtual machine. Obtaining administrative privileges inside the guest does not automatically grant the ability to remove the hypervisor's firewall rules.

This is not a perfect sandbox. A compromised runner could potentially poison subsequent builds, modify local build environments or abuse credentials available to it. Recreating the VM would remove its compromised local state, but would not magically invalidate previously published artifacts or exposed credentials.

Ephemeral runners, more narrowly scoped credentials and signed artifacts would provide further protection.

For our current scale and predominantly trusted repositories, however, the dedicated VM provides a reasonable and proportionate security boundary.

Naturally, the machine refused to boot

Infrastructure automation is particularly pleasant once it works.

Getting there occasionally provides a reminder of how many independent layers are involved in apparently simple operations.

The first attempt failed because the permissions on the directory containing the virtual disk were a little too restrictive. Root could access everything. The unprivileged QEMU process could not traverse the directory.

A reasonable security precaution, implemented slightly too enthusiastically.

After fixing that, the VM started. Or rather, it spent an impressive amount of CPU time continuously announcing:

Booting Debian GNU/Linux

It turned out that the Debian 13 cloud image could encounter a GRUB-related boot problem with the headless virtual hardware configuration.

Changing the virtual console to VirtIO resolved it.

--graphics none
--console pty,target_type=virtio
--noautoconsole

Debian booted. CPU usage dropped. The login prompt appeared.

SSH still did not work.

That one was our own firewall. We had blocked new connections from the guest to the hypervisor, which was intentional, but also forgotten to permit replies to connections initiated by the hypervisor.

A small connection tracking exception fixed that.

iifname "virbr-ci" ct state established,related accept

Internet access required another look at the forwarding rules. Eventually, simplifying the restrictions restored connectivity while retaining the intended isolation.

And after deliberately recreating the machine, Ansible refused to establish its SSH connection because the new guest understandably had a different host key.

One dd in Vim later, provisioning continued.

The permanent solution, of course, was to make Ansible remove the obsolete host key when a recreation is explicitly requested, rather than disabling SSH host verification.

Each of these little problems became another improvement to the infrastructure definition.

That is one of the particularly satisfying properties of infrastructure as code. Troubleshooting does not merely repair the current machine. Ideally, it improves every future incarnation of that machine as well.

A software factory that maintains its own tools

The CI virtual machine is only the execution infrastructure.

The actual build environments are Docker images maintained in a dedicated repository.

We currently have three principal environments:

Image Purpose
neoground/ci-php85 Charm and modern PHP applications
neoground/ci-php86 PHP 8.6 applications and compatibility testing
neoground/ci-electron Desktop applications and cross-platform packaging

All three use Debian 13 as their foundation.

The PHP environments contain PHP, Composer, Node.js 26 LTS, Yarn 4, Corepack, PhpRedis, Valkey tooling and the usual collection of utilities needed to build, validate, package and transfer applications.

The Electron environment includes the modern JavaScript toolchain, Wine and the additional tooling necessary to generate desktop application packages for multiple operating systems.

Database servers and other runtime dependencies are deliberately not part of the build environments. If a project needs MariaDB, PostgreSQL or Valkey for integration tests, the workflow can declare the appropriate service containers.

The image provides the tools. The repository defines the work.

There is another rather pleasant detail: the build environments are maintained through CI itself.

Edit Dockerfile
      ↓
Push CI images repository
      ↓
Forgejo workflow
      ↓
Docker daemon inside CI VM
      ↓
Rebuild managed images
      ↓
Retire obsolete images
      ↓
Remove unused build cache

The deployment script discovers the image definitions, validates their names, builds each image and retires managed images whose definitions no longer exist.

It does not indiscriminately delete everything it finds in Docker. Managed images are explicitly labelled, and obsolete definitions are only retired after the builds succeed.

The entire toolchain can consequently be modernized in one place.

Updating PHP, Node.js, Yarn or a common build utility does not require visiting every individual application repository.

During this migration, we also moved PHP extension installation from PECL to PIE, following the changes in the PHP 8.6 image. That modernizes both PHP environments and keeps their Dockerfiles structurally similar.

Corepack is explicitly installed rather than relying on its former inclusion with Node.js. Yarn remains independently versioned.

A fairly contemporary software toolchain, maintained through a surprisingly small collection of Dockerfiles.

Incidentally, after resolving all the virtualization, networking and provisioning issues, the Electron image failed to build because of a single trailing backslash in a Dockerfile.

The syntax highlighting had even looked suspicious beforehand. I had attributed that to my AstroNvim configuration.

Apparently, the editor was right.

The problem with idle infrastructure

Getting the VM to run was only half the objective.

I also wanted it to have as little impact as reasonably possible when it was not running builds.

An intermittently busy CI runner has somewhat different resource requirements from a continuously busy application server.

It needs CPU, memory and storage while a build is running. Between jobs, retaining substantial resources merely because they might eventually be useful again is considerably less attractive.

Fortunately, modern Linux virtualization provides most of the mechanisms needed to address this.

Storage that actually shrinks again

The guest uses a dynamically allocated QCOW2 disk with VirtIO storage and discard support:

format=qcow2,discard=unmap,bus=virtio

Debian's periodic fstrim operation can report unused filesystem blocks through the virtual storage device.

QEMU can subsequently release their physical backing on the hypervisor, assuming the underlying storage supports the necessary operations.

This is particularly valuable for Docker workloads.

Building container images involves a rather impressive amount of writing, unpacking, compiling, copying and deleting data. The live filesystem usage can be relatively modest while the cumulative storage churn is enormous.

Without a working reclamation mechanism, a dynamically allocated virtual disk tends to remember the busiest moments of its existence.

Our Docker image deployment process therefore ends with:

docker image prune -f
docker builder prune -af

There is no need to retain BuildKit caches indefinitely.

The CI images themselves are retained. The ordinary workflows continue to use them. Only the unused cache involved in manufacturing those images is discarded.

Since we rebuild the environments relatively infrequently, the performance benefit of preserving several gigabytes of intermediate layers between deployments is negligible.

The VM also performs daily Docker housekeeping, APT cache cleanup and periodic filesystem trimming. Docker logs and the system journal have bounded retention policies.

The intention is that the virtual disk should grow because the infrastructure genuinely needs more storage, not merely because time has passed.

Memory that returns to the host

Memory was a slightly more interesting subject.

The VM has 4 GiB available for builds, which is sufficient for our current workload.

However, after several Docker builds, QEMU occupied almost the entire allocation on the hypervisor, despite Debian reporting only a few hundred megabytes of active memory usage.

Linux was doing what Linux normally does: keeping useful filesystem data in memory and maintaining a healthy amount of available RAM.

From the guest's perspective, everything was perfectly reasonable.

From the hypervisor's perspective, a largely idle CI appliance was occupying several gigabytes of memory that could be useful elsewhere.

VirtIO free-page reporting provides part of the solution. It allows the guest to report unused memory pages to the hypervisor, which can then release their physical backing without reducing the VM's configured memory capacity.

The relevant libvirt configuration is remarkably small:

<memballoon model="virtio" freePageReporting="on">
  <stats period="10"/>
</memballoon>

However, free-page reporting is not the same thing as automatic host-pressure-driven memory ballooning. Nor does it necessarily release fragmented free memory or filesystem caches as aggressively as one might expect.

After some experimentation, I settled on a pragmatic solution specific to this workload.

When the machine is idle, a small systemd maintenance service can perform the following:

sync
echo 3 > /proc/sys/vm/drop_caches
echo 1 > /proc/sys/vm/compact_memory

This flushes pending filesystem writes, releases reclaimable caches and compacts memory, allowing more free pages to become eligible for reclamation.

Regularly dropping filesystem caches would generally be a questionable optimization for a busy Linux server.

This is not a busy Linux server.

It is a disposable build appliance that might spend the next six hours doing practically nothing. I would rather let the hypervisor use that memory elsewhere than preserve cached copies of files involved in a build that has already finished.

The maintenance service checks for running Docker containers and active APT maintenance before proceeding. Those are best-effort idle checks rather than strict workload synchronization, but they are sufficient for our present requirements.

The results were quite interesting.

Measurement QEMU resident memory
Peak during image builds 4.06 GiB
Initially idle after builds 3.62 GiB
After manual memory compaction 2.56 GiB
After cache reclamation and compaction 1.41 GiB
After an extended idle period 1.24 GiB

These are observed resident memory measurements, not controlled benchmark results.

Nevertheless, they illustrate the difference quite nicely.

The guest still has its full 4 GiB capacity available when required. It simply does not have to occupy all of it physically throughout the day.

After migrating the remaining CI pipelines and running another five builds, physical memory usage returned to approximately 2 GiB within five minutes of inactivity, even without waiting for the next scheduled cleanup.

CPU usage when idle is typically below one percent.

That is a resource footprint I am quite comfortable accommodating on an already running server.

Infrastructure & operations

Need this kind of infrastructure thinking professionally?

Through Neoground, I work on Linux systems, hosting, platform operations, modernization, reliability, and the less glamorous technical foundations that good digital systems depend on.

The machine looks after itself

The final piece of the operational architecture is deliberately unremarkable.

Systemd timers.

No additional scheduling framework. No infrastructure management service running permanently just to maintain another infrastructure service.

Debian already provides most of the mechanisms required.

The VM now handles:

  • Daily unattended Debian security updates.
  • Periodic Docker cache and dangling image cleanup.
  • Cleanup of abandoned stopped containers.
  • APT package cache maintenance.
  • Bounded Docker and system journal logging.
  • Weekly filesystem trimming.
  • Periodic memory reclamation during idle periods.

Automatic reboots are disabled. Upgrading the runner itself or deliberately changing the software environment remains an infrastructure management decision.

The Ansible role can also reconcile the configuration of an existing guest without destroying it.

Consequently, there are two rather different operational procedures available:

Update the existing machine through Ansible.

Or remove the machine and recreate it through Ansible.

Both are preferable to gradually accumulating years of undocumented configuration changes.

From a Git push to a Windows installer

One of the first meaningful tests of the new infrastructure was an Electron application.

I updated the application to Electron 45.5.0, changed its Forgejo workflow to use the new runner, and pushed the repository.

The build started immediately.

Six minutes later, I had three downloadable packages:

  • Windows x64 installer.
  • Debian package.
  • RPM package.

During the build, QEMU consumed approximately 160–170% CPU, corresponding to around 1.6–1.7 logical CPU cores.

Physical memory usage increased to roughly 3–4 GiB.

The rest of the server continued doing its usual work.

Shortly afterwards, CPU usage returned to around 0.5–1%. Running the memory maintenance service reduced QEMU's resident memory to approximately 1.7 GiB, with most of the guest's memory available for future workloads.

No resource allocation changes. No manual resizing of the virtual machine. No additional build workers.

Just one modest virtual machine briefly doing some useful work.

The remaining project pipelines were subsequently migrated to the new runner as well.

They worked.

There is something rather satisfying about an infrastructure modernization whose most important success criterion is that the applications barely notice it happened.

The other end of the pipeline

Building software is only one part of software delivery.

The other part is getting that software into the environment where it belongs.

This is where artifact-based deployments become particularly attractive.

For desktop applications, the artifact is usually the finished product: an installer or a platform-specific package.

For web applications, we produce a prepared application tree packaged into a compressed archive, accompanied by a manifest and checksum information.

The artifact already contains the production dependencies and compiled frontend assets. It does not need another Node.js environment, another dependency installation or another build process on the destination machine.

A typical deployment now looks something like this:

Source repository
        ↓
Forgejo workflow
        ↓
Standardized build environment
        ↓
Dependencies, assets, validation
        ↓
Release artifact + manifest + checksum
        ↓
SSH / rsync
        ↓
Compass
        ↓
Production application

The destination might be my local server or a dedicated machine in a data center. The concept remains the same.

At Neoground, we already have the appropriate infrastructure management layer for this: Compass, our own lightweight hosting control plane.

Compass manages webspaces and their deployment configuration, and its accompanying system-side tooling can ingest release artifacts, deploy them and handle rollbacks.

There is no need to reconstruct that functionality inside every application repository.

Some applications still have a mixed directory structure in which persistent data, logs or other local state live alongside application code. Small project-specific deployment scripts account for those differences and preserve the relevant paths when upgrading.

More deliberately separated applications need even less custom logic.

We are not trying to force every application into an identical directory structure or runtime model merely to satisfy the deployment infrastructure.

The deployment infrastructure accommodates the applications.

I previously described the architectural reasoning behind this approach in more detail on the Neoground blog: From Source to Production: How We Modernized Our App Delivery Pipeline.

What has changed since then is not the fundamental deployment architecture.

It is the machinery producing those artifacts.

And with the new CI infrastructure in place, moving the remaining websites and applications from Git-based deployment to artifact-based releases has become considerably more attractive.

Is this over-engineered?

A perfectly reasonable person might look at the resulting architecture and ask why I did not simply rent a cheap VPS.

A headless Linux server running a QEMU/KVM virtual machine, provisioned from a Debian cloud image through Ansible, with a dedicated libvirt network, nftables isolation, Docker, Forgejo, custom build environments, socket-based Docker management and automated resource reclamation.

It is certainly not the shortest possible list of technologies.

But the list alone is not a particularly useful measure of complexity.

Most of these technologies are mature, independently understandable components. Each has a reasonably well-defined responsibility. Very little custom software is required to connect them.

There is no Kubernetes cluster. No distributed runner fleet. No separate deployment orchestration platform. No infrastructure subscription purchased specifically to execute a handful of daily build jobs.

The server already exists. The computing resources already exist. The source control infrastructure already exists. The application deployment tooling already exists.

The engineering investment was in making those resources work together coherently.

A VPS would eliminate the need to manage virtualization and some aspects of networking. It would also introduce another machine to rent, administer and maintain, with dedicated capacity that our workload would rarely use.

Hosted CI would eliminate even more infrastructure responsibility, and for many organizations that is absolutely the correct economic decision.

For us, the combination of existing hardware, numerous software projects, in-house Linux expertise and a preference for infrastructure independence produces a rather different calculation.

There is still a cost, of course. My engineering time is not free, the server consumes electricity, and I remain responsible for the hypervisor. Concentrating services on one physical machine also creates a shared failure domain.

The justification is not that self-hosting is universally cheaper or inherently superior.

It is that the resulting system fits the environment in which it operates.

And, importantly, most of the complexity is now expressed in configuration rather than recurring operational work.

Complexity should disappear into the system

One of my favorite aspects of the resulting architecture is how little of it I encounter during ordinary development.

If I want to update a build environment, I edit a Dockerfile and push the repository.

If I want to release a desktop application, I push its source code and receive finished packages.

If I want to deploy a website, the pipeline produces a verified artifact and transfers it to the destination, where the existing deployment tooling knows what to do with it.

If I want to rebuild the CI machine itself, I have an Ansible role.

The underlying mechanisms are relatively sophisticated. The everyday interactions are almost trivial.

That is a distinction I increasingly appreciate in systems engineering.

Simplicity does not necessarily mean having few components. Sometimes a system with several deliberately separated components is considerably simpler to operate than one large component with poorly defined responsibilities.

Likewise, automation is not particularly valuable merely because it replaces a manual command. It becomes valuable when it removes an entire category of things one has to remember, coordinate or worry about.

I no longer need to remember to start the CI machine.

I do not need to periodically investigate whether Docker has accumulated another dozen gigabytes of intermediate layers.

I do not need to maintain slightly different build environments across numerous project repositories.

I do not need to care much about where the CI runner happens to execute, provided it supplies the expected environment and produces the expected artifacts.

The infrastructure has become a reusable capability, rather than another ongoing project.

Back to building software

The August architecture was a reasonable solution to the requirements we had in August.

The November architecture is a reasonable solution to the requirements we have now.

I find that evolution more interesting than the individual technologies involved.

There was no grand plan to build an internal developer platform. There were websites to deploy, applications to build, servers to manage, security boundaries to respect, and increasingly obvious opportunities to eliminate repetitive work.

Over time, those pieces formed a fairly coherent system.

Source control, standardized build environments, isolated execution, transferable release artifacts, controlled deployment and reproducible infrastructure.

All maintained through a relatively small collection of repositories.

And somewhere in the background, a little Debian machine spends most of its existence doing practically nothing.

Occasionally, it wakes up a few CPU cores, occupies several gigabytes of memory, compiles some software, produces the requested artifacts, and subsequently returns its resources to the rest of the system.

No daily intervention. No additional hosting subscription. No reason for me to open a virtualization console.

I can finally get back to writing software.

Which, if I remember correctly, was the point of all this.

Professional work

Need help turning a complex technology problem into something workable?

I work with founders and organizations through Neoground on software, infrastructure, AI, and strategic technology questions — from focused reviews to larger systems and advisory engagements.

About Sarah Robin

Founder, technologist, strategic advisor, and writer.

Sarah builds, advises, and writes about AI, software, digital systems, and the wider forces shaping technology and entrepreneurship. She founded Neoground and approaches technology from both an engineering and strategic perspective, with an increasingly international focus across Europe, London, New York, Silicon Valley, and the Pacific Northwest.

No Comments Yet

Add a comment

You can use **Markdown** in your comment. Your email won't be published. Find out more about my data protection in the privacy policy.