Skip to content

Commit 8b7b506

Browse files
authored
Merge pull request #1383 from kranurag7/kr/pin-packer-version
pin packer version to 1.9.5
2 parents 3e29ae4 + 0eb9896 commit 8b7b506

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

images/capi/hack/ensure-packer.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,28 @@ source hack/utils.sh
3838
# invoked, so we are timeboxing it to 10 seconds. This shouldn't be the
3939
# case with Packer installed from Hashicorp releases, which should give
4040
# us a version number. This helps us distinguish the two Packer executables.
41-
if (command -v packer && timeout 10 packer version) >/dev/null 2>&1; then exit 0; fi
4241

42+
if (command -v packer) >/dev/null 2>&1; then
43+
echo "Packer is already installed, checking version..."
44+
# if it's not the hashicorp packer, return "unexpected packer found"
45+
if !(timeout 10 packer version) >/dev/null 2>&1; then
46+
echo "unexpected packer found";
47+
echo "downloading hashicorp packer version v1.9.5"
48+
fi
49+
existing_packer_version=$(packer version | head -1 | cut -d 'v' -f 2; exit 0)
50+
echo "existing packer version: $existing_packer_version"
51+
if [ "$existing_packer_version" != "$_version" ]; then
52+
echo "unsupported packer version ($existing_packer_version) found"
53+
echo "current packer version: $existing_packer_version is not supported"
54+
echo "Downgrading packer to ${_version}"
55+
else
56+
echo "Packer version is as expected"
57+
echo "Packer version $existing_packer_version is already installed"
58+
exit 0
59+
fi
60+
fi
61+
62+
echo "Installing packer v${_version} in .local/bin"
4363
mkdir -p .local/bin && cd .local/bin
4464

4565
SED="sed"

0 commit comments

Comments
 (0)