Skip to content

Commit 3b8223b

Browse files
authored
Merge pull request #47 from ks6088ts-labs/feature/issue-46_support-iac
support IaC by Bicep
2 parents 7c6f7c5 + c6173bc commit 3b8223b

File tree

11 files changed

+390
-2
lines changed

11 files changed

+390
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,4 @@ cython_debug/
163163
*.env
164164
requirements.txt
165165
azure-functions.json
166+
artifacts/

azure_ai_vision.env.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
AZURE_AI_VISION_API_KEY="<your-api-key>"
21
AZURE_AI_VISION_ENDPOINT="<your-endpoint>"
2+
AZURE_AI_VISION_API_KEY="<your-api-key>"

backend/internals/azure_ai_vision.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def analyze_image(
2727
result = image_analysis_client.analyze(
2828
image_data=image,
2929
visual_features=[
30-
VisualFeatures.CAPTION,
3130
VisualFeatures.READ,
3231
],
3332
)

infra/Makefile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Parameters
2+
SOURCE_FILES ?= $(shell find . -type f -name '*.bicep' -print)
3+
OUT_DIR ?= ./artifacts
4+
BICEP_MAIN ?= ./main.bicep
5+
BICEP_PARAMETERS ?= ./main.parameters.bicepparam
6+
7+
# Git
8+
GIT_REVISION ?= $(shell git rev-parse --short HEAD)
9+
GIT_TAG ?= $(shell git describe --tags --abbrev=0 --always | sed -e s/v//g)
10+
11+
# Azure
12+
SUBSCRIPTION_ID ?= $(shell az account show --query id --output tsv)
13+
SUBSCRIPTION_NAME ?= $(shell az account show --query name --output tsv)
14+
TENANT_ID ?= $(shell az account show --query tenantId --output tsv)
15+
RESOURCE_GROUP_NAME ?= rg-azure-ai-services-solutions
16+
LOCATION ?= japaneast
17+
18+
.PHONY: help
19+
help:
20+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
21+
.DEFAULT_GOAL := help
22+
23+
.PHONY: info
24+
info: ## show information
25+
@echo "GIT_REVISION: $(GIT_REVISION)"
26+
@echo "GIT_TAG: $(GIT_TAG)"
27+
@echo "SUBSCRIPTION_ID: $(SUBSCRIPTION_ID)"
28+
@echo "SUBSCRIPTION_NAME: $(SUBSCRIPTION_NAME)"
29+
@echo "TENANT_ID: $(TENANT_ID)"
30+
31+
.PHONY: install-deps-dev
32+
install-deps-dev: ## install dependencies for development
33+
@which az || echo "Please install Azure CLI: https://github.com/Azure/azure-cli#installation"
34+
@az bicep upgrade
35+
36+
.PHONY: format
37+
format: ## format codes
38+
@$(foreach file,$(SOURCE_FILES),az bicep format --file $(file) --insert-final-newline;)
39+
40+
.PHONY: lint
41+
lint: ## lint codes
42+
@echo "lint: Skip since not implemented yet"
43+
44+
.PHONY: build
45+
build: ## build a bicep file
46+
@mkdir -p $(OUT_DIR)
47+
@az bicep build \
48+
--file $(BICEP_MAIN) \
49+
--outfile $(OUT_DIR)/$(GIT_REVISION).json
50+
51+
.PHONY: test
52+
test: deployment-what-if ## test codes
53+
54+
.PHONY: ci-test
55+
ci-test: install-deps-dev lint build test ## ci test
56+
57+
.PHONY: create-resource-group
58+
create-resource-group: ## create resource group
59+
az group create \
60+
--name $(RESOURCE_GROUP_NAME) \
61+
--location $(LOCATION)
62+
63+
.PHONY: delete-resource-group
64+
delete-resource-group: ## delete resource group
65+
az group delete --name $(RESOURCE_GROUP_NAME) --yes --no-wait
66+
67+
.PHONY: deployment-what-if
68+
deployment-what-if: ## execute a deployment What-If operation at resource group scope
69+
az deployment group what-if \
70+
--resource-group $(RESOURCE_GROUP_NAME) \
71+
--template-file $(BICEP_MAIN) \
72+
--parameters $(BICEP_PARAMETERS)
73+
74+
.PHONY: deployment-create
75+
deployment-create: ## start a deployment at resource group
76+
az deployment group create \
77+
--resource-group $(RESOURCE_GROUP_NAME) \
78+
--template-file $(BICEP_MAIN) \
79+
--parameters $(BICEP_PARAMETERS)
80+
81+
.PHONY: deploy
82+
deploy: create-resource-group deployment-what-if deployment-create ## deploy resources
83+
84+
.PHONY: destroy
85+
destroy: delete-resource-group ## destroy resources

infra/main.bicep

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Parameters
2+
@description('Specifies the name prefix.')
3+
param prefix string = toLower(uniqueString(resourceGroup().id, location))
4+
5+
@description('Specifies the primary location of Azure resources.')
6+
param location string = resourceGroup().location
7+
8+
@description('Specifies the resource tags.')
9+
param tags object = {}
10+
11+
// OpenAI
12+
@description('Specifies the name of the Azure OpenAI resource.')
13+
param openAiName string = '${prefix}openai'
14+
15+
@description('Specifies the OpenAI deployments to create.')
16+
param openAiDeployments array = []
17+
18+
@description('Specifies the name of the Azure Cognitive Services resource.')
19+
param cognitiveServicesName string = '${prefix}cognitiveServices'
20+
21+
@description('Specifies the name of the Azure Storage Account resource.')
22+
param storageAccountName string = '${prefix}sa'
23+
24+
@description('Specifies the name of the Azure Event Grid resource.')
25+
param eventGridName string = '${prefix}eg'
26+
27+
module openAi './modules/openAi.bicep' = {
28+
name: 'openAi'
29+
params: {
30+
name: openAiName
31+
sku: {
32+
name: 'S0'
33+
}
34+
customSubDomainName: toLower(openAiName)
35+
deployments: openAiDeployments
36+
location: location
37+
tags: tags
38+
}
39+
}
40+
41+
module cognitiveServices './modules/cognitiveServices.bicep' = {
42+
name: 'cognitiveServices'
43+
params: {
44+
name: cognitiveServicesName
45+
sku: {
46+
name: 'S0'
47+
}
48+
customSubDomainName: toLower(cognitiveServicesName)
49+
location: location
50+
tags: tags
51+
}
52+
}
53+
54+
module storageAccount './modules/storageAccount.bicep' = {
55+
name: 'storageAccount'
56+
params: {
57+
name: storageAccountName
58+
containerNames: [
59+
'dev'
60+
'prod'
61+
]
62+
location: location
63+
tags: tags
64+
}
65+
}
66+
67+
module eventGrid './modules/eventGrid.bicep' = {
68+
name: 'eventGrid'
69+
params: {
70+
name: eventGridName
71+
location: location
72+
tags: tags
73+
}
74+
}
75+
76+
// Output
77+
output cognitiveServicesName string = cognitiveServices.outputs.name
78+
output cognitiveServicesEndpoint string = cognitiveServices.outputs.endpoint
79+
output eventGridTopicName string = eventGrid.outputs.eventGridTopicName
80+
output eventGridTopicEndpoint string = eventGrid.outputs.eventGridTopicEndpoint
81+
output openAiName string = openAi.outputs.name
82+
output openAiEndpoint string = openAi.outputs.endpoint
83+
output storageAccountName string = storageAccount.outputs.name

infra/main.parameters.bicepparam

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using 'main.bicep'
2+
3+
param openAiDeployments = [
4+
{
5+
name: 'gpt-35-turbo'
6+
version: '0613'
7+
capacity: 30
8+
}
9+
{
10+
name: 'gpt-4'
11+
version: 'vision-preview'
12+
capacity: 30
13+
}
14+
{
15+
name: 'text-embedding-ada-002'
16+
version: '2'
17+
capacity: 30
18+
}
19+
]
20+
21+
param tags = {
22+
environment: 'dev'
23+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Parameters
2+
@description('Specifies the name of the Azure cognitiveServices resource.')
3+
param name string
4+
5+
@description('Specifies the resource model definition representing SKU.')
6+
param sku object = {
7+
name: 'S0'
8+
}
9+
10+
@description('Specifies the identity of the cognitiveServices resource.')
11+
param identity object = {
12+
type: 'SystemAssigned'
13+
}
14+
15+
@description('Specifies the location.')
16+
param location string = resourceGroup().location
17+
18+
@description('Specifies the resource tags.')
19+
param tags object = {}
20+
21+
@description('Specifies an optional subdomain name used for token-based authentication.')
22+
param customSubDomainName string = ''
23+
24+
@description('Specifies whether or not public endpoint access is allowed for this account..')
25+
@allowed([
26+
'Enabled'
27+
'Disabled'
28+
])
29+
param publicNetworkAccess string = 'Enabled'
30+
31+
// Resources
32+
resource cognitiveServices 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = {
33+
name: name
34+
location: location
35+
sku: sku
36+
kind: 'CognitiveServices'
37+
identity: identity
38+
tags: tags
39+
properties: {
40+
customSubDomainName: customSubDomainName
41+
publicNetworkAccess: publicNetworkAccess
42+
}
43+
}
44+
45+
// Outputs
46+
output id string = cognitiveServices.id
47+
output name string = cognitiveServices.name
48+
output endpoint string = cognitiveServices.properties.endpoint

infra/modules/eventGrid.bicep

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Parameters
2+
@description('Specifies the name prefix.')
3+
param prefix string = uniqueString(resourceGroup().id)
4+
5+
@description('Specifies the primary location of Azure resources.')
6+
param location string = resourceGroup().location
7+
8+
@description('Specifies the resource tags.')
9+
param tags object = {}
10+
11+
@description('Specifies the name of the Azure resource.')
12+
param name string = '${prefix}-eventgrid-topic'
13+
14+
resource eventGridTopic 'Microsoft.EventGrid/topics@2024-06-01-preview' = {
15+
name: name
16+
location: location
17+
tags: tags
18+
kind: 'Azure'
19+
sku: {
20+
name: 'Basic'
21+
}
22+
properties: {
23+
inputSchema: 'EventGridSchema'
24+
minimumTlsVersionAllowed: '1.0'
25+
}
26+
}
27+
28+
// Outputs
29+
output eventGridTopicId string = eventGridTopic.id
30+
output eventGridTopicName string = eventGridTopic.name
31+
output eventGridTopicEndpoint string = eventGridTopic.properties.endpoint

infra/modules/openAi.bicep

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Parameters
2+
@description('Specifies the name of the Azure OpenAI resource.')
3+
param name string
4+
5+
@description('Specifies the resource model definition representing SKU.')
6+
param sku object = {
7+
name: 'S0'
8+
}
9+
10+
@description('Specifies the identity of the OpenAI resource.')
11+
param identity object = {
12+
type: 'SystemAssigned'
13+
}
14+
15+
@description('Specifies the location.')
16+
param location string = resourceGroup().location
17+
18+
@description('Specifies the resource tags.')
19+
param tags object = {}
20+
21+
@description('Specifies an optional subdomain name used for token-based authentication.')
22+
param customSubDomainName string = ''
23+
24+
@description('Specifies whether or not public endpoint access is allowed for this account..')
25+
@allowed([
26+
'Enabled'
27+
'Disabled'
28+
])
29+
param publicNetworkAccess string = 'Enabled'
30+
31+
@description('Specifies the OpenAI deployments to create.')
32+
param deployments array = []
33+
34+
// Resources
35+
resource openAi 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = {
36+
name: name
37+
location: location
38+
sku: sku
39+
kind: 'OpenAI'
40+
identity: identity
41+
tags: tags
42+
properties: {
43+
customSubDomainName: customSubDomainName
44+
publicNetworkAccess: publicNetworkAccess
45+
}
46+
}
47+
48+
@batchSize(1)
49+
resource model 'Microsoft.CognitiveServices/accounts/deployments@2023-10-01-preview' = [for deployment in deployments: {
50+
name: deployment.name
51+
parent: openAi
52+
properties: {
53+
model: {
54+
format: 'OpenAI'
55+
name: deployment.name
56+
version: deployment.version
57+
}
58+
currentCapacity: deployment.capacity
59+
raiPolicyName: contains(deployment, 'raiPolicyName') ? deployment.raiPolicyName : null
60+
versionUpgradeOption: contains(deployment, 'versionUpgradeOption') ? deployment.versionUpgradeOption : 'OnceNewDefaultVersionAvailable'
61+
}
62+
sku: contains(deployment, 'sku') ? deployment.sku : {
63+
name: 'Standard'
64+
capacity: deployment.capacity
65+
}
66+
}]
67+
68+
// Outputs
69+
output id string = openAi.id
70+
output name string = openAi.name
71+
output endpoint string = openAi.properties.endpoint

0 commit comments

Comments
 (0)