Skip to content

Commit

Permalink
Merge pull request #3 from adamruderman/feature-update-logo
Browse files Browse the repository at this point in the history
Adding --webApi and --webApiUrl for SH file as well
  • Loading branch information
adamruderman authored Nov 25, 2024
2 parents a7f25ed + 8c368d2 commit cf3ced6
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions scripts/deploy/deploy-webapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
# Deploy Chat Copilot application to Azure

usage() {
echo "Usage: $0 -d DEPLOYMENT_NAME -s SUBSCRIPTION -rg RESOURCE_GROUP [OPTIONS]"
echo "Usage: $0 -s SUBSCRIPTION -rg RESOURCE_GROUP [OPTIONS]"
echo ""
echo "Arguments:"
echo " -d, --deployment-name DEPLOYMENT_NAME Name of the deployment from a 'deploy-azure.sh' deployment (mandatory)"
echo " -d, --deployment-name DEPLOYMENT_NAME Name of the deployment from a 'deploy-azure.sh' deployment"
echo " -s, --subscription SUBSCRIPTION Subscription to which to make the deployment (mandatory)"
echo " -rg, --resource-group RESOURCE_GROUP Resource group name from a 'deploy-azure.sh' deployment (mandatory)"
echo " -p, --package PACKAGE_FILE_PATH Path to the package file from a 'package-webapi.sh' run (default: \"./out/webapi.zip\")"
echo " -o, --slot DEPLOYMENT_SLOT Name of the target web app deployment slot"
echo " -sr, --skip-app-registration Skip adding our URI in app registration's redirect URIs"
echo " -sc, --skip-cors-registration Skip registration of service with the plugins as allowed CORS origin"
echo " -e, --environment ENVIRONMENT Azure cloud environment (default: AzureCloud)"
echo " -wa, --webApi WEB_API_NAME Web API name"
echo " -wu, --webApiUrl WEB_API_URL Web API URL"
}

# Parse arguments
Expand Down Expand Up @@ -61,6 +64,16 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
-wa |--webApi)
WEB_API_NAME="$2"
shift
shift
;;
-wu |--webApiUrl)
WEB_API_URL="$2"
shift
shift
;;
*)
echo "Unknown option $1"
usage
Expand All @@ -70,7 +83,7 @@ while [[ $# -gt 0 ]]; do
done

# Check mandatory arguments
if [[ -z "$DEPLOYMENT_NAME" ]] || [[ -z "$SUBSCRIPTION" ]] || [[ -z "$RESOURCE_GROUP" ]]; then
if [[ -z "$SUBSCRIPTION" ]] || [[ -z "$RESOURCE_GROUP" ]]; then
usage
exit 1
fi
Expand All @@ -83,8 +96,6 @@ if [[ ! -f "$PACKAGE_FILE_PATH" ]]; then
echo "Package file '$PACKAGE_FILE_PATH' does not exist. Have you run 'package-webapi.sh' yet?"
exit 1
fi


# Ensure that the environment variable is set
if [[ -z "$ENVIRONMENT" ]]; then
echo "Error: Environment not set. Please set the environment to either 'AzureCloud' or 'AzureUSGovernment'."
Expand All @@ -110,20 +121,27 @@ fi

az account set -s "$SUBSCRIPTION"

echo "Getting Azure WebApp resource name..."
DEPLOYMENT_JSON=$(az deployment group show --name $DEPLOYMENT_NAME --resource-group $RESOURCE_GROUP --output json)
WEB_API_URL=$(echo $DEPLOYMENT_JSON | jq -r '.properties.outputs.webapiUrl.value')
echo "WEB_API_URL: $WEB_API_URL"
WEB_API_NAME=$(echo $DEPLOYMENT_JSON | jq -r '.properties.outputs.webapiName.value')
echo "WEB_API_NAME: $WEB_API_NAME"
PLUGIN_NAMES=$(echo $DEPLOYMENT_JSON | jq -r '.properties.outputs.pluginNames.value[]')
# Remove double quotes
PLUGIN_NAMES=${PLUGIN_NAMES//\"/}
echo "PLUGIN_NAMES: $PLUGIN_NAMES"
# Ensure $WEB_API_NAME is set
if [[ -z "$WEB_API_NAME" ]]; then
echo "Could not get Azure WebApp resource name from deployment output."
exit 1
if [[ -z "$WEB_API_NAME" || -z "$WEB_API_URL" ]]; then
if [[ -z "$DEPLOYMENT_NAME" ]]; then
echo "Either DeploymentName or both WebApi and WebApiUrl must be provided."
exit 1
fi

echo "Getting Azure WebApp resource name..."
DEPLOYMENT_JSON=$(az deployment group show --name $DEPLOYMENT_NAME --resource-group $RESOURCE_GROUP --output json)
WEB_API_URL=$(echo $DEPLOYMENT_JSON | jq -r '.properties.outputs.webapiUrl.value')
echo "WEB_API_URL: $WEB_API_URL"
WEB_API_NAME=$(echo $DEPLOYMENT_JSON | jq -r '.properties.outputs.webapiName.value')
echo "WEB_API_NAME: $WEB_API_NAME"
PLUGIN_NAMES=$(echo $DEPLOYMENT_JSON | jq -r '.properties.outputs.pluginNames.value[]')
# Remove double quotes
PLUGIN_NAMES=${PLUGIN_NAMES//\"/}
echo "PLUGIN_NAMES: $PLUGIN_NAMES"
# Ensure $WEB_API_NAME is set
if [[ -z "$WEB_API_NAME" ]]; then
echo "Could not get Azure WebApp resource name from deployment output."
exit 1
fi
fi

echo "Configuring Azure WebApp to run from package..."
Expand All @@ -139,11 +157,11 @@ AZ_WEB_APP_CMD="az webapp deployment source config-zip --resource-group $RESOURC
ORIGINS="$WEB_API_URL"
if [ -n "$DEPLOYMENT_SLOT" ]; then
AZ_WEB_APP_CMD+=" --slot ${DEPLOYMENT_SLOT}"
echo "Checking whether slot $DEPLOYMENT_SLOT exists for $WEB_APP_NAME..."
echo "Checking whether slot $DEPLOYMENT_SLOT exists for $WEB_API_NAME..."
SLOT_INFO=$(az webapp deployment slot list --resource-group $RESOURCE_GROUP --name $WEB_API_NAME)

AVAILABLE_SLOTS=$(echo $SLOT_INFO | jq '.[].name')
ORIGINS=$(echo $slotInfo | jq '.[].defaultHostName')
ORIGINS=$(echo $SLOT_INFO | jq '.[].defaultHostName')
SLOT_EXISTS=false

# Checking if the slot exists
Expand Down

0 comments on commit cf3ced6

Please sign in to comment.