Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-22440 The vm image list result can contain multiple versions but we need only the latest #25

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /bin
RUN apk update && apk add bash coreutils jq curl

ADD ./azure-copy /bin/
ADD ./azure-get-vm-image-version /bin/
ADD ./azure-get-latest-vm-image-version /bin/

RUN curl -Lsf https://github.com/hortonworks/pollprogress/releases/download/0.2.4/pollprogress_0.2.4_Linux_x86_64.tgz | tar -xz -C /bin
ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/azure/bin
Expand Down
46 changes: 46 additions & 0 deletions azure-get-latest-vm-image-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

: ${AZURE_IMAGE_PUBLISHER?= required}
: ${AZURE_IMAGE_OFFER?= required}
: ${AZURE_IMAGE_SKU?= required}

LOG_FILE=azure_get_latest_vm_image_version.log

log() {
MESSAGE=$1
echo "$(date '+%d/%m/%Y %H:%M:%S') - $MESSAGE " >> $LOG_FILE
}

debug() {
[[ "$DEBUG" ]] && echo "-----> $*" 1>&2
}

alias r="source $BASH_SOURCE"

azure_login() {
if [[ "$ARM_CLIENT_ID" ]] && [[ "$ARM_CLIENT_SECRET" ]]; then
az login --username $ARM_CLIENT_ID --password $ARM_CLIENT_SECRET --service-principal --tenant $ARM_TENANT_ID
fi
}

azure_get_latest_vm_image_version() {
log "Lookup latest VM image version by publisher=$AZURE_IMAGE_PUBLISHER offer=$AZURE_IMAGE_OFFER and sku=$AZURE_IMAGE_SKU"

VERSION=$(az vm image list --publisher $AZURE_IMAGE_PUBLISHER --offer $AZURE_IMAGE_OFFER --sku $AZURE_IMAGE_SKU --all | jq -r --arg publisher $AZURE_IMAGE_PUBLISHER --arg offer $AZURE_IMAGE_OFFER --arg sku $AZURE_IMAGE_SKU '.[] | select(.publisher == $publisher and .offer == $offer and .sku == $sku) | .version' | sort -u | tail -n 1)

log "Latest VM image version: $VERSION"

if [ -z $VERSION ]; then
echo "Failed to get latest vm image version!" 1>&2
exit 1
fi
echo $VERSION
}

main() {
: ${DEBUG:=1}
azure_login
azure_get_latest_vm_image_version > azure_get_latest_vm_image_version.out
}

[[ "$0" == "$BASH_SOURCE" ]] && main "$@"
48 changes: 0 additions & 48 deletions azure-get-vm-image-version

This file was deleted.