-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EES-4765 Provision API container app
- Loading branch information
Showing
9 changed files
with
322 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
metadata description = 'Creates a container app in an Azure Container App environment.' | ||
param name string | ||
param location string = resourceGroup().location | ||
param tags object = {} | ||
|
||
@description('Allowed origins') | ||
param allowedOrigins array = [] | ||
|
||
@description('Name of the environment for container apps') | ||
param containerAppsEnvironmentName string | ||
|
||
@description('CPU cores allocated to a single container instance, e.g., 0.5') | ||
param containerCpuCoreCount string = '0.5' | ||
|
||
@description('The maximum number of replicas to run. Must be at least 1.') | ||
@minValue(1) | ||
param containerMaxReplicas int = 10 | ||
|
||
@description('Memory allocated to a single container instance, e.g., 1Gi') | ||
param containerMemory string = '1.0Gi' | ||
|
||
@description('The minimum number of replicas to run. Must be at least 1.') | ||
param containerMinReplicas int = 1 | ||
|
||
@description('The name of the container') | ||
param containerName string = 'main' | ||
|
||
@description('The name of the container registry') | ||
param containerRegistryName string = '' | ||
|
||
@description('The protocol used by Dapr to connect to the app, e.g., http or grpc') | ||
@allowed([ 'http', 'grpc' ]) | ||
param daprAppProtocol string = 'http' | ||
|
||
@description('The Dapr app ID') | ||
param daprAppId string = containerName | ||
|
||
@description('Enable Dapr') | ||
param daprEnabled bool = false | ||
|
||
@description('The environment variables for the container') | ||
param env array = [] | ||
|
||
@description('Specifies if the resource ingress is exposed externally') | ||
param external bool = true | ||
|
||
@description('The name of the user-assigned identity') | ||
param identityName string = '' | ||
|
||
@description('The name of the container image') | ||
param imageName string = '' | ||
|
||
@description('Specifies if the resource already exists') | ||
param exists bool = false | ||
|
||
@description('Specifies if Ingress is enabled for the container app') | ||
param ingressEnabled bool = true | ||
|
||
param revisionMode string = 'Single' | ||
|
||
@description('The secrets required for the container') | ||
param secrets array = [] | ||
|
||
@description('The service binds associated with the container') | ||
param serviceBinds array = [] | ||
|
||
@description('The name of the container apps add-on to use. e.g. redis') | ||
param serviceType string = '' | ||
|
||
@description('The target port for the container') | ||
param targetPort int = 80 | ||
|
||
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-04-01-preview' existing = { | ||
name: containerAppsEnvironmentName | ||
} | ||
|
||
resource existingApp 'Microsoft.App/containerApps@2023-04-01-preview' existing = if (exists) { | ||
name: name | ||
} | ||
|
||
resource userIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = { | ||
name: identityName | ||
} | ||
|
||
resource app 'Microsoft.App/containerApps@2023-04-01-preview' = { | ||
name: name | ||
location: location | ||
tags: tags | ||
// It is critical that the identity is granted ACR pull access before the app is created | ||
// otherwise the container app will throw a provision error | ||
// This also forces us to use an user assigned managed identity since there would no way to | ||
// provide the system assigned identity with the ACR pull access before the app is created | ||
identity: { | ||
type: 'UserAssigned' | ||
userAssignedIdentities: { '${userIdentity.id}': {} } | ||
} | ||
properties: { | ||
managedEnvironmentId: containerAppsEnvironment.id | ||
configuration: { | ||
activeRevisionsMode: revisionMode | ||
ingress: ingressEnabled ? { | ||
external: external | ||
targetPort: targetPort | ||
transport: 'auto' | ||
corsPolicy: { | ||
allowedOrigins: union([ 'https://portal.azure.com', 'https://ms.portal.azure.com' ], allowedOrigins) | ||
} | ||
} : null | ||
dapr: daprEnabled ? { | ||
enabled: true | ||
appId: daprAppId | ||
appProtocol: daprAppProtocol | ||
appPort: ingressEnabled ? targetPort : 0 | ||
} : { enabled: false } | ||
secrets: secrets | ||
service: !empty(serviceType) ? { type: serviceType } : null | ||
registries: [ | ||
{ | ||
server: '${containerRegistryName}.azurecr.io' | ||
identity: userIdentity.id | ||
} | ||
] | ||
} | ||
template: { | ||
serviceBinds: !empty(serviceBinds) ? serviceBinds : null | ||
containers: [ | ||
{ | ||
image: !empty(imageName) ? imageName : exists ? existingApp.properties.template.containers[0].image : 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest' | ||
name: containerName | ||
env: env | ||
resources: { | ||
cpu: json(containerCpuCoreCount) | ||
memory: containerMemory | ||
} | ||
} | ||
] | ||
scale: { | ||
minReplicas: containerMinReplicas | ||
maxReplicas: containerMaxReplicas | ||
} | ||
} | ||
} | ||
} | ||
|
||
output defaultDomain string = containerAppsEnvironment.properties.defaultDomain | ||
output identityPrincipalId string = userIdentity.properties.principalId | ||
output imageName string = imageName | ||
output name string = app.name | ||
output serviceBind object = !empty(serviceType) ? { serviceId: app.id, name: name } : {} | ||
output uri string = ingressEnabled ? 'https://${app.properties.configuration.ingress.fqdn}' : '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.