DevOps

Self-Hosted GitHub Runners on $28 Hetzner VPS: Slashing Docker Build Times from 22 Minutes to 84 Seconds

A
Adebayo FalojuPrincipal Systems Architect
November 20, 20267 min read
Self-Hosted GitHub Runners on $28 Hetzner VPS: Slashing Docker Build Times from 22 Minutes to 84 Seconds

Cloud-hosted CI runners are expensive and suffer from severe network bottlenecks when pulling multi-gigabyte Docker layers. Here is how Neobot Tech migrated a client's CI/CD pipeline to self-hosted Hetzner runners with local layer caching, cutting build times by 93% and eliminating over $1,400 in monthly runner bills.

When mid-sized engineering teams scale up their microservices, the default reaction to slow CI/CD pipelines is usually to pay GitHub or AWS for bigger cloud runners. But if your team is deploying containerized workloads from Africa or Eastern Europe, cloud runner billings escalate quickly without fixing the core bottleneck: transatlantic bandwidth latency and redundant Docker image layer pulls.

In early 2024, Neobot Tech audited a client’s deployment workflow. The engineering team had 14 microservices written in Go and Node.js. Every pull request triggered multi-stage Docker builds on standard GitHub-hosted ubuntu-latest runners. As the team grew to 18 full-time developers, their GitHub Actions bill hit $1,420 in a single month. Worse, developers spent nearly half an hour waiting for basic integration tests to complete because every single build spent minutes redownloading npm modules, Go build caches, and standard Alpine base images.

We eliminated the monthly runner bill entirely and reduced average build times from 22 minutes down to 84 seconds. Here is the exact breakdown of why the standard setup failed, how we re-architected the CI infrastructure, and the step-by-step playbook you can use on bare-metal or cheap Virtual Private Servers (VPS).

Architecture diagram showing GitHub Actions workflow sending jobs to a self-hosted Hetzner runner with local NVMe Docker build cache

The Problem: Transatlantic Network Latency and Cache Eviction

GitHub’s default hosted runners operate on shared Azure virtual machines in North America or Western Europe. Every time a build job starts, it provisions a clean virtual machine environment. While this guarantees isolated, reproducible builds, it introduces two severe failure modes for teams running complex container pipelines:

  1. Network Payload Saturation: Every multi-stage Docker build requires fetching base dependencies. Even with basic Docker cache actions (actions/cache), pulling compressed 800MB layer caches over GitHub’s internal network to fresh runner VMs takes 45 to 90 seconds per job step.
  2. Aggressive Cache Limits: GitHub Actions enforces a strict 10GB cache limit per repository. Once a repository exceeds 10GB, GitHub silently evicts the oldest cache archives. For a codebase with 14 active microservices across multiple feature branches, cache hit rates dropped below 30%.

Developers were routinely waiting 20 to 25 minutes for PR checks. When working on shaky local connections in Lagos, pushing a quick one-line bugfix felt like launching a rocket—if the connection dropped midway or the GitHub runner hit a transient timeout, the developer lost another 20 minutes.

Our client was suffering from infrastructure issues similar to those we addressed when resolving WAL-G Stream Compression & S3 Multipart Chunks: Stopping Postgres Backup Failures on 10Mbps VPS Uploads. Unstable upstream connections and inefficient transfer patterns burn engineering hours fast.

| Pipeline Approach | Avg Build Time | Monthly Cost | Cache Persistence Mechanism | | :--- | :--- | :--- | :--- | | GitHub-Hosted ubuntu-latest | 22 mins | $1,420 / mo | Ephemeral actions/cache (10GB limit) | | AWS EC2 t3.xlarge Self-Hosted | 8 mins | $640 / mo | Remote ECR Registry Cache (High DTO fees) | | Hetzner AX41 NVMe Bare Metal | 84 secs | $28 / mo | Persistent Local Host Storage Engine (type=local) |

What We Tried First (And Why It Failed)

Before settling on bare-metal self-hosted nodes, we tried two intermediary solutions that failed to solve the real problem.

Attempt 1: Tuning actions/cache and BuildKit Registry Caching

We first modified the GitHub Actions workflows to export Docker BuildKit layers directly to GitHub Container Registry (GHCR) using --cache-to type=registry.

- name: Build and push
  uses: docker/build-push-action@v5
  with:
    context: .
    cache-from: type=registry,ref=ghcr.io/org/repo:buildcache
    cache-to: type=registry,ref=ghcr.io/org/repo:buildcache,mode=max

While this improved cache hit rates slightly, the build duration barely moved. Fetching multi-gigabyte layer caches over public container registry endpoints incurred significant latency. Ephemeral runners still spent 60% of their lifespan downloading and uncompressing tarballs before executing a single line of application code.

Attempt 2: Provisioning AWS EC2 Self-Hosted Runners

Next, we spun up an AWS EC2 t3.xlarge instance in the eu-west-1 region to act as a persistent self-hosted runner. Because the node remained online continuously, Docker’s local daemon cached intermediate build layers directly on disk.

Build times instantly dropped from 22 minutes to 8 minutes. However, AWS data transfer costs caught us off guard. Pulling base images, pushing release artifacts to external registries, and updating package mirrors generated hundreds of gigabytes in cross-region Data Transfer Out (DTO). The EC2 compute instance cost $120/month, but the network transfer fees added another $520/month. We were still burning nearly $700 monthly for mid-tier CI performance.

The Architecture That Worked: Hetzner Bare-Metal + Docker Local Engine

To strip out network bottlenecks entirely, we moved the execution layer to dedicated hardware. We provisioned a Hetzner AX41-NVMe server (AMD Ryzen 5 3600, 64GB DDR4 RAM, 2 x 512GB NVMe SSDs in RAID 1) located in Falkenstein, Germany, costing roughly €26/month (~$28 USD).

By leveraging the full disk read/write bandwidth of NVMe drives (up to 3,000 MB/s), intermediate BuildKit caches could be read from and written to local storage in milliseconds rather than downloaded over a network connection.

Here is how the working system was built.

1. In-Cluster Docker Registry Mirroring

To eliminate rates and limits imposed by Docker Hub, we ran a local pull-through registry mirror on the runner machine. We configured /etc/docker/daemon.json on the runner node to proxy requests:

{
  

Neobot Engineering Standard

Every system deployed by Neobot Tech incorporates enterprise baseline practices. We continuously audit our database topologies, REST API query paths, and frontend modular bundles to prevent latency spikes and ensure top-tier security posture.

Tags:#DevOps#Docker#CI/CD#GitHub Actions#Hetzner#Infrastructure

Discussion

Comments Coming Soon

We are currently migrating our discussion engine to a new real-time database schema. Check back shortly to join the conversation.