X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=blobdiff_plain;f=shell%2Fpacker-validate.sh;h=86cf8de84f1286ad58fcadd47b1cfe0a44b93723;hb=907c06f064252914e44b92476ea4b12c07d99ebb;hp=61e14313ac6739c6e7e5fc5fa3f0f762bef4820e;hpb=37f05c74e577373c062563634176f8435c6a939a;p=releng%2Fglobal-jjb.git diff --git a/shell/packer-validate.sh b/shell/packer-validate.sh index 61e14313..86cf8de8 100644 --- a/shell/packer-validate.sh +++ b/shell/packer-validate.sh @@ -16,24 +16,47 @@ echo "---> packer-validate.sh" # Ensure we fail the job if any steps fail. set -eu -o pipefail +# Functions to compare semantic versions x.y.z +version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; } + PACKER_LOGS_DIR="$WORKSPACE/archives/packer" mkdir -p "$PACKER_LOGS_DIR" export PATH="${WORKSPACE}/bin:$PATH" - +set -x cd packer -varfiles=(vars/*.json common-packer/vars/*.json) -templates=(templates/*.json) + +if version_ge "$PACKER_VERSION" "1.9.0"; then + varfiles=(vars/*.pkrvars.hcl common-packer/vars/*.pkrvars.hcl) + templates=(templates/*.pkr.hcl) +else + varfiles=(vars/*.json common-packer/vars/*.json) + templates=(templates/*.json) +fi for varfile in "${varfiles[@]}"; do - # cloud-env.json is a file containing credentials which is pulled in via - # CLOUDENV variable so skip it here. Also handle the case where a project - # has not vars/*.json file. - if [[ "$varfile" == *"cloud-env.json"* ]] || [[ "$varfile" == 'vars/*.json' ]]; then + # cloud-env.{json,pkrvars.hcl} is a file containing credentials which is + # pulled in via CLOUDENV variable so skip it here. Also handle case + # where a project does not vars/*.{json,pkrvars.hcl} file. + if [[ "$varfile" == *"cloud-env.json"* ]] || \ + [[ "$varfile" == "vars/*.json" ]] || \ + [[ "$varfile" == *"cloud-env.pkrvars.hcl"* ]] || \ + [[ "$varfile" == *"cloud-env-aws.pkrvars.hcl"* ]] || \ + [[ "$varfile" == "vars/*.pkrvars.hcl" ]]; then continue fi echo "-----> Testing varfile: $varfile" for template in "${templates[@]}"; do + if [[ "$template" == *"variables.pkr.hcl"* ]] || \ + [[ "$template" == *"variables.auto.pkr.hcl"* ]]; then + continue + fi + + if [[ "${template#*.}" == "pkr.hcl" ]]; then + echo "packer init $template ..." + packer.io init "$template" + fi + export PACKER_LOG="yes" export PACKER_LOG_PATH="$PACKER_LOGS_DIR/packer-validate-${varfile##*/}-${template##*/}.log" if output=$(packer.io validate -var-file="$CLOUDENV" -var-file="$varfile" "$template"); then