Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Jan 15, 2024
1 parent 680e999 commit 8b700d1
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 3 deletions.
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ container_name := ghcr.io/clemlesne/claim-ai-phone-bot
docker := docker
version_full ?= $(shell $(MAKE) --silent version-full)
version_small ?= $(shell $(MAKE) --silent version)
tunnel_name := claim-ai-phone-bot-$(shell hostname | tr '[:upper:]' '[:lower:]')
tunnel_name := claim-ai-$(shell hostname | tr '[:upper:]' '[:lower:]')
tunnel_url := $(shell devtunnel show $(tunnel_name) | grep -o 'http[s]*://[^"]*')

version:
Expand Down Expand Up @@ -66,7 +66,21 @@ run:
--env VERSION=$(version_full) \
--mount type=bind,source="$(CURDIR)/.env",target="/app/.env" \
--mount type=bind,source="$(CURDIR)/config.yaml",target="/app/config.yaml" \
--name claim-ai-phone-bot \
--name claim-ai \
--publish 8080:8080 \
--rm \
$(container_name):$(version_small)

deploy:
echo "🚀 Deploying to Azure..."
az deployment sub create \
--location westeurope \
--parameters config='$(shell cat config.yaml | yq -o json)' \
--template-file bicep/main.bicep \
--name $(name)

echo "🔍 Deployment outputs:"
az deployment sub show --name $(name) | yq --prettyPrint .properties.outputs

destroy:
az deployment sub delete --name $(name)
189 changes: 189 additions & 0 deletions bicep/app.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
param config string
param imageVersion string
param instance string = deployment().name
param location string = resourceGroup().location
param openaiLocation string
param tags object

var prefix = instance

output appUrl string = 'https://claim-ai.${acaEnv.properties.defaultDomain}'

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: prefix
location: location
tags: tags
properties: {
retentionInDays: 30
sku: {
name: 'PerGB2018'
}
}
}

resource acaEnv 'Microsoft.App/managedEnvironments@2023-05-01' = {
name: prefix
location: location
tags: tags
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
workloadProfiles: [
{
// Consumption workload profile name must be 'Consumption'
name: 'Consumption'
workloadProfileType: 'Consumption'
}
]
}
}

resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
name: 'claim-ai'
location: location
tags: tags
identity: {
type: 'SystemAssigned'
}
properties: {
configuration: {
activeRevisionsMode: 'Single'
ingress: {
external: true
targetPort: 8080
}
}
environmentId: acaEnv.id
template: {
scale: {
maxReplicas: 1 // TODO: The actual implementation should be able to scale, because it registers itself to the EventGrid topic
minReplicas: 1
}
containers: [
{
image: 'ghcr.io/clemlesne/claim-ai-phone-bot:${imageVersion}'
name: 'claim-ai'
env: [
{
name: 'CONFIG_JSON'
value: config
}
{
name: 'EVENTS_DOMAIN'
value: 'https://claim-ai.${acaEnv.properties.defaultDomain}'
}
]
resources: {
cpu: 1
memory: '2Gi'
}
probes: [
{
type: 'Liveness'
httpGet: {
path: '/health/liveness'
port: 8080
}
}
]
}
]
}
}
}

resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: replace(prefix, '-', '')
location: location
tags: tags
sku: {
name: 'Standard_ZRS'
}
kind: 'StorageV2'
}

resource blobService 'Microsoft.Storage/storageAccounts/blobServices@2023-01-01' = {
parent: storageAccount
name: 'default'
}

resource blobContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2023-01-01' = {
parent: blobService
name: '$web'
}

resource communication 'Microsoft.Communication/CommunicationServices@2023-06-01-preview' existing = {
name: prefix
}

resource rolEventgridContributor 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
name: '1e241071-0855-49ea-94dc-649edcd759de'
}

resource appAccessEventgrid 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(subscription().id, deployment().name, 'appAccessEventgrid')
scope: eventgridTopic
properties: {
principalId: containerApp.identity.principalId
principalType: 'ServicePrincipal'
roleDefinitionId: rolEventgridContributor.id
}
}

resource eventgridTopic 'Microsoft.EventGrid/systemTopics@2023-12-15-preview' = {
name: prefix
location: 'global'
tags: tags
properties: {
source: communication.id
topicType: 'Microsoft.Communication.CommunicationServices'
}
}

resource roleOpenaiContributor 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
name: 'a001fd3d-188f-4b5d-821b-7da978bf7442'
}

resource appAccessOpenai 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(subscription().id, deployment().name, 'appAccessOpenai')
scope: cognitiveOpenai
properties: {
principalId: containerApp.identity.principalId
principalType: 'ServicePrincipal'
roleDefinitionId: roleOpenaiContributor.id
}
}

resource cognitiveOpenai 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = {
name: '${prefix}-openai'
location: openaiLocation
tags: tags
sku: {
name: 'S0'
}
kind: 'OpenAI'
properties: {
customSubDomainName: '${prefix}-openai'
}
}

resource gpt 'Microsoft.CognitiveServices/accounts/deployments@2023-10-01-preview' = {
parent: cognitiveOpenai
name: 'gpt-4-turbo'
sku: {
capacity: 50
name: 'Standard'
}
properties: {
model: {
format: 'OpenAI'
name: 'gpt-4'
version: '1106-Preview'
}
}
}
35 changes: 35 additions & 0 deletions bicep/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
param config string
param imageVersion string = 'develop'
param instance string = deployment().name
param location string = 'westeurope'
param openaiLocation string = 'swedencentral'

targetScope = 'subscription'

output appUrl string = app.outputs.appUrl

var tags = {
application: 'claim-ai'
instance: instance
managed_by: 'Bicep'
sources: 'https://github.com/clemlesne/claim-ai-phone-bot'
version: imageVersion
}

resource sub 'Microsoft.Resources/resourceGroups@2021-04-01' = {
location: location
name: instance
tags: tags
}

module app 'app.bicep' = {
name: instance
scope: sub
params: {
config: config
imageVersion: imageVersion
location: location
openaiLocation: openaiLocation
tags: tags
}
}
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def lifespan(_: FastAPI):
},
lifespan=lifespan,
root_path=ROOT_PATH,
title="claim-ai-phone-bot",
title="claim-ai",
version=VERSION,
)

Expand Down

0 comments on commit 8b700d1

Please sign in to comment.