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
25 changes: 25 additions & 0 deletions run-samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,28 @@ host_arch() {
esac
}

# Set PREFIX, from which every sample builds its resource group and resource names ("local" by default), to the
# letter l and four random lowercase letters, never the previous sample's. The cleanup after each sample deletes
# every resource group with --no-wait, so a sample that reused the previous one's names could write into a group
# still being deleted: Azure refuses that with 409 ResourceGroupBeingDeleted, and an emulator that accepts it
# leaves the new resources behind once the group is gone. Giving every sample its own names avoids both without
# waiting for the deletes. The prefix keeps the length and the characters of "local", so no name changes length.
# $RANDOM in this shell rather than a pipeline from /dev/urandom: under pipefail, the SIGPIPE that head gives tr
# would end the script.
set_sample_name_prefix() {
local letters=abcdefghijklmnopqrstuvwxyz previous="${PREFIX:-}" i
while true; do
PREFIX=l
for (( i = 0; i < 4; i++ )); do
PREFIX+="${letters:RANDOM % 26:1}"
done
if [[ "$PREFIX" != "$previous" ]]; then
break
fi
done
export PREFIX
}

# 2. Handle --list flag: output JSON metadata for CI matrix generation (no tools required)
# Each entry has: shard (1-based index), splits (total count), name, watch_folders,
# and arches. CI uses watch_folders to detect which tests are affected by changed
Expand Down Expand Up @@ -368,6 +390,9 @@ for (( i=START; i<START+COUNT; i++ )); do
echo " amd64. Set SKIP_AMD64_ONLY=1 to skip these instead."
fi

set_sample_name_prefix
Comment thread
paolosalvatori marked this conversation as resolved.
Resolved
Comment thread
paolosalvatori marked this conversation as resolved.
Resolved
echo "Name prefix: $PREFIX"

pushd "$path" > /dev/null

# Deploy a Terraform sample from empty state. A failed run skips the cleanup below and leaves
Expand Down
8 changes: 4 additions & 4 deletions samples/aci-blob-storage/python/bicep/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -x

# Variables
PREFIX='local'
PREFIX="${PREFIX:-local}"
SUFFIX='test'
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
Expand Down Expand Up @@ -42,7 +42,7 @@ if [[ $? != 0 ]]; then
echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]"
else
echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]"
exit
exit 1
fi
else
echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]"
Expand Down Expand Up @@ -131,7 +131,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then
echo "Bicep template [$TEMPLATE] validation succeeded"
else
echo "Failed to validate Bicep template [$TEMPLATE]"
exit
exit 1
fi
else
# Validate the Bicep template
Expand All @@ -150,7 +150,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then
else
echo "Failed to validate Bicep template [$TEMPLATE]"
echo "$output"
exit
exit 1
fi
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion samples/aci-blob-storage/python/scripts/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# =============================================================================

# Variables (must match deploy.sh)
PREFIX='local'
PREFIX="${PREFIX:-local}"
RESOURCE_GROUP_NAME="${PREFIX}-aci-rg"
ACI_GROUP_NAME="${PREFIX}-aci-planner"
ACI_GROUP_ADVANCED="${PREFIX}-aci-planner-advanced"
Expand Down
2 changes: 1 addition & 1 deletion samples/aci-blob-storage/python/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# =============================================================================

# Variables
PREFIX='local'
PREFIX="${PREFIX:-local}"
LOCATION='eastus'
RESOURCE_GROUP_NAME="${PREFIX}-aci-rg"
STORAGE_ACCOUNT_NAME="${PREFIX}acistorage"
Expand Down
2 changes: 1 addition & 1 deletion samples/aci-blob-storage/python/scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# =============================================================================

# Variables (must match deploy.sh)
PREFIX='local'
PREFIX="${PREFIX:-local}"
LOCATION='eastus'
RESOURCE_GROUP_NAME="${PREFIX}-aci-rg"
STORAGE_ACCOUNT_NAME="${PREFIX}acistorage"
Expand Down
12 changes: 11 additions & 1 deletion samples/aci-blob-storage/python/terraform/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Variables
PREFIX='local'
PREFIX="${PREFIX:-local}"
SUFFIX='test'
LOCATION='eastus'
IMAGE_NAME='vacation-planner'
Expand All @@ -20,6 +20,16 @@ cd "$CURRENT_DIR" || exit
RESOURCE_GROUP_NAME="${PREFIX}-aci-rg"
ACR_NAME="${PREFIX}aciacr${SUFFIX}"

# Stop if the Terraform state of a previous run tracks another resource group: run under another PREFIX, the
# apply would replace that run's resource group and delete its resources
echo "Checking that the Terraform state tracks no resource group other than [$RESOURCE_GROUP_NAME]..."
STATE_RESOURCE_GROUP_NAME=$(terraform state show -no-color azurerm_resource_group.example 2>/dev/null | awk '$1 == "name" { gsub(/"/, "", $3); print $3 }')

if [[ -n $STATE_RESOURCE_GROUP_NAME && $STATE_RESOURCE_GROUP_NAME != "$RESOURCE_GROUP_NAME" ]]; then
echo "The Terraform state tracks the [$STATE_RESOURCE_GROUP_NAME] resource group of a previous run: delete its terraform.tfstate files, or run with the PREFIX of that run"
exit 1
fi

echo "Creating resource group [$RESOURCE_GROUP_NAME]..."
az group create \
--name "$RESOURCE_GROUP_NAME" \
Expand Down
46 changes: 42 additions & 4 deletions samples/container-apps-blob-storage/python/bicep/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -x

# Variables
PREFIX='local'
PREFIX="${PREFIX:-local}"
SUFFIX='test'
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
Expand Down Expand Up @@ -43,7 +43,7 @@ if [[ $? != 0 ]]; then
echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]"
else
echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]"
exit
exit 1
fi
else
echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]"
Expand All @@ -65,27 +65,55 @@ az acr create \
--admin-enabled true \
--only-show-errors 1>/dev/null

if [[ $? == 0 ]]; then
echo "[$ACR_NAME] container registry successfully created in the [$RESOURCE_GROUP_NAME] resource group"
else
echo "Failed to create [$ACR_NAME] container registry in the [$RESOURCE_GROUP_NAME] resource group"
exit 1
fi

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

if [[ -n $LOGIN_SERVER ]]; then
echo "Successfully retrieved the login server of the [$ACR_NAME] container registry"
else
echo "Failed to retrieve the login server of the [$ACR_NAME] container registry"
exit 1
fi

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

if [[ -n $ACR_USERNAME ]]; then
echo "Successfully retrieved the admin username of the [$ACR_NAME] container registry"
else
echo "Failed to retrieve the admin username of the [$ACR_NAME] container registry"
exit 1
fi

ACR_PASSWORD=$(az acr credential show \
--name "$ACR_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--query "passwords[0].value" \
--output tsv \
--only-show-errors)

if [[ -n $ACR_PASSWORD ]]; then
echo "Successfully retrieved the admin password of the [$ACR_NAME] container registry"
else
echo "Failed to retrieve the admin password of the [$ACR_NAME] container registry"
exit 1
fi

FULL_IMAGE="${LOGIN_SERVER}/${IMAGE_NAME}:${IMAGE_TAG}"

echo "Building Docker image [$IMAGE_NAME:$IMAGE_TAG]..."
Expand All @@ -98,9 +126,19 @@ fi

docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE"

if [[ $? != 0 ]]; then
echo "Failed to tag Docker image."
exit 1
fi

echo "Logging in to ACR [$LOGIN_SERVER]..."
echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null

if [[ $? != 0 ]]; then
echo "Failed to log in to ACR."
exit 1
fi

echo "Pushing image [$FULL_IMAGE]..."
docker push "$FULL_IMAGE" 2>/dev/null

Expand Down Expand Up @@ -133,7 +171,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then
echo "Bicep template [$TEMPLATE] validation succeeded"
else
echo "Failed to validate Bicep template [$TEMPLATE]"
exit
exit 1
fi
else
# Validate the Bicep template
Expand All @@ -153,7 +191,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then
else
echo "Failed to validate Bicep template [$TEMPLATE]"
echo "$output"
exit
exit 1
fi
fi
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# =============================================================================

# Variables (must match deploy.sh)
PREFIX='local'
PREFIX="${PREFIX:-local}"
RESOURCE_GROUP_NAME="${PREFIX}-aca-rg"
ACA_APP_NAME="${PREFIX}-aca-guestbook"
ACA_ENV_NAME="${PREFIX}-aca-env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# =============================================================================

# Variables
PREFIX='local'
PREFIX="${PREFIX:-local}"
LOCATION='eastus'
RESOURCE_GROUP_NAME="${PREFIX}-aca-rg"
STORAGE_ACCOUNT_NAME="${PREFIX}acastorage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ null_device() {
}

# Variables (must match deploy.sh)
PREFIX='local'
PREFIX="${PREFIX:-local}"
LOCATION='eastus'
RESOURCE_GROUP_NAME="${PREFIX}-aca-rg"
STORAGE_ACCOUNT_NAME="${PREFIX}acastorage"
Expand Down
Loading
Loading