Last active
February 18, 2022 18:46
-
-
Save danielscholl/95f5442c28bea8b9d98302361ee485d3 to your computer and use it in GitHub Desktop.
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 | |
# Random string generator - don't change this. | |
RAND=$(echo $((RANDOM%9999+1000))) | |
LOCATION="eastus" | |
RESOURCEGROUP="container-deployment-$RAND" | |
if [ -z $1 ]; then | |
tput setaf 1; echo 'ERROR: URL Location of Deployment Script not provided' ; tput sgr0 | |
usage; | |
else | |
echo "Deployment Script: $1" | |
fi | |
# Get commandline for Azure CLI | |
az=$(which az) | |
# Fetch the CloudShell subscription ID | |
subId=$($az account show --query id -o tsv 2>/dev/null) | |
echo "===============================================================================================================================================================" | |
if [ ! "$($az group show -n $RESOURCEGROUP --query tags.currentStatus -o tsv 2>/dev/null)" = "groupCreated" ]; then | |
# Deploy the resource group and update Status Tag | |
echo "Deploying the resource group." | |
$az group create -g "$RESOURCEGROUP" -l "$LOCATION" -o none 2>/dev/null | |
$az group update -n $RESOURCEGROUP --tag currentStatus=groupCreated 2>/dev/null | |
echo "done." | |
fi | |
echo "===============================================================================================================================================================" | |
if [ ! "$($az group show -n $RESOURCEGROUP --query tags.currentStatus -o tsv 2>/dev/null)" = "containerCreated" ]; then | |
echo "Deploying the container (might take 2-3 minutes)..." | |
$az container create -g $RESOURCEGROUP --name containerdeploy --image danielscholl/container-deploy --restart-policy Never --environment-variables subId=$subId RANDOM_NUMBER=$RAND SETUP_SCRIPT=$1 -o none 2>/dev/null | |
$az group update -n $RESOURCEGROUP --tag currentStatus=containerCreated 2>/dev/null | |
echo "done." | |
fi | |
echo "===============================================================================================================================================================" | |
echo "===============================================================================================================================================================" | |
echo "If cloudshell times out copy this command and run it again when cloud shell is restarted:" | |
echo " az container logs --follow -n containerDeploy -g $RESOURCEGROUP" | |
echo "===============================================================================================================================================================" | |
echo "===============================================================================================================================================================" | |
if [ "$($az group show -n $RESOURCEGROUP --query tags.currentStatus -o tsv 2>/dev/null)" = "containerCreated" ]; then | |
echo "Tail Logs" | |
$az container logs -n containerDeploy -g $RESOURCEGROUP 2>/dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment