Skip to content

Commit

Permalink
Get Azure image id (part of CB-22440)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Solya committed Aug 4, 2023
1 parent ddfea34 commit 4402147
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ WORKDIR /bin
RUN apk update && apk add bash coreutils jq curl

ADD ./azure-copy /bin/
ADD ./azure-get-rhel8-source-image-id /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
39 changes: 39 additions & 0 deletions azure-get-rhel8-source-image-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

: ${AZURE_IMAGE_PUBLISHER?= required}
: ${AZURE_IMAGE_OFFER?= required}
: ${AZURE_IMAGE_SKU?= required}
: ${AZURE_IMAGE_VERSION?= required}
#AZURE_IMAGE_PUBLISHER="RedHat"
#AZURE_IMAGE_OFFER="rhel-byos"
#AZURE_IMAGE_SKU="rhel-lvm88"
#AZURE_IMAGE_VERSION="8.8"
#SKIP_IF_CONTAINS_STRING="gen2" Where the souruce image id contains this substring will be skipped.

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_rhel8_source_image_id() {
if [[ "$SKIP_IF_CONTAINS_STRING" ]]; then
az vm image list --publisher $AZURE_IMAGE_PUBLISHER --offer $AZURE_IMAGE_OFFER --all | jq -r --arg version $AZURE_IMAGE_VERSION --arg offer $AZURE_IMAGE_OFFER --arg skipthis $SKIP_IF_CONTAINS_STRING '.[] | select(.version | startswith($version)) | select(.urn | contains($offer)) | select(.urn | contains($skipthis) | not) | .urn'
else
az vm image list --publisher $AZURE_IMAGE_PUBLISHER --offer $AZURE_IMAGE_OFFER --all | jq -r --arg version $AZURE_IMAGE_VERSION --arg offer $AZURE_IMAGE_OFFER '.[] | select(.version | startswith($version)) | select(.urn | contains($offer)) | .urn'
fi
}

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

[[ "$0" == "$BASH_SOURCE" ]] && main "$@"

0 comments on commit 4402147

Please sign in to comment.