From a298ae7955fc4b0c04bf0056b7e32630f9968f0c Mon Sep 17 00:00:00 2001 From: batinica Date: Sat, 16 Dec 2023 09:13:51 +0000 Subject: [PATCH 1/3] fix: handle updated packer version output from 1.10 --- modules/packer/packer.go | 9 ++++++++- modules/packer/packer_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/modules/packer/packer.go b/modules/packer/packer.go index 4045c0f99..3a4534e05 100644 --- a/modules/packer/packer.go +++ b/modules/packer/packer.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "regexp" + "strings" "sync" "time" @@ -186,10 +187,11 @@ func hasPackerInit(t testing.TestingT, options *Options) (bool, error) { Env: options.Env, WorkingDir: options.WorkingDir, } - localVersion, err := shell.RunCommandAndGetOutputE(t, cmd) + versionCmdOutput, err := shell.RunCommandAndGetOutputE(t, cmd) if err != nil { return false, err } + localVersion := trimPackerVersion(versionCmdOutput) thisVersion, err := version.NewVersion(localVersion) if err != nil { return false, err @@ -262,3 +264,8 @@ func formatPackerArgs(options *Options) []string { return append(args, options.Template) } + +// From packer 1.10 the -version command output is prefixed with Packer v +func trimPackerVersion(versionCmdOutput string) string { + return strings.Replace(versionCmdOutput, "Packer v", "", -1) +} diff --git a/modules/packer/packer_test.go b/modules/packer/packer_test.go index 3c76cb922..a13297dea 100644 --- a/modules/packer/packer_test.go +++ b/modules/packer/packer_test.go @@ -174,3 +174,28 @@ func TestFormatPackerArgs(t *testing.T) { assert.Equal(t, strings.Join(args, " "), test.expected) } } + +func TestTrimPackerVersion(t *testing.T) { + t.Parallel() + + tests := []struct { + versionOutput string + expected string + }{ + { + // Pre 1.10 output + versionOutput: "1.7.0", + expected: "1.7.0", + }, + { + // From 1.10 matches the output of packer version + versionOutput: "Packer v1.10.0", + expected: "1.10.0", + }, + } + + for _, test := range tests { + out := trimPackerVersion(test.versionOutput) + assert.Equal(t, test.expected, out) + } +} From 2d7c135e5a71aab3b46126ef5c50555ba3a3659f Mon Sep 17 00:00:00 2001 From: batinica Date: Tue, 26 Dec 2023 19:43:35 +0000 Subject: [PATCH 2/3] ci: bump packer version to 1.10 for integration tests --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 162c7a90b..91074a918 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ env: &env MODULE_CI_VERSION: v0.46.0 MODULE_GCP_CI_VERSION: v0.1.1 TERRAFORM_VERSION: 1.5.7 - PACKER_VERSION: 1.7.4 + PACKER_VERSION: 1.10.0 TERRAGRUNT_VERSION: v0.52.0 OPA_VERSION: v0.33.1 GO_VERSION: 1.21.1 From d3af93bd4b477127b6acb44ae257f80204455802 Mon Sep 17 00:00:00 2001 From: batinica Date: Thu, 4 Jan 2024 19:42:31 +0000 Subject: [PATCH 3/3] fix: add docker plugin requirement to packer-docker-example --- examples/packer-docker-example/build.pkr.hcl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/packer-docker-example/build.pkr.hcl b/examples/packer-docker-example/build.pkr.hcl index afedc3279..f55003731 100644 --- a/examples/packer-docker-example/build.pkr.hcl +++ b/examples/packer-docker-example/build.pkr.hcl @@ -4,6 +4,10 @@ packer { version = ">=v1.0.0" source = "github.com/hashicorp/amazon" } + docker = { + version = ">=v1.0.1" + source = "github.com/hashicorp/docker" + } } }