Start GitHub Actions self-hosted runner with VirtualBox and Vagrant

Overview
  • Start GitHub Actions self-hosted runner with VirtualBox and Vagrant on your local machine or a remote machine like Google Compute Engine and EC2.
  • Avoid dind (Docker in Docker)
  • Accelerate docker build (or docker-compose build) on the virtual machine with the Docker Layer Caching as the same as your local environment.
  • Host OS: Ubuntu 18.04/20.04, macOS, Windows
  • Guest OS: Ubuntu 20.04
  • Install VirtualBox
    Ubuntu 18.04/20.04
    sudo apt install -y virtualbox
    macOS
    brew cask install virtualbox
    Allow Oracle America, Inc. in the System Preferences.
    Install Vagrant
    Ubuntu 18.04/20.04
    curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
    sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
    sudo apt update && sudo apt install -y vagrant
    vagrant autocomplete install
    macOS
    brew install vagrant
    vagrant autocomplete install
    Start VM
    git clone https://github.com/peaceiris/actions-self-hosted-runners.git
    cd ./actions-self-hosted-runners/images/ubuntu-20.04
    git checkout v0.4.0
    vim .env
    make up
    vagrant ssh
    cd actions-runner
    ./config.sh --url https://github.com/[owner]/[repo] --token [token]
    nohup ./run.sh &
    Create .env file as follows.
    VB_CPUS = '4'
    VB_MEMORY = '8192'
    VB_DISK_SIZE = '30GB'
  • VB_CPUS: CPU cores
  • VB_MEMORY: Memory size
  • VB_DISK_SIZE: Disk size
  • Use the VM and Accelerate docker build
    Unlike the GitHub hosted runner, a self-hosted runner is not destroyed for each job, so Docker Layer Caching will work as well as local machine. You don't have to worry about tricky usage of the actions/cache and capacity limits. The docker build job became accelerated and we achieved the purpose.
    name: CI frontend
    
    on:
      push:
        branches:
          - main
      pull_request:
    
    jobs:
      docker:
        runs-on: self-hosted
        timeout-minutes: 3
        env:
          COMPOSE_DOCKER_CLI_BUILD: 1
          DOCKER_BUILDKIT: 1
        steps:
          - uses: actions/checkout@v2.3.4
          - run: hadolint ./Dockerfile
          - run: sudo docker-compose build frontend
    Slow docker-compose build job on the GitHub hosted runner.
    Accelerated docker-compose build job on a self-hosted GitHub Actions runner.
    Enabled Docker Layer Caching on a GitHub Actions self-hosted runner.
    Repository

    GitHub logo peaceiris / actions-self-hosted-runners

    GitHub Actions self-hosted runner on VirtualBox with Vagrant.

    actions-self-hosted-runners

    CI

    GitHub Actions self-hosted runner on VirtualBox with Vagrant.

    Getting Started

    git clone https://github.com/peaceiris/actions-self-hosted-runners.git
    cd ./actions-self-hosted-runners/images/ubuntu-20.04
    git checkout v0.4.0
    vim .env
    make up
    vagrant ssh
    cd actions-runner
    ./config.sh --url https://github.com/[owner]/[repo] --token [token]
    nohup ./run.sh &
    Enter fullscreen mode Exit fullscreen mode

    Create .env file as follows.

    VB_CPUS = '4'
    VB_MEMORY = '8192'
    VB_DISK_SIZE = '30GB'
    Enter fullscreen mode Exit fullscreen mode
    Conclusion
  • We can start a self-hosted GitHub Actions runner on a Ubuntu 20.04 virtual machine with VirtualBox and Vagrant very easily.
  • We can accelerate docker build (or docker-compose build) on the virtual machine with the Docker Layer Caching as the same as your local environment.
  • Enjoy the comfortable CI/CD! Thank you.

    55

    This website collects cookies to deliver better user experience

    Start GitHub Actions self-hosted runner with VirtualBox and Vagrant