From 0eb989607469deace8b5b4c41b7de560fe0dc443 Mon Sep 17 00:00:00 2001 From: Anurag <81210977+kranurag7@users.noreply.github.com> Date: Sun, 28 Jan 2024 01:29:01 +0530 Subject: [PATCH] pin packer version to 1.9.5 if packer version is greater than 1.9.5 in semver terms then downgrade packer. Signed-off-by: kranurag7 <81210977+kranurag7@users.noreply.github.com> --- images/capi/hack/ensure-packer.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/images/capi/hack/ensure-packer.sh b/images/capi/hack/ensure-packer.sh index 70c78b66ca..5f7d0a9dbd 100755 --- a/images/capi/hack/ensure-packer.sh +++ b/images/capi/hack/ensure-packer.sh @@ -38,8 +38,28 @@ source hack/utils.sh # invoked, so we are timeboxing it to 10 seconds. This shouldn't be the # case with Packer installed from Hashicorp releases, which should give # us a version number. This helps us distinguish the two Packer executables. -if (command -v packer && timeout 10 packer version) >/dev/null 2>&1; then exit 0; fi +if (command -v packer) >/dev/null 2>&1; then + echo "Packer is already installed, checking version..." + # if it's not the hashicorp packer, return "unexpected packer found" + if !(timeout 10 packer version) >/dev/null 2>&1; then + echo "unexpected packer found"; + echo "downloading hashicorp packer version v1.9.5" + fi + existing_packer_version=$(packer version | head -1 | cut -d 'v' -f 2; exit 0) + echo "existing packer version: $existing_packer_version" + if [ "$existing_packer_version" != "$_version" ]; then + echo "unsupported packer version ($existing_packer_version) found" + echo "current packer version: $existing_packer_version is not supported" + echo "Downgrading packer to ${_version}" + else + echo "Packer version is as expected" + echo "Packer version $existing_packer_version is already installed" + exit 0 + fi +fi + +echo "Installing packer v${_version} in .local/bin" mkdir -p .local/bin && cd .local/bin SED="sed"