forked from microsoft/call-center-ai
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
153 lines (124 loc) · 5.36 KB
/
Makefile
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Global Path
app_config_folder = "app/configs"
# Versioning
version_full ?= $(shell $(MAKE) --silent version-full)
version_small ?= $(shell $(MAKE) --silent version)
# DevTunnel configuration
tunnel_name := call-center-ai-$(shell hostname | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')
tunnel_url ?= $(shell res=$$(devtunnel show $(tunnel_name) | grep -o 'http[s]*://[^"]*' | xargs) && echo $${res%/})
# App location
cognitive_communication_location := westeurope
default_location := francecentral
functionapp_location := swedencentral
openai_location := swedencentral
search_location := francecentral
# Sanitize variables
name_sanitized := $(shell echo $(name) | tr '[:upper:]' '[:lower:]')
# App configuration
bot_phone_number ?= $(shell cat $(app_config_folder)/config.yaml | yq '.communication_services.phone_number')
event_subscription_name ?= $(shell echo '$(name_sanitized)-$(bot_phone_number)' | tr -dc '[:alnum:]-')
twilio_phone_number ?= $(shell cat $(app_config_folder)/config.yaml | yq '.sms.twilio.phone_number')
# Bicep outputs
app_url ?= $(shell az deployment sub show --name $(name_sanitized) | yq '.properties.outputs["appUrl"].value')
blob_storage_public_name ?= $(shell az deployment sub show --name $(name_sanitized) | yq '.properties.outputs["blobStoragePublicName"].value')
communication_id ?= $(shell az deployment sub show --name $(name_sanitized) | yq '.properties.outputs["communicationId"].value')
function_app_name ?= $(shell az deployment sub show --name $(name_sanitized) | yq '.properties.outputs["functionAppName"].value')
log_analytics_workspace_customer_id ?= $(shell az deployment sub show --name $(name_sanitized) | yq '.properties.outputs["logAnalyticsWorkspaceName"].value')
version:
@bash ./infra/cicd/version/version.sh -g . -c
version-full:
@bash ./infra/cicd/version/version.sh -g . -c -m
install:
@echo "➡️ Installing Twilio CLI..."
twilio --version || brew tap twilio/brew && brew install twilio
cd ./app && for f in $$(find . -name "requirements*.txt"); do \
echo "➡️ Installing Python dependencies in $$f..."; \
python3 -m pip install -r $$f; \
done
upgrade:
@echo "➡️ Upgrading pip..."
python3 -m pip install --upgrade pip
cd ./app && for f in $$(find . -name "requirements*.txt"); do \
echo "➡️ Upgrading Python dependencies in $$f..."; \
python3 -m pur -r $$f; \
done
@echo "➡️ Upgrading Bicep CLI..."
az bicep upgrade
test:
@echo "➡️ Running Black..."
cd ./app && python3 -m black --check .
@echo "➡️ Running deptry..."
cd ./app && python3 -m deptry \
--ignore-notebooks \
--per-rule-ignores "DEP002=aiohttp" \
--per-rule-ignores "DEP003=aiohttp_retry" \
.
@echo "➡️ Running Pytest..."
cd ./app && PUBLIC_DOMAIN=dummy pytest \
--junit-xml=test-reports/$$(date +%Y%m%d%H%M%S).xml \
tests/*.py
lint:
@echo "➡️ Running Black..."
cd ./app && python3 -m black .
tunnel:
@echo "➡️ Creating tunnel..."
devtunnel show $(tunnel_name) || devtunnel create $(tunnel_name) --allow-anonymous --expiration 1d
@echo "➡️ Creating port forwarding..."
devtunnel port show $(tunnel_name) --port-number 8080 || devtunnel port create $(tunnel_name) --port-number 8080
@echo "➡️ Starting tunnel..."
devtunnel host $(tunnel_name)
dev:
cd ./app && VERSION=$(version_full) PUBLIC_DOMAIN=$(tunnel_url) func start --python
deploy:
@echo "👀 Current subscription:"
@az account show --query "{subscriptionId:id, subscriptionName:name, tenantId:tenantId}" --output table
@echo "🛠️ Deploying resources..."
az deployment sub create \
--location $(default_location) \
--parameters \
'cognitiveCommunicationLocation=$(cognitive_communication_location)' \
'functionappLocation=$(functionapp_location)' \
'instance=$(name)' \
'openaiLocation=$(openai_location)' \
'searchLocation=$(search_location)' \
'version=$(version_full)' \
--template-file infra/bicep/main.bicep \
--name $(name_sanitized)
@echo "🛠️ Deploying Function App..."
cd ./app && func azure functionapp publish $(function_app_name) --python
@echo "🚀 Call Center AI is running on $(app_url)"
@$(MAKE) post-deploy name=$(name_sanitized)
post-deploy:
@$(MAKE) copy-resources \
name=$(blob_storage_public_name)
@$(MAKE) logs name=$(name_sanitized)
destroy:
@echo "🧐 Are you sure you want to delete? Type 'delete now $(name_sanitized)' to confirm."
@read -r confirm && [ "$$confirm" = "delete now $(name_sanitized)" ] || (echo "Confirmation failed. Aborting."; exit 1)
@echo "❗️ Deleting RG..."
az group delete --name $(name_sanitized) --yes --no-wait
@echo "❗️ Deleting deployment..."
az deployment sub delete --name $(name_sanitized)
logs:
cd ./app && func azure functionapp logstream $(function_app_name) \
--browser
twilio-register:
@echo "⚙️ Registering Twilio webhook..."
twilio phone-numbers:update $(twilio_phone_number) \
--sms-url $(endpoint)/twilio/sms
copy-resources:
@echo "📦 Copying resources to Azure storage account..."
cd ./app && az storage blob upload-batch \
--account-name $(name_sanitized) \
--destination '$$web' \
--no-progress \
--output none \
--overwrite \
--source resources
watch-call:
@echo "👀 Watching status of $(phone_number)..."
while true; do \
clear; \
curl -s "$(endpoint)/call?phone_number=%2B$(phone_number)" | yq --prettyPrint '.[0] | {"phone_number": .phone_number, "claim": .claim, "reminders": .reminders}'; \
sleep 3; \
done