Spaces:
Sleeping
Sleeping
Sync from GitHub via hub-sync
Browse filesFiles changed (2)
- README.md+49
- infra/bicep/main.bicepAdded+177
204 unmodified lines205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259204 unmodified linesFACEVERIFICATION_JWT_SECRET_KEY```
### Azure Container Apps
The FastAPI image can also be deployed as an ephemeral Azure Container App fromthe GHCR image published by the container workflow.
The deployment is defined in `infra/bicep/main.bicep` and is wired to`.github/workflows/deploy-azure-container-app.yml`. The workflow:
- creates or reuses the Azure resource group configured in GitHub repository variables;- deploys a Log Analytics workspace, Container Apps environment, and FastAPI Container App;- runs the published `ghcr.io/leandrodevai/faceverification:fastapi` image;- keeps the app ephemeral with no mounted volume or external vector database;- configures `minReplicas: 0` and `maxReplicas: 1`;- smoke tests `GET /health` after deployment.
Required GitHub repository variables:
```textAZURE_CLIENT_IDAZURE_LOCATIONAZURE_RESOURCE_GROUPAZURE_TENANT_IDAZURE_SUBSCRIPTION_ID```
Required GitHub repository secrets:
```textFACEVERIFICATION_DEMO_USERNAMEFACEVERIFICATION_DEMO_PASSWORDFACEVERIFICATION_JWT_SECRET_KEY```
Optional GitHub repository secrets for private GHCR packages:
```textGHCR_PULL_USERNAMEGHCR_PULL_TOKEN```
If the GHCR package is public, those optional secrets can be omitted. If it isprivate, `GHCR_PULL_TOKEN` must be a GitHub token with package read access.
To avoid ongoing cost while keeping the OIDC and RBAC setup intact, remove thedemo resources inside the configured resource group from Azure when they are nolonger needed.
Example enrollment request:
```bash123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177targetScope = 'resourceGroup'
@description('Azure region for the Container Apps resources.')param location string = resourceGroup().location
@description('Name of the Azure Container App.')param containerAppName string = 'faceverification-api'
@description('Name of the Container Apps managed environment.')param containerAppsEnvironmentName string = 'cae-faceverification-dev'
@description('Name of the Log Analytics workspace used by Container Apps.')param logAnalyticsWorkspaceName string = 'law-faceverification-dev'
@description('Tags applied to all resources created by this deployment.')param tags object = { app: 'faceverification' environment: 'dev' managedBy: 'bicep'}
@description('Container image to deploy.')param image string
@description('FastAPI container port.')param targetPort int = 8000
@description('CPU cores allocated to the app container.')param cpu string = '2.0'
@description('Memory allocated to the app container.')param memory string = '4Gi'
@description('Demo username for the protected API endpoints.')@secure()param demoUsername string
@description('Demo password for the protected API endpoints.')@secure()param demoPassword string
@description('JWT signing secret for the FastAPI demo auth.')@secure()param jwtSecretKey string
@description('Optional GHCR username for private package pulls.')param registryUsername string = ''
@description('Optional GHCR token for private package pulls. Leave empty for public packages.')@secure()param registryPassword string = ''
var registryServer = 'ghcr.io'var appSecrets = concat([ { name: 'demo-username' value: demoUsername } { name: 'demo-password' value: demoPassword } { name: 'jwt-secret-key' value: jwtSecretKey }], empty(registryPassword) ? [] : [ { name: 'ghcr-password' value: registryPassword }])
var registries = empty(registryPassword) ? [] : [ { server: registryServer username: registryUsername passwordSecretRef: 'ghcr-password' }]
resource logs 'Microsoft.OperationalInsights/workspaces@2023-09-01' = { name: logAnalyticsWorkspaceName location: location tags: tags properties: { sku: { name: 'PerGB2018' } retentionInDays: 30 }}
resource environment 'Microsoft.App/managedEnvironments@2024-03-01' = { name: containerAppsEnvironmentName location: location tags: tags properties: { appLogsConfiguration: { destination: 'log-analytics' logAnalyticsConfiguration: { customerId: logs.properties.customerId sharedKey: logs.listKeys().primarySharedKey } } }}
resource app 'Microsoft.App/containerApps@2024-03-01' = { name: containerAppName location: location tags: tags properties: { managedEnvironmentId: environment.id configuration: { activeRevisionsMode: 'Single' ingress: { external: true targetPort: targetPort transport: 'auto' allowInsecure: false } secrets: appSecrets registries: registries } template: { containers: [ { name: 'api' image: image env: [ { name: 'APP_VARIANT' value: 'fastapi' } { name: 'FACEVERIFICATION_DEVICE' value: 'cpu' } { name: 'FACEVERIFICATION_DEMO_USERNAME' secretRef: 'demo-username' } { name: 'FACEVERIFICATION_DEMO_PASSWORD' secretRef: 'demo-password' } { name: 'FACEVERIFICATION_JWT_SECRET_KEY' secretRef: 'jwt-secret-key' } ] resources: { cpu: json(cpu) memory: memory } } ] scale: { minReplicas: 0 maxReplicas: 1 rules: [ { name: 'http-scale' http: { metadata: { concurrentRequests: '10' } } } ] } } }}
output appUrl string = 'https://${app.properties.configuration.ingress.fqdn}'README.md+49
infra/bicep/main.bicepAdded+177