netfoundry / packer-builder-linode

Packer Builder plugin for Linode Images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Packer builder plugin for Linode Images

GoDoc Go Report Card CircleCI GitHub release

This is a Packer plug-in for building Linode Images.

Work in Progress

This project is currently not supported. Use at your own risk. Contributions welcome!

Build and Install

Requirements:

Go makes installing the Linode Images builder plugin for Packer easy:

GOBIN=~/.packer.d/plugins go install github.com/linode/packer-builder-linode

To fetch the code and improve the plugin itself:

git clone https://github.com/linode/packer-builder-linode
cd packer-builder-linode
make install

Configuration

With the builder plugin installed, an Packer file like the example at test/fixtures/builder-linode/minimal.json can create a Linode Image.

packer build -var "linode-token=$LINODE_TOKEN" test/fixtures/builder-linode/minimal.json

Some notes:

  1. You will need a Linode APIv4 Personal Access Token. Get one here: https://developers.linode.com/api/v4#section/Personal-Access-Token Naturally it's a bad idea to hard-code it, so you will probably want to pull it from an environment variable, which is what minimal.json does.
  2. ssh_username is required, generally this value should be root. All Linode images use root, except for linode/containerlinux which uses core.

Development

HashiCorp provides excellent guidance on how to build, use, and debug plugins:

Tests

Tests can be run in the following ways:

  • make test This will run all unittests except and will not fail if acceptance tests against the actual Linode API are skipped.
  • LINODE_TOKEN=... make testacc This will run all unittests and will fail if acceptance tests aginst the actual Linode API do not succeed. A LINODE_TOKEN must be set in the environment.

Helpers

Helper tools to interact with Linode objects and assist in development can be found in cmd/. These can be built with go build within their path. They all expect a LINODE_TOKEN environment variable to be set.

  • list-images - Lists all Linode images, both public and private
  • list-events - Lists the most recent page of events on the Linode account
  • list-kernels - Lists all Linode kernels
  • delete-image - Deletes a single Linode image whose numeric ID is required (delete_image 123 to remove image private/123)

The Linode CLI can also help during development. Install it by running pip install linode-cli.

Patching the Packer build tree

These instructions are an alternative to installing packer-builder-linode as a plugin.

To patch this plugin into Packer's source code, fetch this repository and Packer:

go get -d github.com/hashicorp/packer
go get -d github.com/linode/packer-builder-linode

Then copy the contents of linode/ and test/ to Packer's source tree:

cp -r linode $GOPATH/src/github.com/hashicorp/packer/builder/
cp -r test $GOPATH/src/github.com/hashicorp/packer/test

Then open up Packer's file command/plugin.go and add Linode as a new builder.

diff --git a/command/plugin.go b/command/plugin.go
index 62c909168..088c4af70 100644
--- a/command/plugin.go
+++ b/command/plugin.go
@@ -29,6 +29,7 @@ import (
        hyperonebuilder "github.com/hashicorp/packer/builder/hyperone"
        hypervisobuilder "github.com/hashicorp/packer/builder/hyperv/iso"
        hypervvmcxbuilder "github.com/hashicorp/packer/builder/hyperv/vmcx"
+       linodebuilder "github.com/hashicorp/packer/builder/linode"
        lxcbuilder "github.com/hashicorp/packer/builder/lxc"
        lxdbuilder "github.com/hashicorp/packer/builder/lxd"
        ncloudbuilder "github.com/hashicorp/packer/builder/ncloud"
@@ -109,6 +110,7 @@ var Builders = map[string]packer.Builder{
        "hyperone":            new(hyperonebuilder.Builder),
        "hyperv-iso":          new(hypervisobuilder.Builder),
        "hyperv-vmcx":         new(hypervvmcxbuilder.Builder),
+       "linode":              new(linodebuilder.Builder),
        "lxc":                 new(lxcbuilder.Builder),
        "lxd":                 new(lxdbuilder.Builder),
        "ncloud":              new(ncloudbuilder.Builder),

To verify that the Linode patching applied:

make dev
bin/packer build -var "linode-token=$LINODE_TOKEN" test/fixtures/builder-linode/minimal.json

Then you can go install Packer, and it will have support for the "linode" plugin.

Contribution Guidelines

Want to improve the Linode Packer Builder? Please start here.

Discussion / Help

Join us at #linodego on the gophers slack

About

Packer Builder plugin for Linode Images

License:Mozilla Public License 2.0


Languages

Language:Go 91.6%Language:Makefile 8.4%