Skip to content

Commit e9f948c

Browse files
update bicep and azd template to build and deploy container app and app service from local while deploying
1 parent e10aa37 commit e9f948c

6 files changed

Lines changed: 113 additions & 17 deletions

File tree

azure.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,26 @@ name: multi-agent-custom-automation-engine-solution-accelerator
33
metadata:
44
template: multi-agent-custom-automation-engine-solution-accelerator@1.0
55
requiredVersions:
6-
azd: ">=1.15.0 !=1.17.1"
6+
azd: ">=1.15.0 !=1.17.1"
7+
8+
services:
9+
backend:
10+
project: ./src/backend
11+
language: py
12+
host: containerapp
13+
docker:
14+
image: backend
15+
remoteBuild: true
16+
17+
frontend:
18+
project: ./src/frontend
19+
language: py
20+
host: appservice
21+
dist: ./dist
22+
hooks:
23+
prepackage:
24+
windows:
25+
shell: pwsh
26+
run: ../../infra/scripts/package_frontend.ps1
27+
interactive: true
28+
continueOnError: false

infra/main.bicep

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ param containerAppConfiguration containerAppConfigurationType = {
195195
enabled: true
196196
name: 'ca-${solutionPrefix}'
197197
location: solutionLocation
198-
tags: tags
198+
tags: union(tags, { 'azd-service-name': 'backend' })
199199
environmentResourceId: null //Default value set on module configuration
200200
concurrentRequests: '100'
201201
containerCpu: '2.0'
202202
containerMemory: '4.0Gi'
203-
containerImageRegistryDomain: 'biabcontainerreg.azurecr.io'
203+
containerImageRegistryDomain: ''
204204
containerImageName: 'macaebackend'
205205
containerImageTag: imageTag
206206
containerName: 'backend'
@@ -228,7 +228,7 @@ param webSiteConfiguration webSiteConfigurationType = {
228228
containerImageName: 'macaefrontend'
229229
containerImageTag: imageTag
230230
containerName: 'backend'
231-
tags: tags
231+
tags: union(tags, { 'azd-service-name': 'frontend' })
232232
environmentResourceId: null //Default value set on module configuration
233233
}
234234

@@ -901,6 +901,33 @@ module cosmosDb 'br/public:avm/res/document-db/database-account:0.12.0' = if (co
901901
}
902902
}
903903

904+
// ========== Container Registry ========== //
905+
module containerRegistry 'br/public:avm/res/container-registry/registry:0.9.1' = {
906+
name: 'registryDeployment'
907+
params: {
908+
name: 'cr${solutionPrefix}'
909+
acrAdminUserEnabled: false
910+
acrSku: 'Basic'
911+
azureADAuthenticationAsArmPolicyStatus: 'enabled'
912+
exportPolicyStatus: 'enabled'
913+
location: solutionLocation
914+
softDeletePolicyDays: 7
915+
softDeletePolicyStatus: 'disabled'
916+
tags: tags
917+
networkRuleBypassOptions: 'AzureServices'
918+
roleAssignments: [
919+
{
920+
roleDefinitionIdOrName: acrPullRole
921+
principalType: 'ServicePrincipal'
922+
principalId: userAssignedIdentity.outputs.principalId
923+
}
924+
]
925+
}
926+
}
927+
928+
var acrPullRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')
929+
930+
904931
// ========== Backend Container App Environment ========== //
905932
// WAF best practices for container apps: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/azure-container-apps
906933
var containerAppEnvironmentEnabled = containerAppEnvironmentConfiguration.?enabled ?? true
@@ -962,10 +989,16 @@ module containerApp 'br/public:avm/res/app/container-app:0.14.2' = if (container
962989
}
963990
]
964991
}
992+
registries: [
993+
{
994+
server: containerRegistry.outputs.loginServer
995+
identity: userAssignedIdentity.outputs.resourceId
996+
}
997+
]
965998
containers: [
966999
{
9671000
name: containerAppConfiguration.?containerName ?? 'backend'
968-
image: '${containerAppConfiguration.?containerImageRegistryDomain ?? 'biabcontainerreg.azurecr.io'}/${containerAppConfiguration.?containerImageName ?? 'macaebackend'}:${containerAppConfiguration.?containerImageTag ?? 'latest'}'
1001+
image: 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
9691002
resources: {
9701003
//TODO: Make cpu and memory parameterized
9711004
cpu: containerAppConfiguration.?containerCpu ?? '2.0'
@@ -1069,22 +1102,26 @@ module webSite 'br/public:avm/res/web/site:0.15.1' = if (webSiteEnabled) {
10691102
name: webSiteName
10701103
tags: webSiteConfiguration.?tags ?? tags
10711104
location: webSiteConfiguration.?location ?? solutionLocation
1072-
kind: 'app,linux,container'
1105+
kind: 'app,linux'
1106+
// kind: 'app,linux,container'
10731107
enableTelemetry: enableTelemetry
10741108
serverFarmResourceId: webSiteConfiguration.?environmentResourceId ?? webServerFarm.?outputs.resourceId
10751109
appInsightResourceId: applicationInsights.outputs.resourceId
10761110
diagnosticSettings: [{ workspaceResourceId: logAnalyticsWorkspaceId }]
10771111
publicNetworkAccess: 'Enabled' //TODO: use Azure Front Door WAF or Application Gateway WAF instead
10781112
siteConfig: {
1079-
linuxFxVersion: 'DOCKER|${webSiteConfiguration.?containerImageRegistryDomain ?? 'biabcontainerreg.azurecr.io'}/${webSiteConfiguration.?containerImageName ?? 'macaefrontend'}:${webSiteConfiguration.?containerImageTag ?? 'latest'}'
1113+
// linuxFxVersion: 'DOCKER|${webSiteConfiguration.?containerImageRegistryDomain ?? 'biabcontainerreg.azurecr.io'}/${webSiteConfiguration.?containerImageName ?? 'macaefrontend'}:${webSiteConfiguration.?containerImageTag ?? 'latest'}'
1114+
linuxFxVersion: 'python|3.11'
1115+
appCommandLine: 'python3 -m uvicorn frontend_server:app --host 0.0.0.0 --port 8000'
10801116
}
10811117
appSettingsKeyValuePairs: {
1082-
SCM_DO_BUILD_DURING_DEPLOYMENT: 'true'
1083-
DOCKER_REGISTRY_SERVER_URL: 'https://${webSiteConfiguration.?containerImageRegistryDomain ?? 'biabcontainerreg.azurecr.io'}'
1084-
WEBSITES_PORT: '3000'
1085-
WEBSITES_CONTAINER_START_TIME_LIMIT: '1800' // 30 minutes, adjust as needed
1118+
SCM_DO_BUILD_DURING_DEPLOYMENT: 'True'
1119+
// DOCKER_REGISTRY_SERVER_URL: 'https://${webSiteConfiguration.?containerImageRegistryDomain ?? 'biabcontainerreg.azurecr.io'}'
1120+
WEBSITES_PORT: '8000'
1121+
// WEBSITES_CONTAINER_START_TIME_LIMIT: '1800' // 30 minutes, adjust as needed
10861122
BACKEND_API_URL: 'https://${containerApp.outputs.fqdn}'
10871123
AUTH_ENABLED: 'false'
1124+
ENABLE_ORYX_BUILD: 'True'
10881125
}
10891126
}
10901127
}
@@ -1098,6 +1135,21 @@ module webSite 'br/public:avm/res/web/site:0.15.1' = if (webSiteEnabled) {
10981135
@description('The default url of the website to connect to the Multi-Agent Custom Automation Engine solution.')
10991136
output webSiteDefaultHostname string = webSite.outputs.defaultHostname
11001137

1138+
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerRegistry.outputs.loginServer
1139+
1140+
// @description('The name of the resource.')
1141+
// output name string = <Resource>.name
1142+
1143+
// @description('The location the resource was deployed into.')
1144+
// output location string = <Resource>.location
1145+
1146+
// ================ //
1147+
// Definitions //
1148+
// ================ //
1149+
//
1150+
// Add your User-defined-types here, if any
1151+
//
1152+
11011153
@export()
11021154
@description('The type for the Multi-Agent Custom Automation Engine Log Analytics Workspace resource configuration.')
11031155
type logAnalyticsWorkspaceConfigurationType = {

infra/scripts/package_frontend.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mkdir dist -Force
2+
rm dist/* -r -Force
3+
4+
# Python
5+
cp requirements.txt dist -Force
6+
cp *.py dist -Force
7+
8+
# Node
9+
npm install
10+
npm run build
11+
cp -r build dist -Force

infra/scripts/package_frontend.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -eou pipefail
3+
4+
mkdir -p dist
5+
rm -rf dist/*
6+
7+
#python
8+
cp -f requirements.txt dist
9+
cp -f *.py dist
10+
11+
#node
12+
npm install
13+
npm run build
14+
cp -rf build dist

src/backend/Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ WORKDIR /app
1010
COPY uv.lock pyproject.toml /app/
1111

1212
# Install the project's dependencies using the lockfile and settings
13-
RUN --mount=type=cache,target=/root/.cache/uv \
14-
--mount=type=bind,source=uv.lock,target=uv.lock \
15-
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
16-
uv sync --frozen --no-install-project --no-dev
13+
RUN uv sync --frozen --no-install-project --no-dev
1714

1815
# Backend app setup
1916
COPY . /app
20-
RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev
17+
RUN uv sync --frozen --no-dev
2118

2219
FROM base
2320

src/frontend/frontend_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ async def serve_app(full_path: str):
5959

6060

6161
if __name__ == "__main__":
62-
uvicorn.run(app, host="127.0.0.1", port=3000)
62+
uvicorn.run(app, host="127.0.0.1", port=8000)

0 commit comments

Comments
 (0)