grv87 / gradle-packer-plugin

Runs Packer builds (https://www.packer.io/) from Gradle
Other
3 stars 1 forks source link
devops gradle packer vm

gradle-packer-plugin

This plugin allows to run Packer builds from Gradle.

  1. It parses Packer's templates and creates Gradle tasks to run Packer. For each template it creates single task to run all builders at once and separate task for each builder.

  2. It could pass used-defined variables to Packer.

  3. It configures tasks' inputs and outputs so that Gradle could detect tasks as UP-TO-DATE.

Example of use:

plugins {
    id 'org.fidata.packer' version '2.4.0'
}

packer {
    variables = [
        'packer_output_dir': packerOutputDir,
        'aws_access_key': awsAccessKey,
        'aws_secret_key': awsSecretKey
    ]
    template 'src/base_images/UbuntuServer16.04.1-amd64.json'
}

Requirements

Task names

Plugin creates series of tasks for cleaning and running Packer builds. If template has a name variable, it is used instead of template filename. High-level task names are:

Supported Packer configurations:

Gradle Offline Mode

This plugin doesn't respect Gradle's --offline command line argument.

  1. Although it is feasible to detect that specific builder/provisioner/post-processor doesn't require network connection itself, it is not so for provisioning scripts. VirtualBox VM created from local ISO could be provisioned with scripts that run apt-get install inside. There is no (simple) way to detect it and prevent running such task in offline mode. Generally, Packer builds almost always require network connection.

  2. I haven't seen live examples where Gradle's --offline command line argument is used for something useful except testing and debugging purposes. So, I see little benefit in its support.

Notes

  1. Gradle (as of 3.2) can't handle URLs.

    However, it is usually safe to assume that ISOs in the web are not changed.

Security Notes

Plugin uses Jackson to deserialize Packer templates from JSON to nice Groovy objects. Although this plugin is secure by itself, it allows other (custom) plugins to register its own builders, provisioners and post-processors. This could open a security vulnerability if used carelessly. See this whitepaper produced by NCC Group for examples of exploits.

To mitigate this risk:


Copyright © Basil Peace

This is part of gradle-packer-plugin.

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.