From 0aa941bcb4a911ed1866e6c37c2c061af7db9ebd Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 9 Feb 2024 10:37:37 +0100 Subject: [PATCH] fix: add base uri for web api (#425) After APIM is removed, we need to add the base uri for the container app in app configuration and use that in the swagger and when we publish events. --- .azure/applications/web-api-eu/main.bicep | 16 ++++--- .../web-api-eu/staging.bicepparam | 2 +- .../applications/web-api-eu/test.bicepparam | 2 +- .../web-api-migration-job/main.bicep | 8 +++- .../web-api-migration-job/staging.bicepparam | 6 +-- .../web-api-migration-job/test.bicepparam | 2 +- .azure/applications/web-api-so/main.bicep | 44 ++++++++++++++----- .../web-api-so/staging.bicepparam | 2 +- .../applications/web-api-so/test.bicepparam | 2 +- .github/workflows/action-deploy-apps.yml | 6 +-- .github/workflows/ci-cd-main.yml | 2 +- 11 files changed, 60 insertions(+), 32 deletions(-) diff --git a/.azure/applications/web-api-eu/main.bicep b/.azure/applications/web-api-eu/main.bicep index dac67b98d..7de2ad411 100644 --- a/.azure/applications/web-api-eu/main.bicep +++ b/.azure/applications/web-api-eu/main.bicep @@ -9,11 +9,11 @@ param location string @minLength(3) @secure() -param containerAppEnvironmentId string +param containerAppEnvironmentName string @minLength(3) @secure() param appInsightConnectionString string -@minLength(3) +@minLength(5) @secure() param appConfigurationName string @minLength(3) @@ -23,8 +23,12 @@ param environmentKeyVaultName string var namePrefix = 'dp-be-${environment}' var baseImageUrl = 'ghcr.io/digdir/dialogporten-' -resource appConfig 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = { - name: '${namePrefix}-appConfiguration' +resource appConfiguration 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = { + name: appConfigurationName +} + +resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = { + name: containerAppEnvironmentName } var containerAppEnvVars = [ @@ -38,7 +42,7 @@ var containerAppEnvVars = [ } { name: 'AZURE_APPCONFIG_URI' - value: appConfig.properties.endpoint + value: appConfiguration.properties.endpoint } { name: 'ASPNETCORE_URLS' @@ -59,7 +63,7 @@ module containerApp '../../modules/containerApp/main.bicep' = { image: '${baseImageUrl}webapi:${imageTag}' location: location envVariables: containerAppEnvVars - containerAppEnvId: containerAppEnvironmentId + containerAppEnvId: containerAppEnvironment.id } } diff --git a/.azure/applications/web-api-eu/staging.bicepparam b/.azure/applications/web-api-eu/staging.bicepparam index 589cc8ceb..fdc6bc1fa 100644 --- a/.azure/applications/web-api-eu/staging.bicepparam +++ b/.azure/applications/web-api-eu/staging.bicepparam @@ -6,6 +6,6 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG') // secrets param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME') -param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID') +param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME') param appInsightConnectionString = readEnvironmentVariable('APP_INSIGHTS_CONNECTION_STRING') param appConfigurationName = readEnvironmentVariable('APP_CONFIGURATION_NAME') diff --git a/.azure/applications/web-api-eu/test.bicepparam b/.azure/applications/web-api-eu/test.bicepparam index efe327b64..3d72092e7 100644 --- a/.azure/applications/web-api-eu/test.bicepparam +++ b/.azure/applications/web-api-eu/test.bicepparam @@ -6,6 +6,6 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG') // secrets param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME') -param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID') +param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME') param appInsightConnectionString = readEnvironmentVariable('APP_INSIGHTS_CONNECTION_STRING') param appConfigurationName = readEnvironmentVariable('APP_CONFIGURATION_NAME') diff --git a/.azure/applications/web-api-migration-job/main.bicep b/.azure/applications/web-api-migration-job/main.bicep index 7e6ecdd51..db2470faf 100644 --- a/.azure/applications/web-api-migration-job/main.bicep +++ b/.azure/applications/web-api-migration-job/main.bicep @@ -9,7 +9,7 @@ param location string @minLength(3) @secure() -param containerAppEnvironmentId string +param containerAppEnvironmentName string @minLength(3) @secure() param adoConnectionStringSecretUri string @@ -19,13 +19,17 @@ var baseImageUrl = 'ghcr.io/digdir/dialogporten-' var name = '${namePrefix}-db-migration-job' +resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = { + name: containerAppEnvironmentName +} + module migrationJob '../../modules/containerAppJob/main.bicep' = { name: name params: { name: name location: location image: '${baseImageUrl}migration-bundle:${imageTag}' - containerAppEnvId: containerAppEnvironmentId + containerAppEnvId: containerAppEnvironment.id adoConnectionStringSecretUri: adoConnectionStringSecretUri } } diff --git a/.azure/applications/web-api-migration-job/staging.bicepparam b/.azure/applications/web-api-migration-job/staging.bicepparam index d4705b812..581936cc5 100644 --- a/.azure/applications/web-api-migration-job/staging.bicepparam +++ b/.azure/applications/web-api-migration-job/staging.bicepparam @@ -2,8 +2,8 @@ using './main.bicep' param environment = 'staging' param location = 'norwayeast' -param imageTag = readEnvironmentVariable('IMAGE_TAG', '') -param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID', '') +param imageTag = readEnvironmentVariable('IMAGE_TAG') +param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME') //secrets -param adoConnectionStringSecretUri = readEnvironmentVariable('ADO_CONNECTION_STRING_SECRET_URI', '') +param adoConnectionStringSecretUri = readEnvironmentVariable('ADO_CONNECTION_STRING_SECRET_URI') diff --git a/.azure/applications/web-api-migration-job/test.bicepparam b/.azure/applications/web-api-migration-job/test.bicepparam index 005a0c089..e5e3696a6 100644 --- a/.azure/applications/web-api-migration-job/test.bicepparam +++ b/.azure/applications/web-api-migration-job/test.bicepparam @@ -5,5 +5,5 @@ param location = 'norwayeast' //secrets param imageTag = readEnvironmentVariable('IMAGE_TAG') -param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID') +param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME') param adoConnectionStringSecretUri = readEnvironmentVariable('ADO_CONNECTION_STRING_SECRET_URI') diff --git a/.azure/applications/web-api-so/main.bicep b/.azure/applications/web-api-so/main.bicep index bbd0007f6..28b53c50c 100644 --- a/.azure/applications/web-api-so/main.bicep +++ b/.azure/applications/web-api-so/main.bicep @@ -1,30 +1,37 @@ targetScope = 'resourceGroup' -@minLength(1) +@minLength(3) param imageTag string -@minLength(1) +@minLength(3) param environment string -@minLength(1) +@minLength(3) param location string -@minLength(1) +@minLength(3) @secure() -param containerAppEnvironmentId string -@minLength(1) +param containerAppEnvironmentName string +@minLength(3) @secure() param appInsightConnectionString string -@minLength(1) +@minLength(5) @secure() param appConfigurationName string -@minLength(1) +@minLength(3) @secure() param environmentKeyVaultName string +@minLength(3) +@secure() +param apimUri string var namePrefix = 'dp-be-${environment}' var baseImageUrl = 'ghcr.io/digdir/dialogporten-' -resource appConfig 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = { - name: '${namePrefix}-appConfiguration' +resource appConfiguration 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = { + name: appConfigurationName +} + +resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = { + name: containerAppEnvironmentName } var containerAppEnvVars = [ @@ -38,7 +45,7 @@ var containerAppEnvVars = [ } { name: 'AZURE_APPCONFIG_URI' - value: appConfig.properties.endpoint + value: appConfiguration.properties.endpoint } { name: 'ASPNETCORE_URLS' @@ -63,7 +70,20 @@ module containerApp '../../modules/containerApp/main.bicep' = { image: '${baseImageUrl}webapi:${imageTag}' location: location envVariables: containerAppEnvVars - containerAppEnvId: containerAppEnvironmentId + containerAppEnvId: containerAppEnvironment.id + } +} + +// If the APIM URI is not provided, we will use the default domain of the container app environment. We only do this for the so service. +var baseUri = !empty(apimUri) ? apimUri : 'https://${containerAppName}.${containerAppEnvironment.properties.defaultDomain}' + +module appConfigConfigurations '../../modules/appConfiguration/upsertKeyValue.bicep' = { + name: 'AppConfig_Add_DialogPortenBaseUri' + params: { + configStoreName: appConfigurationName + key: 'Application:Dialoporten:BaseUri' + value: baseUri + keyValueType: 'custom' } } diff --git a/.azure/applications/web-api-so/staging.bicepparam b/.azure/applications/web-api-so/staging.bicepparam index 589cc8ceb..fdc6bc1fa 100644 --- a/.azure/applications/web-api-so/staging.bicepparam +++ b/.azure/applications/web-api-so/staging.bicepparam @@ -6,6 +6,6 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG') // secrets param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME') -param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID') +param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME') param appInsightConnectionString = readEnvironmentVariable('APP_INSIGHTS_CONNECTION_STRING') param appConfigurationName = readEnvironmentVariable('APP_CONFIGURATION_NAME') diff --git a/.azure/applications/web-api-so/test.bicepparam b/.azure/applications/web-api-so/test.bicepparam index efe327b64..3d72092e7 100644 --- a/.azure/applications/web-api-so/test.bicepparam +++ b/.azure/applications/web-api-so/test.bicepparam @@ -6,6 +6,6 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG') // secrets param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME') -param containerAppEnvironmentId = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_ID') +param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME') param appInsightConnectionString = readEnvironmentVariable('APP_INSIGHTS_CONNECTION_STRING') param appConfigurationName = readEnvironmentVariable('APP_CONFIGURATION_NAME') diff --git a/.github/workflows/action-deploy-apps.yml b/.github/workflows/action-deploy-apps.yml index b71bd64b2..e752fbd50 100644 --- a/.github/workflows/action-deploy-apps.yml +++ b/.github/workflows/action-deploy-apps.yml @@ -14,7 +14,7 @@ on: required: true AZURE_ENVIRONMENT_KEY_VAULT_NAME: required: true - AZURE_CONTAINER_APP_ENVIRONMENT_ID: + AZURE_CONTAINER_APP_ENVIRONMENT_NAME: required: true AZURE_APP_INSIGHTS_CONNECTION_STRING: required: true @@ -72,7 +72,7 @@ jobs: # IMAGE_TAG: ${{ inputs.gitShortSha }} # # secrets # ADO_CONNECTION_STRING_SECRET_URI: ${{ secrets.AZURE_ADO_CONNECTION_STRING_SECRET_URI }} - # CONTAINER_APP_ENVIRONMENT_ID: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_ID }} + # CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }} # with: # scope: resourcegroup # template: ./.azure/applications/web-api-migration-job/main.bicep @@ -139,7 +139,7 @@ jobs: # parameters IMAGE_TAG: ${{ inputs.gitShortSha }} # secrets - CONTAINER_APP_ENVIRONMENT_ID: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_ID }} + CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }} APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }} APP_CONFIGURATION_NAME: ${{ secrets.AZURE_APP_CONFIGURATION_NAME }} ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }} diff --git a/.github/workflows/ci-cd-main.yml b/.github/workflows/ci-cd-main.yml index fecc93c08..2e30f6115 100644 --- a/.github/workflows/ci-cd-main.yml +++ b/.github/workflows/ci-cd-main.yml @@ -63,7 +63,7 @@ jobs: AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} AZURE_ADO_CONNECTION_STRING_SECRET_URI: ${{ secrets.AZURE_ADO_CONNECTION_STRING_SECRET_URI }} AZURE_ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }} - AZURE_CONTAINER_APP_ENVIRONMENT_ID: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_ID }} + AZURE_CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }} AZURE_APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }} AZURE_APP_CONFIGURATION_NAME: ${{ secrets.AZURE_APP_CONFIGURATION_NAME }} with: