HTTPS SSH

Gradle Vagrant Plugin

This is a Vagrant Plugin for Gradle. It is used internally at Coherent Software Australia, and has been released under the Apache licence (v2) in the hope someone else might find it useful.

Its primary purpose is to assist testing projects by managing a Vagrant virtual machine.

The task types added to your project can be thought of as belonging to one of two groups. The 'basic' types have a one-to-one relationship with vagrant commands. This group includes tasks such as VagrantUp, VagrantDestroy, VagrantSsh. They expect you to micro-manage any dependencies or requirements.

The other group of tasks are more intelligent. They will adjust their interaction with Vagrant according to the current status of the VM.

This plugin will not create or alter a VagrantFile, nor will it init a vagrant directory. All tasks assume the VagrantFile and vagrant project directory have already been correctly configured.

Building

The build system uses the Gradle wrapper. Therefore the only requirement is Java 6 or later.

./gradlew

will build the plugin.

Usage

Common to all Vagrant plugin tasks

import au.com.coherentsoftware.gradle.vagrant.task.*

buildscript {
    dependencies {
        classpath locationOfPluginJar
    }
}

apply plugin: 'vagrant'

vagrant {
    path = '/usr/bin/vagrant' // the default value
    baseDir = 'vagrant' // the location of the vagrant project, should be valid for use with Gradle's project.file()
}

The basic tasks

All tasks accept optional machineName(s). If supplied, that task will act only on the named machine(s).

VagrantUp

task dbVmUp(type: VagrantUp) {
    machineName 'db'
}

:::groovy
task allVmsUp(type: VagrantUp)

VagrantDestroy

task cleanVms(type: VagrantDestroy)

VagrantHalt

task stopVms(type: VagrantHalt)

VagrantProvision

task provisionVms(type: VagrantProvision)

VagrantReload

task resetBackendVms(type: VagrantReload) {
    machineNames ['db','store']
}

VagrantResume

task resumeVms(type: VagrantResume)

VagrantSuspend

task pauseVms(type: VagrantSuspend)

VagrantSsh

task restartJettyInVmOne(type: VagrantSsh) {
    machineName 'JettyOne'
    command = 'sudo service jetty8 restart'
}

:::groovy
task compileLegacyProjectWithinVm(type: VagrantSsh) {
    command = 'cd /data/project; make'
}

The 'intelligent' task

VagrantRunning

Does the minimum necessary to ensure the vm is running.

task ensureDbAvailable(type: VagrantRunning) {
    machineName 'db'
    alwaysProvision = true
    alwaysReload = false
}

Licence

This software is released under the Apache License, Version 2.0. Please see the copy of the licence, included in this directory as LICENSE, for details.

Bugs, Wishlist

The implemented features could be more generalised: they are currently specific to our use cases.

Documentation could be improved.

There are probably many ways the plugin could be made more robust.

Feel free to fork and send pull requests! Home page on BitBucket at https://bitbucket.org/coherentsoftware/gradle-vagrantplugin