Skip to content

Commit

Permalink
Merge pull request #212 from linode/dev
Browse files Browse the repository at this point in the history
v1.4.1
  • Loading branch information
zliang-akamai authored Mar 26, 2024
2 parents 5d07271 + fc395d8 commit f44199a
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ runtime in order to build packer with the Linode plugin.

1. This project always releases from the latest version of golang.
[Install go](https://golang.org/doc/install#install) To properly build from
source, you need to have golang >= 1.20.
source, you need to have golang >= 1.21.

## Setting up Linode plugin for dev

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ensure-docs-compiled.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Ensure Docs are Compiled
on:
push:
pull_request:
jobs:
ensure-docs-compiled:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-test-multiplatform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- run: |
echo "Testing with Go ${{ needs.get-go-version.outputs.go-version }}"
make unit-test
go test -race -count 1 ./builder/linode/... -timeout=3m -v
windows-go-tests:
needs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ main
dist/*
packer-plugin-linode
.docs
docs-partials
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1.20.11
1.21.8

10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
NAME=linode
BINARY=packer-plugin-${NAME}
PLUGIN_FQN="$(shell grep -E '^module' <go.mod | sed -E 's/module *//')"
COUNT?=1
UNIT_TEST_TARGET?=$(shell go list ./builder/...)
HASHICORP_PACKER_PLUGIN_SDK_VERSION?=$(shell go list -m github.com/hashicorp/packer-plugin-sdk | cut -d " " -f2)
Expand All @@ -11,16 +12,16 @@ PACKER_SDC_REPO ?= github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc
install: dev

.PHONY: dev
dev: build
@mkdir -p ~/.packer.d/plugins/
@mv ${BINARY} ~/.packer.d/plugins/${BINARY}
dev:
@go build -ldflags="-X '${PLUGIN_FQN}/version.VersionPrerelease=dev'" -o '${BINARY}'
packer plugins install --path ${BINARY} "$(shell echo "${PLUGIN_FQN}" | sed 's/packer-plugin-//')"

.PHONY: build
build: fmtcheck
@go build -o ${BINARY}

.PHONY: test
test: dev fmtcheck acctest
test: fmtcheck unit-test int-test

.PHONY: install-packer-sdc
install-packer-sdc: ## Install packer sofware development command
Expand Down Expand Up @@ -71,3 +72,4 @@ deps: install-packer-sdc
clean:
@rm -rf .docs
@rm -rf ./packer-plugin-linode
@rm -rf ./docs-partials
3 changes: 2 additions & 1 deletion builder/linode/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/packer-plugin-linode/helper"
)

// The unique ID for this builder.
Expand All @@ -39,7 +40,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) (ret packersdk.Artifact, err error) {
ui.Say("Running builder ...")

client := newLinodeClient(b.config.PersonalAccessToken)
client := helper.NewLinodeClient(b.config.PersonalAccessToken)

if err != nil {
ui.Error(err.Error())
Expand Down
4 changes: 2 additions & 2 deletions builder/linode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
"github.com/linode/packer-plugin-linode/helper"
)

type InterfaceIPv4 struct {
Expand All @@ -35,11 +36,10 @@ type Interface struct {

type Config struct {
common.PackerConfig `mapstructure:",squash"`
helper.LinodeCommon `mapstructure:",squash"`
ctx interpolate.Context
Comm communicator.Config `mapstructure:",squash"`

PersonalAccessToken string `mapstructure:"linode_token"`

Interfaces []Interface `mapstructure:"interface"`
Region string `mapstructure:"region"`
AuthorizedKeys []string `mapstructure:"authorized_keys"`
Expand Down
4 changes: 2 additions & 2 deletions builder/linode/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions builder/linode/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/communicator"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
"github.com/linode/packer-plugin-linode/helper"
)

func TestPrepare(t *testing.T) {
Expand All @@ -15,12 +16,15 @@ func TestPrepare(t *testing.T) {
}

config := &Config{
ctx: interpolate.Context{},
Comm: communicator.Config{SSH: data},
PersonalAccessToken: "test-linode-access-token",
Region: "us-ord",
InstanceType: "g6-standard-1",
Image: "linode/debian10",
LinodeCommon: helper.LinodeCommon{
PersonalAccessToken: "test-linode-access-token",
},
ctx: interpolate.Context{},
Comm: communicator.Config{SSH: data},

Region: "us-ord",
InstanceType: "g6-standard-1",
Image: "linode/debian10",
}

warnings, err := config.Prepare()
Expand Down
3 changes: 2 additions & 1 deletion builder/linode/step_create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/linodego"
"github.com/linode/packer-plugin-linode/helper"
)

type stepCreateImage struct {
Expand All @@ -19,7 +20,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
instance := state.Get("instance").(*linodego.Instance)

handleError := func(prefix string, err error) multistep.StepAction {
return errorHelper(state, ui, prefix, err)
return helper.ErrorHelper(state, ui, prefix, err)
}

creationPoller, err := s.client.NewEventPoller(
Expand Down
3 changes: 2 additions & 1 deletion builder/linode/step_create_linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/linodego"
"github.com/linode/packer-plugin-linode/helper"
)

type stepCreateLinode struct {
Expand Down Expand Up @@ -41,7 +42,7 @@ func (s *stepCreateLinode) Run(ctx context.Context, state multistep.StateBag) mu
ui := state.Get("ui").(packersdk.Ui)

handleError := func(prefix string, err error) multistep.StepAction {
return errorHelper(state, ui, prefix, err)
return helper.ErrorHelper(state, ui, prefix, err)
}

ui.Say("Creating Linode...")
Expand Down
3 changes: 2 additions & 1 deletion builder/linode/step_create_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/packer-plugin-linode/helper"
"golang.org/x/crypto/ssh"
)

Expand All @@ -27,7 +28,7 @@ func (s *StepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult
config := state.Get("config").(*Config)

handleError := func(prefix string, err error) multistep.StepAction {
return errorHelper(state, ui, prefix, err)
return helper.ErrorHelper(state, ui, prefix, err)
}

if config.Comm.SSHPrivateKeyFile != "" {
Expand Down
3 changes: 2 additions & 1 deletion builder/linode/step_shutdown_linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/linodego"
"github.com/linode/packer-plugin-linode/helper"
)

type stepShutdownLinode struct {
Expand All @@ -18,7 +19,7 @@ func (s *stepShutdownLinode) Run(ctx context.Context, state multistep.StateBag)
instance := state.Get("instance").(*linodego.Instance)

handleError := func(prefix string, err error) multistep.StepAction {
return errorHelper(state, ui, prefix, err)
return helper.ErrorHelper(state, ui, prefix, err)
}

ui.Say("Shutting down Linode...")
Expand Down
37 changes: 16 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
module github.com/linode/packer-plugin-linode

go 1.20
go 1.21

require (
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/hcl/v2 v2.20.0
github.com/hashicorp/packer-plugin-sdk v0.5.2
github.com/linode/linodego v1.29.0
github.com/zclconf/go-cty v1.13.3
golang.org/x/crypto v0.19.0
golang.org/x/oauth2 v0.17.0
)

require (
github.com/linode/linodego v1.31.0
github.com/mitchellh/mapstructure v1.5.0
github.com/stretchr/testify v1.8.4
github.com/zclconf/go-cty v1.13.3
golang.org/x/crypto v0.21.0
golang.org/x/oauth2 v0.18.0
)

require (
Expand All @@ -31,15 +27,14 @@ require (
github.com/aws/aws-sdk-go v1.44.114 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dylanmei/iso8601 v0.1.0 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-resty/resty/v2 v2.11.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-resty/resty/v2 v2.12.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
Expand Down Expand Up @@ -83,27 +78,27 @@ require (
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db // indirect
github.com/pkg/sftp v1.13.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/zclconf/go-cty => github.com/nywilken/go-cty v1.13.3 // added by packer-sdc fix as noted in github.com/hashicorp/packer-plugin-sdk/issues/187
Loading

0 comments on commit f44199a

Please sign in to comment.