diff --git a/CHANGELOG.md b/CHANGELOG.md index 644e991..dc6a51a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,4 +2,5 @@ ## 1.0.0 -Copy codebase from https://github.com/UpCloudLtd/upcloud-packer +* Upgrade to Packer 1.7.0 +* Copy codebase from https://github.com/UpCloudLtd/upcloud-packer diff --git a/Makefile b/Makefile index 2c17af6..e196237 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,6 @@ build: install: build mkdir -p ~/.packer.d/plugins - install ./packer-plugin-upcloud ~/.packer.d/plugins/packer-builder-upcloud + install ./packer-plugin-upcloud ~/.packer.d/plugins/ .PHONY: default test test_integration lint build install diff --git a/README.md b/README.md index 6608b01..4774e8e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,36 @@ # UpCloud Packer builder ![Build Status](https://github.com/UpCloudLtd/packer-plugin-upcloud/workflows/test/badge.svg) +![Release Status](https://github.com/UpCloudLtd/packer-plugin-upcloud/workflows/test/release.svg) This is a builder plugin for Packer which can be used to generate storage templates on UpCloud. It utilises the [UpCloud Go API](https://github.com/UpCloudLtd/upcloud-go-api) to interface with the UpCloud API. ## Installation +### Installing using Packer Packet Manager + +In order to use `packer init` you need to have Packer version ">=1.7.0" installed. Config template should be in `hcl` format and contains `required_plugins` block. For example: + +```hcl +... +packer { + required_plugins { + upcloud = { + version = ">=v1.0.0" + source = "github.com/UpCloudLtd/upcloud" + } + } +} +... +``` + +Runn following command and check the output: +```sh +$ packer init examples/basic_example.pkr.hcl + +Installed plugin github.com/upcloudltd/upcloud v1.0.0 in "/Users/johndoe/.packer.d/plugins/github.com/upcloudltd/upcloud/packer-plugin-upcloud_v1.0.0_x5.0_darwin_amd64" +``` + ### Pre-built binaries You can download the pre-built binaries of the plugin from the [GitHub releases page](https://github.com/UpCloudLtd/packer-plugin-upcloud/releases). Just download the archive for your operating system and architecture, unpack it, and place the binary in the appropriate location, e.g. on Linux `~/.packer.d/plugins`. Make sure the file is executable, then install [Packer](https://www.packer.io/). @@ -24,7 +49,7 @@ Run the following commands to download and install the plugin from the source. git clone https://github.com/UpCloudLtd/packer-plugin-upcloud cd packer-plugin-upcloud go build -cp packer-plugin-upcloud ~/.packer.d/plugins/packer-builder-upcloud +cp packer-plugin-upcloud ~/.packer.d/plugins/ ``` ## Usage diff --git a/examples/basic_example.pkr.hcl b/examples/basic_example.pkr.hcl index 4aded04..37685cf 100644 --- a/examples/basic_example.pkr.hcl +++ b/examples/basic_example.pkr.hcl @@ -8,6 +8,15 @@ variable "password" { default = "${env("UPCLOUD_API_PASSWORD")}" } +packer { + required_plugins { + upcloud = { + version = ">=v1.0.0" + source = "github.com/UpCloudLtd/upcloud" + } + } +} + source "upcloud" "test" { username = "${var.username}" password = "${var.password}" diff --git a/go.mod b/go.mod index bb91e8c..802534a 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/UpCloudLtd/upcloud-go-api v0.0.0-20210127073406-2964ed7e5972 github.com/agext/levenshtein v1.2.3 // indirect github.com/armon/go-metrics v0.3.6 // indirect - github.com/aws/aws-sdk-go v1.37.13 // indirect + github.com/aws/aws-sdk-go v1.37.14 // indirect github.com/fatih/color v1.10.0 // indirect github.com/frankban/quicktest v1.11.3 // indirect github.com/gofrs/flock v0.8.0 // indirect @@ -40,7 +40,7 @@ require ( github.com/zclconf/go-cty v1.7.1 go.opencensus.io v0.22.6 // indirect golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df - golang.org/x/oauth2 v0.0.0-20210216194517-16ff1888fd2e // indirect + golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99 // indirect golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b // indirect golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect diff --git a/go.sum b/go.sum index 8808701..831a8a8 100644 --- a/go.sum +++ b/go.sum @@ -147,6 +147,8 @@ github.com/aws/aws-sdk-go v1.36.5 h1:SouM2ar1A8f+3DYWW622sDdqkkZAO3ha4j8GQjiPLFg github.com/aws/aws-sdk-go v1.36.5/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.37.13 h1:7w1gJHJdpMfv+JbedCeOkQrYu46k0j01ULpv7oLfb3U= github.com/aws/aws-sdk-go v1.37.13/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= +github.com/aws/aws-sdk-go v1.37.14 h1:thuR1hd1doCvsaMDYDMhqCGSmw39bSvZaw+DPGhMm5w= +github.com/aws/aws-sdk-go v1.37.14/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -888,6 +890,8 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210113205817-d3ed898aa8a3/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210216194517-16ff1888fd2e h1:xxTKAjlluPXFVQnUNoBO7OvmNNE/RpmyUeLVFSYiQQ0= golang.org/x/oauth2 v0.0.0-20210216194517-16ff1888fd2e/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99 h1:5vD4XjIc0X5+kHZjx4UecYdjA6mJo+XXNoaW0EjU5Os= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/main.go b/main.go index 46f6c72..897d9e6 100644 --- a/main.go +++ b/main.go @@ -1,20 +1,20 @@ package main import ( + "fmt" + "os" + upcloud "github.com/UpCloudLtd/packer-plugin-upcloud/builder/upcloud" "github.com/hashicorp/packer-plugin-sdk/plugin" ) func main() { - server, err := plugin.Server() + pps := plugin.NewSet() + pps.RegisterBuilder(plugin.DEFAULT_NAME, new(upcloud.Builder)) + err := pps.Run() if err != nil { - panic(err) - } - - if err := server.RegisterBuilder(new(upcloud.Builder)); err != nil { - panic(err) + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) } - - server.Serve() }