Skip to content

Commit

Permalink
Merge remote-tracking branch 'batinicaz/bug/packer-version-check-1379…
Browse files Browse the repository at this point in the history
…' into deps-update
  • Loading branch information
denis256 committed May 22, 2024
2 parents 9c1259b + d3af93b commit 076e7b7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env: &env
MODULE_GCP_CI_VERSION: v0.1.1
MODULE_CI_CIRCLECI_HELPER_VERSION: v0.56.0
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
Expand Down
4 changes: 4 additions & 0 deletions examples/packer-docker-example/build.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ packer {
version = ">=v1.0.0"
source = "github.com/hashicorp/amazon"
}
docker = {
version = ">=v1.0.1"
source = "github.com/hashicorp/docker"
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion modules/packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
25 changes: 25 additions & 0 deletions modules/packer/packer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 076e7b7

Please sign in to comment.