-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_function_app.sh
More file actions
73 lines (59 loc) · 2.79 KB
/
Copy pathdeploy_function_app.sh
File metadata and controls
73 lines (59 loc) · 2.79 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
echo "This script will deploy your Azure Function App."
echo "Please provide the following details:"
read -p "Enter Azure Resource Group Name: " RESOURCE_GROUP_NAME
read -p "Enter Azure Location (e.g., eastus): " LOCATION
read -p "Enter Azure Storage Account Name (globally unique): " STORAGE_ACCOUNT_NAME
read -p "Enter Azure Function App Name (globally unique): " FUNCTION_APP_NAME
echo "Logging into Azure..."
az login --output none
echo "Creating resource group '$RESOURCE_GROUP_NAME' in '$LOCATION'ப்பான"
az group create --name "$RESOURCE_GROUP_NAME" --location "$LOCATION" --output none
echo "Creating storage account '$STORAGE_ACCOUNT_NAME'ப்பான"
az storage account create \
--name "$STORAGE_ACCOUNT_NAME" \
--location "$LOCATION" \
--resource-group "$RESOURCE_GROUP_NAME" \
--sku Standard_LRS --output none
echo "Creating Function App '$FUNCTION_APP_NAME'ப்பான"
az functionapp create \
--name "$FUNCTION_APP_NAME" \
--storage-account "$STORAGE_ACCOUNT_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--consumption-plan-location "$LOCATION" \
--runtime python \
--python-version 3.9 \
--functions-version 4 --output none
echo "Retrieving storage account connection string..."
STORAGE_CONNECTION_STRING=$(az storage account show-connection-string \
--name "$STORAGE_ACCOUNT_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--query "connectionString" --output tsv)
echo "Configuring application settings..."
# Set AzureWebJobsStorage and AZURE_STORAGE_CONNECTION_STRING from the newly created storage account
az functionapp config appsettings set \
--name "$FUNCTION_APP_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--settings "AzureWebJobsStorage=$STORAGE_CONNECTION_STRING" --output none
az functionapp config appsettings set \
--name "$FUNCTION_APP_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--settings "AZURE_STORAGE_CONNECTION_STRING=$STORAGE_CONNECTION_STRING" --output none
# Set other settings from local.settings.json
az functionapp config appsettings set \
--name "$FUNCTION_APP_NAME" \
--resource-group "$RESOURCE_GROUP_NAME" \
--settings "FUNCTIONS_WORKER_RUNTIME=python" \
"AZURE_STORAGE_CONTAINER=scaniq" \
"DB_USER=your_db_user" \
"DB_PASSWORD=your_db_password" \
"DB_HOST=your_db_host" \
"DB_NAME=your_db_name" \
"SCHEDULE=0 */5 * * * *" --output none
echo "Deploying code to Function App '$FUNCTION_APP_NAME'..."
# Ensure you are in the ScanIQFunctionApp directory before running this command
func azure functionapp publish "$FUNCTION_APP_NAME"
echo "Deployment complete!"
echo "Your Function App is now live on Azure."