-
Notifications
You must be signed in to change notification settings - Fork 5k
Add Azure Container Apps as a host option #1952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
d721099
Update bicep for ACA
1yefuwang1 30f00e5
First working version
1yefuwang1 72e34d2
Support workload profile
1yefuwang1 55a97fd
Merge branch 'Azure-Samples:main' into main
1yefuwang1 7edd2db
Add support for CORS and fix identity for openai
1yefuwang1 8fc2d5a
Add aca-host
1yefuwang1 9cadd14
Make acr unique
1yefuwang1 0623e9b
Add doc for aca host
1yefuwang1 73b2bb3
Merge branch 'Azure-Samples:main' into yefu/aca
1yefuwang1 e362545
Update ACA docs
1yefuwang1 24d668a
Remove unneeded bicep files
1yefuwang1 fbb4b05
Revert chanes to infra/main.parameters.json
1yefuwang1 4ced7ce
Fix markdown lint issues
1yefuwang1 625866f
Run frontend build before building docker image
1yefuwang1 40287f2
remove symlinks and update scripts with paths relative to its own fol…
1yefuwang1 a99a6c5
Merge with main.bicep
1yefuwang1 9dc65ca
output AZURE_CONTAINER_REGISTRY_ENDPOINT
1yefuwang1 7f523a0
Fix deployment with app service
1yefuwang1 9e6e145
Improve naming and README
1yefuwang1 4ec32f7
Fix identity name and cost esitmation for aca
1yefuwang1 4174fd3
Share env vars in bicep and update docs
1yefuwang1 7e49c99
Revert "remove symlinks and update scripts with paths relative to its…
1yefuwang1 259e7a5
Add containerapps as a commented out host option
1yefuwang1 920e979
Update app/backend/.dockerignore
pamelafox eb09e46
Apply suggestions from code review
pamelafox 56025eb
Merge branch 'main' into yefu/aca
pamelafox 13021cb
More steps for deployment guide
pamelafox 8b19702
Update azure.yaml
pamelafox 6550960
Merge branch 'main' into yefu/aca
pamelafox d49f60c
Update comment
pamelafox 11837ba
cleanup bicep files and improve docs
1yefuwang1 560076b
Update condition for running in production for credential
pamelafox 5682b67
Merge branch 'yefu/aca' of https://github.com/tawalke/azure-search-op…
pamelafox 8d3edb0
Update ManagedIdentityCredential to use UAMI for containerapps
1yefuwang1 8f08b3f
Merge branch 'main' into yefu/aca
pamelafox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -22,6 +22,7 @@ contact [[email protected]](mailto:[email protected]) with any additio | |
- [Running unit tests](#running-unit-tests) | ||
- [Running E2E tests](#running-e2e-tests) | ||
- [Code Style](#code-style) | ||
- [Adding new azd environment variables](#add-new-azd-environment-variables) | ||
|
||
## Code of Conduct | ||
|
||
|
@@ -160,3 +161,10 @@ python -m black <path-to-file> | |
``` | ||
|
||
If you followed the steps above to install the pre-commit hooks, then you can just wait for those hooks to run `ruff` and `black` for you. | ||
|
||
## Adding new azd environment variables | ||
|
||
When adding new azd environment variables, please remember to update: | ||
1. App Service's [azure.yaml](./azure.yaml) | ||
1. [ADO pipeline](.azdo/pipelines/azure-dev.yml). | ||
1. [Github workflows](.github/workflows/azure-dev.yml) |
This file contains hidden or 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 hidden or 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,7 @@ | ||
.git | ||
__pycache__ | ||
*.pyc | ||
*.pyo | ||
*.pyd | ||
.Python | ||
env |
This file contains hidden or 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,11 @@ | ||
FROM python:3.11-bullseye | ||
|
||
WORKDIR /app | ||
|
||
COPY ./ /app | ||
|
||
RUN python -m pip install -r requirements.txt | ||
|
||
RUN python -m pip install gunicorn | ||
|
||
CMD ["python3", "-m", "gunicorn", "-b", "0.0.0.0:8000", "main:app"] |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
# Deploying on Azure Container Apps | ||
1yefuwang1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Due to [a limitation](https://github.com/Azure/azure-dev/issues/2736) of the Azure Developer CLI (`azd`), there can be only one host option in the [azure.yaml](../azure.yaml) file. | ||
By default, `host: appservice` is used and `host: containerapp` is commented out. | ||
|
||
To deploy to Azure Container Apps, please follow the following steps: | ||
|
||
1. Comment out `host: appservice` and uncomment `host: containerapp` in the [azure.yaml](../azure.yaml) file. | ||
|
||
2. Login to your Azure account: | ||
|
||
```bash | ||
azd auth login | ||
``` | ||
|
||
3. Create a new `azd` environment to store the deployment parameters: | ||
|
||
```bash | ||
azd env new | ||
``` | ||
|
||
Enter a name that will be used for the resource group. | ||
This will create a new folder in the `.azure` folder, and set it as the active environment for any calls to `azd` going forward. | ||
|
||
4. Set the deployment target to `containerapps`: | ||
|
||
```bash | ||
azd env set DEPLOYMENT_TARGET containerapps | ||
``` | ||
|
||
5. (Optional) This is the point where you can customize the deployment by setting other `azd1 environment variables, in order to [use existing resources](docs/deploy_existing.md), [enable optional features (such as auth or vision)](docs/deploy_features.md), or [deploy to free tiers](docs/deploy_lowcost.md). | ||
6. Provision the resources and deploy the code: | ||
```bash | ||
azd up | ||
``` | ||
|
||
This will provision Azure resources and deploy this sample to those resources, including building the search index based on the files found in the `./data` folder. | ||
|
||
**Important**: Beware that the resources created by this command will incur immediate costs, primarily from the AI Search resource. These resources may accrue costs even if you interrupt the command before it is fully executed. You can run `azd down` or delete the resources manually to avoid unnecessary spending. | ||
|
||
## Customizing Workload Profile | ||
|
||
The default workload profile is Consumption. If you want to use a dedicated workload profile like D4, please run: | ||
|
||
```bash | ||
azd env AZURE_CONTAINER_APPS_WORKLOAD_PROFILE D4 | ||
``` | ||
|
||
For a full list of workload profiles, please check [here](https://learn.microsoft.com/azure/container-apps/workload-profiles-overview#profile-types). | ||
Please note dedicated workload profiles have a different billing model than Consumption plan. Please check [here](https://learn.microsoft.com/azure/container-apps/billing) for details. | ||
|
||
## Private endpoints | ||
|
||
Private endpoints is still in private preview for Azure Conainer Apps and not supported for now. |
This file contains hidden or 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 hidden or 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,130 @@ | ||
metadata description = 'Creates or updates an existing Azure Container App.' | ||
param name string | ||
param location string = resourceGroup().location | ||
param tags object = {} | ||
|
||
|
||
@description('The number of 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('The amount of 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.') | ||
@minValue(1) | ||
param containerMinReplicas int = 1 | ||
|
||
@description('The name of the container') | ||
param containerName string = 'main' | ||
|
||
@description('The environment name for the container apps') | ||
param containerAppsEnvironmentName string = '${containerName}env' | ||
|
||
@description('The name of the container registry') | ||
param containerRegistryName string | ||
|
||
@description('Hostname suffix for container registry. Set when deploying to sovereign clouds') | ||
param containerRegistryHostSuffix string = 'azurecr.io' | ||
|
||
@allowed(['http', 'grpc']) | ||
@description('The protocol used by Dapr to connect to the app, e.g., HTTP or gRPC') | ||
param daprAppProtocol string = 'http' | ||
|
||
@description('Enable or disable Dapr for the container app') | ||
param daprEnabled bool = false | ||
|
||
@description('The Dapr app ID') | ||
param daprAppId string = containerName | ||
|
||
@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 | ||
|
||
@description('The type of identity for the resource') | ||
@allowed(['None', 'SystemAssigned', 'UserAssigned']) | ||
param identityType string = 'None' | ||
|
||
@description('The name of the user-assigned identity') | ||
param identityName string = '' | ||
|
||
@description('The name of the container image') | ||
param imageName string = '' | ||
|
||
@description('The secrets required for the container') | ||
@secure() | ||
param secrets object = {} | ||
|
||
@description('The keyvault identities required for the container') | ||
@secure() | ||
param keyvaultIdentities object = {} | ||
|
||
@description('The environment variables for the container in key value pairs') | ||
param env object = {} | ||
|
||
@description('Specifies if the resource ingress is exposed externally') | ||
param external bool = true | ||
|
||
@description('The service binds associated with the container') | ||
param serviceBinds array = [] | ||
|
||
@description('The target port for the container') | ||
param targetPort int = 80 | ||
|
||
@allowed(['Consumption', 'D4', 'D8', 'D16', 'D32', 'E4', 'E8', 'E16', 'E32', 'NC24-A100', 'NC48-A100', 'NC96-A100']) | ||
param workloadProfile string = 'Consumption' | ||
|
||
param allowedOrigins array = [] | ||
|
||
resource existingApp 'Microsoft.App/containerApps@2023-05-02-preview' existing = if (exists) { | ||
name: name | ||
} | ||
|
||
module app 'container-app.bicep' = { | ||
name: '${deployment().name}-update' | ||
params: { | ||
name: name | ||
workloadProfile: workloadProfile | ||
location: location | ||
tags: tags | ||
identityType: identityType | ||
identityName: identityName | ||
ingressEnabled: ingressEnabled | ||
containerName: containerName | ||
containerAppsEnvironmentName: containerAppsEnvironmentName | ||
containerRegistryName: containerRegistryName | ||
containerRegistryHostSuffix: containerRegistryHostSuffix | ||
containerCpuCoreCount: containerCpuCoreCount | ||
containerMemory: containerMemory | ||
containerMinReplicas: containerMinReplicas | ||
containerMaxReplicas: containerMaxReplicas | ||
daprEnabled: daprEnabled | ||
daprAppId: daprAppId | ||
daprAppProtocol: daprAppProtocol | ||
secrets: secrets | ||
keyvaultIdentities: keyvaultIdentities | ||
allowedOrigins: allowedOrigins | ||
external: external | ||
env: [ | ||
for key in objectKeys(env): { | ||
name: key | ||
value: '${env[key]}' | ||
} | ||
] | ||
imageName: !empty(imageName) ? imageName : exists ? existingApp.properties.template.containers[0].image : '' | ||
targetPort: targetPort | ||
serviceBinds: serviceBinds | ||
} | ||
} | ||
|
||
output defaultDomain string = app.outputs.defaultDomain | ||
output imageName string = app.outputs.imageName | ||
output name string = app.outputs.name | ||
output uri string = app.outputs.uri | ||
output id string = app.outputs.id | ||
output identityPrincipalId string = app.outputs.identityPrincipalId |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.