Skip to content
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
29 changes: 9 additions & 20 deletions samples/aci-blob-storage/python/bicep/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ SUBSCRIPTION_NAME=$(az account show --query name --output tsv)
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
IMAGE_NAME="vacation-planner"
IMAGE_TAG="v1"
ENVIRONMENT=$(az account show --query environmentName --output tsv)

echo "=================================================="
echo "DEBUG: Starting bicep deployment for aci-blob-storage"
Expand All @@ -26,26 +25,16 @@ echo "=================================================="

# Change the current directory to the script's directory
cd "$CURRENT_DIR" || exit

# Choose the appropriate CLI based on the environment
if [[ $ENVIRONMENT == "LocalStack" ]]; then
echo "Using azlocal for LocalStack emulator environment."
AZ="azlocal"
else
echo "Using standard az for AzureCloud environment."
AZ="az"
fi

# Validates if the resource group exists in the subscription, if not creates it
echo "Checking if resource group [$RESOURCE_GROUP_NAME] exists in the subscription [$SUBSCRIPTION_NAME]..."
$AZ group show --name $RESOURCE_GROUP_NAME &>/dev/null
az group show --name $RESOURCE_GROUP_NAME &>/dev/null

if [[ $? != 0 ]]; then
echo "No resource group [$RESOURCE_GROUP_NAME] exists in the subscription [$SUBSCRIPTION_NAME]"
echo "Creating resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]..."

# Create the resource group
$AZ group create \
az group create \
--name $RESOURCE_GROUP_NAME \
--location $LOCATION \
--only-show-errors 1>/dev/null
Expand All @@ -68,29 +57,29 @@ fi
# Create ACR first so we can push the image
ACR_NAME="${PREFIX}aciacr${SUFFIX}"
echo "Creating ACR [$ACR_NAME] for image push..."
$AZ acr create \
az acr create \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--location "$LOCATION" \
--sku Basic \
--admin-enabled true \
--only-show-errors 1>/dev/null

LOGIN_SERVER=$($AZ acr show \
LOGIN_SERVER=$(az acr show \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--query "loginServer" \
--output tsv \
--only-show-errors)

ACR_USERNAME=$($AZ acr credential show \
ACR_USERNAME=$(az acr credential show \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--query "username" \
--output tsv \
--only-show-errors)

ACR_PASSWORD=$($AZ acr credential show \
ACR_PASSWORD=$(az acr credential show \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--query "passwords[0].value" \
Expand Down Expand Up @@ -130,7 +119,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then
if [[ $USE_WHAT_IF == 1 ]]; then
# Execute a deployment What-If operation at resource group scope.
echo "Previewing changes deployed by Bicep template [$TEMPLATE]..."
$AZ deployment group what-if \
az deployment group what-if \
--resource-group $RESOURCE_GROUP_NAME \
--template-file $TEMPLATE \
--parameters $PARAMETERS \
Expand All @@ -148,7 +137,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then
else
# Validate the Bicep template
echo "Validating Bicep template [$TEMPLATE]..."
output=$($AZ deployment group validate \
output=$(az deployment group validate \
--resource-group $RESOURCE_GROUP_NAME \
--template-file $TEMPLATE \
--parameters $PARAMETERS \
Expand All @@ -169,7 +158,7 @@ fi

# Deploy the Bicep template
echo "Deploying Bicep template [$TEMPLATE]..."
if DEPLOYMENT_OUTPUTS=$($AZ deployment group create \
if DEPLOYMENT_OUTPUTS=$(az deployment group create \
--resource-group $RESOURCE_GROUP_NAME \
--only-show-errors \
--template-file $TEMPLATE \
Expand Down
15 changes: 7 additions & 8 deletions samples/aci-blob-storage/python/scripts/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ ACI_GROUP_ADVANCED="${PREFIX}-aci-planner-advanced"
KEY_VAULT_NAME="${PREFIX}acikv"
ACR_NAME="${PREFIX}aciacr"
STORAGE_ACCOUNT_NAME="${PREFIX}acistorage"
ENVIRONMENT=$(az account show --query environmentName --output tsv)

# Choose the appropriate CLI based on the environment
if [[ $ENVIRONMENT == "LocalStack" ]]; then
Expand All @@ -31,13 +30,13 @@ echo ""

# 1. Delete ACI container groups (basic + advanced)
echo "[1/5] Deleting ACI container groups..."
$AZ container delete \
az container delete \
--name "$ACI_GROUP_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--yes \
--only-show-errors 2>/dev/null && echo " Deleted: $ACI_GROUP_NAME" || echo " Skipped: $ACI_GROUP_NAME (not found)"

$AZ container delete \
az container delete \
--name "$ACI_GROUP_ADVANCED" \
--resource-group "$RESOURCE_GROUP_NAME" \
--yes \
Expand All @@ -46,7 +45,7 @@ echo ""

# 2. Delete ACR
echo "[2/5] Deleting ACR [$ACR_NAME]..."
$AZ acr delete \
az acr delete \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--yes \
Expand All @@ -55,18 +54,18 @@ echo ""

# 3. Delete Key Vault (delete + purge to release the vault name)
echo "[3/5] Deleting Key Vault [$KEY_VAULT_NAME]..."
$AZ keyvault delete \
az keyvault delete \
--name "$KEY_VAULT_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--only-show-errors 2>/dev/null && echo " Deleted: $KEY_VAULT_NAME" || echo " Skipped: $KEY_VAULT_NAME (not found)"
$AZ keyvault purge \
az keyvault purge \
--name "$KEY_VAULT_NAME" \
--only-show-errors 2>/dev/null && echo " Purged: $KEY_VAULT_NAME" || true
echo ""

# 4. Delete Storage Account
echo "[4/5] Deleting Storage Account [$STORAGE_ACCOUNT_NAME]..."
$AZ storage account delete \
az storage account delete \
--name "$STORAGE_ACCOUNT_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--yes \
Expand All @@ -75,7 +74,7 @@ echo ""

# 5. Delete Resource Group
echo "[5/5] Deleting Resource Group [$RESOURCE_GROUP_NAME]..."
$AZ group delete \
az group delete \
--name "$RESOURCE_GROUP_NAME" \
--yes \
--only-show-errors 2>/dev/null && echo " Deleted: $RESOURCE_GROUP_NAME" || echo " Skipped: $RESOURCE_GROUP_NAME (not found)"
Expand Down
39 changes: 14 additions & 25 deletions samples/aci-blob-storage/python/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,18 @@ ACI_GROUP_NAME="${PREFIX}-aci-planner"
IMAGE_NAME="vacation-planner"
IMAGE_TAG="v1"
LOGIN_NAME="paolo"
ENVIRONMENT=$(az account show --query environmentName --output tsv)
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"

# Change the current directory to the script's directory
cd "$CURRENT_DIR" || exit

# Choose the appropriate CLI based on the environment
if [[ $ENVIRONMENT == "LocalStack" ]]; then
echo "Using azlocal for LocalStack emulator environment."
AZ="azlocal"
else
echo "Using standard az for AzureCloud environment."
AZ="az"
fi

# =============================================================================
# Step 1: Create Resource Group
# =============================================================================
echo ""
echo "============================================================"
echo "Step 1: Creating resource group [$RESOURCE_GROUP_NAME]..."
echo "============================================================"
$AZ group create \
az group create \
--name $RESOURCE_GROUP_NAME \
--location $LOCATION \
--only-show-errors 1>/dev/null
Expand All @@ -63,7 +52,7 @@ echo ""
echo "============================================================"
echo "Step 2: Creating storage account [$STORAGE_ACCOUNT_NAME]..."
echo "============================================================"
$AZ storage account create \
az storage account create \
--name $STORAGE_ACCOUNT_NAME \
--location $LOCATION \
--resource-group $RESOURCE_GROUP_NAME \
Expand All @@ -84,7 +73,7 @@ echo ""
echo "============================================================"
echo "Step 3: Retrieving storage account key..."
echo "============================================================"
STORAGE_ACCOUNT_KEY=$($AZ storage account keys list \
STORAGE_ACCOUNT_KEY=$(az storage account keys list \
--account-name $STORAGE_ACCOUNT_NAME \
--resource-group $RESOURCE_GROUP_NAME \
--query "[0].value" \
Expand All @@ -104,7 +93,7 @@ echo ""
echo "============================================================"
echo "Step 4: Retrieving storage blob endpoint..."
echo "============================================================"
BLOB_ENDPOINT=$($AZ storage account show \
BLOB_ENDPOINT=$(az storage account show \
--name $STORAGE_ACCOUNT_NAME \
--resource-group $RESOURCE_GROUP_NAME \
--query "primaryEndpoints.blob" \
Expand Down Expand Up @@ -142,7 +131,7 @@ echo "Step 5: Creating blob container [$BLOB_CONTAINER_NAME]..."
echo "============================================================"
# Use --connection-string to ensure the correct endpoint is used
# (--account-name constructs its own hostname which may not match LocalStack's cert)
$AZ storage container create \
az storage container create \
--name $BLOB_CONTAINER_NAME \
--connection-string "$STORAGE_CONN_STRING" \
--only-show-errors 1>/dev/null
Expand All @@ -161,7 +150,7 @@ echo ""
echo "============================================================"
echo "Step 6: Creating Key Vault [$KEY_VAULT_NAME]..."
echo "============================================================"
KV_OUTPUT=$($AZ keyvault create \
KV_OUTPUT=$(az keyvault create \
--name "$KEY_VAULT_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--location "$LOCATION" \
Expand All @@ -186,7 +175,7 @@ echo "============================================================"
echo "Step 7: Storing storage connection string in Key Vault..."
echo "============================================================"
# Store the container-friendly connection string so ACI can reach LocalStack
$AZ keyvault secret set \
az keyvault secret set \
--vault-name "$KEY_VAULT_NAME" \
--name "storage-conn" \
--value "$CONTAINER_CONN_STRING" \
Expand All @@ -200,7 +189,7 @@ else
fi

# Retrieve secret to verify and pass to ACI
RETRIEVED_CONN_STRING=$($AZ keyvault secret show \
RETRIEVED_CONN_STRING=$(az keyvault secret show \
--vault-name "$KEY_VAULT_NAME" \
--name "storage-conn" \
--query "value" \
Expand All @@ -221,7 +210,7 @@ echo ""
echo "============================================================"
echo "Step 8: Creating ACR [$ACR_NAME] with admin user enabled..."
echo "============================================================"
$AZ acr create \
az acr create \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--location "$LOCATION" \
Expand All @@ -243,7 +232,7 @@ echo ""
echo "============================================================"
echo "Step 9: Retrieving ACR credentials..."
echo "============================================================"
LOGIN_SERVER=$($AZ acr show \
LOGIN_SERVER=$(az acr show \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--query "loginServer" \
Expand All @@ -256,14 +245,14 @@ if [ -z "$LOGIN_SERVER" ]; then
fi
echo "ACR Login Server: $LOGIN_SERVER"

ACR_USERNAME=$($AZ acr credential show \
ACR_USERNAME=$(az acr credential show \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--query "username" \
--output tsv \
--only-show-errors)

ACR_PASSWORD=$($AZ acr credential show \
ACR_PASSWORD=$(az acr credential show \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--query "passwords[0].value" \
Expand Down Expand Up @@ -333,7 +322,7 @@ echo "Step 11: Creating ACI container group [$ACI_GROUP_NAME]..."
echo "============================================================"

if [ "$USE_ACR_IMAGE" = true ]; then
$AZ container create \
az container create \
--resource-group "$RESOURCE_GROUP_NAME" \
--name "$ACI_GROUP_NAME" \
--image "$FULL_IMAGE" \
Expand All @@ -353,7 +342,7 @@ if [ "$USE_ACR_IMAGE" = true ]; then
--location "$LOCATION" \
--only-show-errors 1>/dev/null
else
$AZ container create \
az container create \
--resource-group "$RESOURCE_GROUP_NAME" \
--name "$ACI_GROUP_NAME" \
--image "$FULL_IMAGE" \
Expand Down
Loading
Loading