Skip to content

Latest commit

 

History

History
66 lines (42 loc) · 2.96 KB

README.md

File metadata and controls

66 lines (42 loc) · 2.96 KB

vagrant-github-actions

Build Status

Example project showing how to run a Vagrant box on GitHub Actions

I have some history in this topic on how to run Vagrant on Cloud CI systems for OpenSource projects :) See https://stackoverflow.com/a/60615201/4964553 & https://stackoverflow.com/a/60380518/4964553 - since until somewhere in 2020 the only possible way was TravisCI with libvrt: https://github.com/jonashackt/vagrant-travisci-libvrt

What didn't work was plain VirtualBox on Travis: https://github.com/jonashackt/vagrant-travisci and also other CI platforms also did't work like AppVeyor https://github.com/jonashackt/vagrant-ansible-on-appveyor (I didn't even try the others because of this).

BUT then the end of 2020 came and Travis defacto ended broad support for OpenSource (see codecentric/cxf-spring-boot-starter#93) and I started to migrate all my repositories to GitHub Actions. I even blogged about it (tba when released).

And I finally found out, that there's Vagrant activated (incl. nested virtualization) on GitHub Action MacOS environment (not Linux or Windows currently).

How to run Vagrant on GitHub Actions

So let's first add a Vagrantfile like this:

Vagrant.configure("2") do |config|
    config.vm.box = "generic/ubuntu1804"

    config.vm.define 'ubuntu'

    # Prevent SharedFoldersEnableSymlinksCreate errors
    config.vm.synced_folder ".", "/vagrant", disabled: true
end

Now add a MacOS environment powered GitHub Actions vagrant-up.yml:

name: vagrant-up

on: [push]

jobs:
  vagrant-up:
    runs-on: macos-10.15

    steps:
      - uses: actions/checkout@v2

      - name: Cache Vagrant boxes
        uses: actions/cache@v2
        with:
          path: ~/.vagrant.d/boxes
          key: ${{ runner.os }}-vagrant-${{ hashFiles('Vagrantfile') }}
          restore-keys: |
            ${{ runner.os }}-vagrant-

      - name: Show Vagrant version
        run: vagrant --version

      - name: Run vagrant up
        run: vagrant up

      - name: ssh into box after boot
        run: vagrant ssh -c "echo 'hello world!'"

And since there's no stable release of VirtualBox for Big Sur (v11), well go with MacOS version 10.15 (which is currently also the macos-latest environment on GitHub Actions)

We also use the https://github.com/actions/cache action here to cache our Vagrant boxes for further runs. Using hashFiles('Vagrantfile') will make sure we only create a new cache, if our Vagrantfile changed (and thus assume, that the box name is also different).