-
Notifications
You must be signed in to change notification settings - Fork 44
/
setup.sh
41 lines (35 loc) · 2.02 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Set up randomized names for a storage account and two functions, which must be globally unique
export STORAGE_ACCOUNT_NAME=storestorage$(openssl rand -hex 5)
export PRODUCT_FUNCTION_NAME=ProductFunction$(openssl rand -hex 5)
export ORDER_FUNCTION_NAME=OrderFunction$(openssl rand -hex 5)
export CURRENT_DIR=$(pwd)
# Get the resource group and location
export RESOURCE_GROUP=$(az group list --query "[0].name" -o tsv)
export LOCATION=$(az group show --name $RESOURCE_GROUP -o json| jq -r ".location")
printf "\nThe resource group is called $RESOURCE_GROUP and is located in $LOCATION\n"
# Create a storage account
printf "\nCreating a storage account for the functions...\n"
az storage account create --name $STORAGE_ACCOUNT_NAME --location $LOCATION --resource-group $RESOURCE_GROUP --sku Standard_LRS
printf "\nStorage account created.\n"
# Create two functions in Azure
printf "\nCreating function apps in Azure...\n"
az functionapp create --resource-group $RESOURCE_GROUP --consumption-plan-location $LOCATION --name $PRODUCT_FUNCTION_NAME --storage-account $STORAGE_ACCOUNT_NAME --functions-version 4
az functionapp create --resource-group $RESOURCE_GROUP --consumption-plan-location $LOCATION --name $ORDER_FUNCTION_NAME --storage-account $STORAGE_ACCOUNT_NAME --functions-version 4
printf "\nFunction apps created.\n"
# Building the zip files for the functions
printf "\nBuilding zip files for deployment...\n"
for zipFile in ProductDetailsFunc OrderShippingFunc
do
mkdir $zipFile
unzip -q $zipFile.zip -d $zipFile
cd $zipFile/bin/Debug/net6.0
zip -q -r $CURRENT_DIR/$zipFile.PKG.zip ./*
cd $CURRENT_DIR
done
printf "\nZip files built.\n"
# Use zip deploy to publish the code
printf "\nPublishing function source code...\n"
az functionapp deployment source config-zip -g $RESOURCE_GROUP -n $PRODUCT_FUNCTION_NAME --src ProductDetailsFunc.PKG.zip
az functionapp deployment source config-zip -g $RESOURCE_GROUP -n $ORDER_FUNCTION_NAME --src OrderShippingFunc.PKG.zip
printf "\nCode published. Functions are ready to use.\n"