• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

bmuschko/gradle-vagrant-plugin: Gradle plugin for managing Vagrant boxes.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

bmuschko/gradle-vagrant-plugin

开源软件地址(OpenSource Url):

https://github.com/bmuschko/gradle-vagrant-plugin

开源编程语言(OpenSource Language):

Groovy 100.0%

开源软件介绍(OpenSource Introduction):

Gradle Vagrant plugin Build Status

Vagrant Logo

Gradle plugin for managing Vagrant boxes.

Usage

To use the plugin, include in your build script:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-vagrant-plugin:3.0.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.file("vagrant")

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
}



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap