Git Product home page Git Product logo

gradle-vagrant-plugin's Introduction

Gradle Vagrant plugin

Vagrant Logo

Gradle plugin for managing Vagrant boxes.

Usage

To use the plugin, include in your build script:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-vagrant-plugin:2.0'
    }
}

Base plugin

If you want to create your own task for managing Vagrant, you should go with the base plugin. This option is usually helpful if you are dealing with multiple VMs in parallel. The base plugin provides all custom task types and preconfigures them with sensible defaults. To use the base plugin, add the following apply notation to your build script.

apply plugin: 'com.bmuschko.vagrant-base'

Custom task types

The base plugin provides the following custom task types:

Type Description

VagrantDestroy

Stops the running machine Vagrant is managing and destroys all resources.

VagrantHalt

Shuts down the running machine Vagrant is managing.

VagrantReload

The equivalent of running a halt followed by an up.

VagrantSsh

Executes a SSH command on the Vagrant machine.

VagrantSshConfig

Outputs the valid configuration for an SSH config file to SSH.

VagrantStatus

Outputs the state of the machines Vagrant is managing.

VagrantSuspend

Suspends the guest machine Vagrant is managing.

VagrantUp

Creates and configures guest machines according to your Vagrantfile.

Extension properties

The base plugin defines the following extension properties in the vagrant closure:

Property name Type Default value Description

boxDir

File

project.projectDir

The directory the targeted Vagrant box resides in.

provider

String

virtualbox

The backend provider to be used.

The recommended way for providing values to the Vagrantfile from the outside is to use environment variables. This is made possible through the nested configuration element environmentVariables. This element exposes the method variable that takes two parameters: the key and value for a environment variable. For each invocation of this method a new key/value pair is added to internal property named variables.

Property name Type Default value Description

variables

Map<String, String>

[:]

Provided environment variables as key/value pairs.

By default the plugin validates the installation of the Vagrant runtime and the selected provider. This validation logic can be disabled from your buildscript. This is made possible through the nested configuration element installation. This element exposes the method validate that take a single parameter.

Property name Type Default value Description

validate

Boolean

true

Installation validation

Example

import com.bmuschko.gradle.vagrant.tasks.VagrantUp
import com.bmuschko.gradle.vagrant.tasks.VagrantDestroy

ext {
    virtualBoxDir = file('virtualbox-box')
    fusionBoxDir = file('fusion-box')
    fusionProvider = 'vmware_fusion'
}

task startVirtualBoxVm(type: VagrantUp) {
    description = 'Starts VM machine running on VirtualBox.'
    group = 'VirtualBox VM'
    boxDir = virtualBoxDir
}

task stopVirtualBoxVm(type: VagrantDestroy) {
    description = 'Stops VM machine running on VirtualBox.'
    group = 'VirtualBox VM'
    boxDir = virtualBoxDir
}

task startFusionVm(type: VagrantUp) {
    description = 'Starts VM machine running on VMware Fusion.'
    group = 'Fusion VM'
    boxDir = fusionBoxDir
    provider = fusionProvider
}

task stopFusionVm(type: VagrantDestroy) {
    description = 'Stops VM machine running on VMware Fusion.'
    group = 'Fusion VM'
    boxDir = fusionBoxDir
    provider = fusionProvider
}

Convention plugin

If you want the plugin to preconfigure commonly-used tasks for you, you should go with the full-fledged convention plugin. This plugin is a viable option if you only have to deal with a single VM. To use the convention plugin, add the following apply notation to your build script.

apply plugin: 'com.bmuschko.vagrant'

Default tasks

The plugin defines the following tasks:

Task name Depends on Type

vagrantDestroy

-

VagrantDestroy

vagrantHalt

-

VagrantHalt

vagrantReload

-

VagrantReload

vagrantResume

-

VagrantResume

vagrantSshConfig

-

VagrantSshConfig

vagrantStatus

-

VagrantStatus

vagrantSuspend

-

VagrantSuspend

vagrantUp

-

VagrantUp

Example

vagrant {
    boxDir = file('~/dev/my-vagrant-box')

    environmentVariables {
        variable 'IP', '192.168.1.33'
        variable 'OPERATINGSYSTEM', 'redhat'
    }

    installation {
        validate = false
    }
}

import com.bmuschko.gradle.vagrant.tasks.Vagrant
import com.bmuschko.gradle.vagrant.tasks.VagrantSsh

task vagrantListsBoxes(type: Vagrant) {
    description = 'Outputs a list of available Vagrant boxes.'
    commands = ['box', 'list']
}

task vagrantEcho(type: VagrantSsh) {
    description = 'Runs remote SSH command in Vagrant box.'
    sshCommand = "echo 'hello'"

    dependsOn vagrantUp
    finalizedBy vagrantDestroy
}

gradle-vagrant-plugin's People

Contributors

bmuschko avatar bjornmagnusson avatar andrewkroh avatar

Watchers

James Cloos avatar Joel Cruz avatar

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.