|

Self-Hosted GitLab Runner & GitHub Actions CI/CD Pipelines on VPS

Self-Hosted GitLab & GitHub Actions CI/CD Runners on VPS technical architecture and dedicated infrastructure diagram
Verified Technical Answer

Deploying self-hosted CI/CD runners on VPS infrastructure cuts build queue times, eliminates per-minute SaaS runner billing, and keeps proprietary source code and registry tokens inside controlled private networks. Production-safe runners use ephemeral Docker or rootless container executors per job, fast NVMe scratch volumes for Cargo/Maven/Docker layer caches, strict cgroups CPU/RAM caps, and automated workspace cleanup so concurrent builds remain reproducible and isolated.

Hosted CI/CD runners on GitHub.com and GitLab.com throttle teams with modest 2-to-4 vCPU burst quotas, cold dependency caches, and steep overage charges once monorepos, integration test suites, or multi-arch container builds scale up. Moving build pipelines onto dedicated VPS instances gives engineering organizations dedicated NVMe disk throughput, persistent local registry mirrors, and direct WireGuard access to private staging clusters. However, executing arbitrary pull-request code on your own servers introduces significant security and disk-exhaustion risks unless runners are architected for ephemeral isolation from the start.

Ephemeral Job Sandboxing

Run GitLab Docker executors or ephemeral GitHub Actions Runner Controller/systemd wrappers so every job starts from a clean image with zero lingering credentials.

NVMe Cache Acceleration

Mount Docker overlay2, BuildKit cache mounts, and language package registries on high-IOPS NVMe storage to cut compile and image-push durations by 3x-5x.

Security & Resource Hygiene

Never mount /var/run/docker.sock directly for untrusted PRs; enforce rootless BuildKit/Kaniko, egress firewalling, and scheduled image/volume pruning.

GitLab Runner vs. Self-Hosted GitHub Actions Architecture

While both GitLab Runner and the GitHub Actions Runner connect outbound over HTTPS/WebSockets to poll job queues—requiring zero inbound firewall ports on your VPS—their isolation models differ significantly. GitLab Runner natively abstracts execution backends through executors (docker, docker-autoscaler, shell, or kubernetes), meaning a single runner daemon can spawn isolated containers per job without exposing the host OS. Detailed executor flags, concurrency limits, and cache S3 bindings are documented in the official GitLab Runner Documentation.

By contrast, the standard GitHub Actions self-hosted runner executes directly on the host OS unless you wrap it inside ephemeral containers, Firecracker microVMs, or pass --ephemeral paired with a systemd restart loop that wipes the work directory and re-registers a fresh JIT runner token after every single job. For public repositories, GitHub explicitly warns against attaching persistent self-hosted runners to fork pull requests due to workflow-injection risks; even for private repositories, ephemeral single-use execution is the gold standard.

Runner Pattern Job Isolation Level Cache Persistence Container Build Method Recommended Workload
GitLab Docker Executor High (fresh container per job) Docker named cache volumes / MinIO S3 Rootless BuildKit or isolated DinD Private/team GitLab repos with parallel jobs
GitHub Ephemeral Container High (container destroyed post-job) Bind-mounted NVMe cache dir (read/write lock) Rootless Podman / Buildah / BuildKit Private org GitHub Actions pipelines
Host Shell Executor Low (shared host user & filesystem) Direct local filesystem Host Docker daemon (high risk) Strictly trusted deploy-only jobs
Ephemeral MicroVM (Kata/Firecracker) Maximum (hardware VM boundary per job) Remote artifact cache / snapshot drives Full unprivileged DinD inside VM Untrusted PRs & multi-team monorepos

Configuring Hardened Executors & Rootless Container Builds

CI/CD pipelines are notoriously I/O-bound: unpacking thousands of node_modules files, compiling Rust crates, and compressing multi-layer Docker images rapidly saturate spinning disks or throttled SATA volumes. Sizing host volumes using NVMe vs SATA SSD dedicated server storage metrics prevents overlay2 metadata operations from stalling concurrent runner threads. Always place /var/lib/docker and runner cache directories on a dedicated partition or LVM volume so a runaway build log cannot fill / and lock up SSH or systemd.

Avoid binding the host /var/run/docker.sock into job containers whenever possible, because socket access is equivalent to full root privileges on the VPS. Instead, build OCI images using daemonless tools like rootless buildkitd, Buildah, or Kaniko, or isolate DinD containers with user-namespace remapping and strict memory/PID limits.

# /etc/gitlab-runner/config.toml - Concurrent isolated Docker executor
concurrent = 4
check_interval = 3

[[runners]]
  name = "vps-nvme-runner-01"
  url = "https://gitlab.example.com/"
  token = "glrt-REDACTED_RUNNER_TOKEN"
  executor = "docker"
  [runners.docker]
    image = "alpine:3.20"
    privileged = false
    cap_drop = ["ALL"]
    cpus = "2.0"
    memory = "4g"
    memory_swap = "4g"
    pids_limit = 512
    volumes = ["/cache/gitlab:/cache:rw"]
    shm_size = 268435456
    pull_policy = ["if-not-present"]
  [runners.cache]
    Type = "s3"
    Shared = true
    [runners.cache.s3]
      ServerAddress = "127.0.0.1:9000"
      BucketName = "runner-cache"
      Insecure = true

Ephemeral GitHub Actions Systemd Units & Dependency Caching

To keep self-hosted GitHub Actions clean without Kubernetes overhead on a single VPS, provision a dedicated unprivileged ghrunner service account, launch the runner with systemd resource limits, and configure a pre/post-job hook (ACTIONS_RUNNER_HOOK_JOB_COMPLETED) to scrub temporary directories. Additionally, deploying a local pull-through Docker registry mirror and an HTTP dependency proxy (such as Verdaccio for npm or Athens for Go) on the same VPS slashes external network latency and protects builds from upstream registry rate limits.

# /etc/systemd/system/github-runner.service
[Unit]
Description=Hardened GitHub Actions Self-Hosted Runner
After=network-online.target
Wants=network-online.target

[Service]
User=ghrunner
Group=ghrunner
WorkingDirectory=/opt/actions-runner
ExecStart=/opt/actions-runner/run.sh
Restart=always
RestartSec=5
CPUQuota=300%
MemoryMax=8G
TasksMax=1024
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ReadWritePaths=/opt/actions-runner /var/cache/ci-shared

[Install]
WantedBy=multi-user.target

Artifact Retention, Automated Pruning & Runner Security

Left unchecked, dangling Docker layers, untagged BuildKit caches, and stale workspaces consume 100% of a CI VPS disk within weeks. Schedule a systemd timer running docker system prune -af --filter 'until=72h' and docker builder prune --keep-storage=40GB to preserve hot recent layers while capping total disk consumption. For organizations retaining multi-terabyte build artifacts, release tarballs, or golden VM images, offload long-term retention from runner NVMe scratch disks onto dedicated storage dedicated server hosting backed by MinIO or S3-compatible object buckets.

Because CI/CD runners routinely inject deployment SSH keys, cloud IAM tokens, and container registry credentials via environment variables, they are prime supply-chain targets. Restrict outbound egress from runner subnets so build jobs cannot exfiltrate tokens to arbitrary IP addresses, and enable Linux auditd logging configuration and system call auditing to record privileged binary executions, /etc/gitlab-runner/config.toml edits, and anomalous outbound socket connections.

Rollback & Safety Precaution: Before modifying /etc/gitlab-runner/config.toml concurrency settings or activating aggressive docker system prune timers on an active build host, drain running pipelines using SIGQUIT (graceful stop) on GitLab Runner so active deployment jobs finish cleanly instead of aborting mid-release. Test prune filters with --dry-run or inspect active BuildKit volumes first so active production build caches are not wiped during peak engineering hours.

Concurrency Sizing & Multi-Runner Fleet Scaling

Overcommitting runner concurrency degrades total pipeline throughput: running eight parallel Maven or Webpack builds on a 4-vCPU VPS triggers severe context switching and OOM kills, making every job slower than queuing four sequential builds. Allocate roughly 2 vCPUs and 3-4 GiB of RAM per concurrent build slot for compiled languages, monitor build wait queues via Prometheus exporter endpoints (port 9252 on GitLab Runner), and scale horizontally across additional VPS nodes tagged by workload profile (e.g., linux-amd64-small, rust-nvme-large, docker-arm64).

  • Tag-Based Routing: Separate fast 30-second lint/unit runners from heavy 15-minute Docker/E2E runners using GitLab tags or GitHub labels so trivial PR checks never wait behind nightly builds.
  • Swap Guardrails: Configure a small 2-4 GiB NVMe swap file with vm.swappiness=1 purely as an emergency cushion against brief linker spikes while keeping memory_swap equal to memory inside build containers.
  • Zero-Downtime Maintenance: Register runners in pairs per tag so one node can drain and reboot for kernel updates without stalling developer merges.

Frequently Asked Questions

How many concurrent CI/CD jobs can run on an 8-vCPU, 16 GiB RAM VPS?

For typical Docker builds, Node.js bundling, or Go/Rust compilation, cap concurrency at 3 to 4 simultaneous jobs (allocating roughly 2 vCPUs and 4 GiB RAM per job). Pushing higher causes CPU thrashing and out-of-memory failures during linker or webpack steps.

Is it safe to mount /var/run/docker.sock into GitLab or GitHub CI containers?

Only in strictly trusted single-team private repositories, and even then it is discouraged. A job with access to the host Docker socket can mount the host root filesystem and gain root access to the VPS. Use rootless BuildKit, Buildah, Kaniko, or isolated Docker-in-Docker containers instead.

Why should self-hosted runners never execute jobs from public fork pull requests?

Anyone can open a pull request on a public repository and modify workflow or build scripts (such as Makefile or package.json) to execute arbitrary code on the runner, stealing secrets or pivoting inside your private network. Keep public fork PRs on disposable vendor-hosted runners.

How do I stop Docker build caches from filling the VPS disk?

Move /var/lib/docker onto a separate partition and run a daily systemd timer executing docker builder prune --keep-storage=30GB -f and docker image prune -af --filter 'until=72h' so recent build layers stay cached while obsolete images are purged.

Do self-hosted GitLab and GitHub runners require open inbound firewall ports?

No. Both runners initiate outbound HTTPS/TLS polling connections to GitLab or GitHub API endpoints. You can keep all inbound firewall ports closed except administrative SSH or WireGuard management access.

How can I share dependency caches across multiple runner VPS nodes?

Deploy a lightweight S3-compatible MinIO server on a fast internal node and point GitLab Runner’s [runners.cache] block to it, or use BuildKit remote registry caching (--cache-to type=registry) so every runner node pulls pre-built intermediate layers over private networking.

Accelerate Your CI/CD Pipelines on NVMe VPS

Deploy high-frequency self-hosted GitLab and GitHub Actions runners with dedicated NVMe storage and unmetered internal bandwidth.

Launch CI/CD Runner VPS

NR
Naveen Rajput — Infrastructure & Cloud Systems Architect

Reviewed by Onlive Server Infrastructure Engineering for technical accuracy, kernel/network safety, and global bare-metal operations.