Giter Site home page Giter Site logo

vagrant-test's Introduction

vagrant-github-actions

Build Status

f

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!'"

Healthcheck

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.