Last active
September 28, 2020 15:05
-
-
Save javitoHertfy/a277092b33aff18195bd083f4b7faf96 to your computer and use it in GitHub Desktop.
This code rumps up your application given the name of the web app, resource group, the duration of the traffic-routing and the percentage of traffic you want to route every time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WEBAPP=$1 | |
RESOURCEGROUP=$2 | |
MINUTES=$3 | |
RAMPUPPERCENTAGE=$4 | |
regularExpression='^[0-9]+$' | |
if ! ([[ $MINUTES =~ $regularExpression ]] && [[ $RAMPUPPERCENTAGE =~ $regularExpression ]]); | |
then | |
echo "error: Not a number" >&2; | |
else | |
secsToRumpUp=$(awk "BEGIN {print ($RAMPUPPERCENTAGE/100)*($MINUTES*60)}") | |
rumpup=$RAMPUPPERCENTAGE; | |
incremental=$(awk "BEGIN {print ($MINUTES*60)/$secsToRumpUp}") | |
echo "Your webapp $WEBAPP in the resource group $RESOURCEGROUP will be traffic-routed in the next $MINUTES minutes every $secsToRumpUp secs a $RAMPUPPERCENTAGE %"; | |
for (( c=0; c<$incremental; c++ )) | |
do | |
echo "Incrementing staging slot to $rumpup %"; | |
az webapp traffic-routing set --distribution staging=$rumpup --name $WEBAPP --resource-group $RESOURCEGROUP | |
sleep "$secsToRumpUp" | |
let "rumpup += RAMPUPPERCENTAGE"; | |
done | |
echo "Rolling back traffic-routing..." | |
az webapp traffic-routing clear --name $WEBAPP --resource-group $RESOURCEGROUP | |
echo "Swapping $WEBAPP" | |
az webapp deployment slot swap -g $RESOURCEGROUP -n $WEBAPP --slot staging --target-slot production | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment