From e21de56130c48684324fd648699a5965c8a88ebf Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Thu, 5 Sep 2024 13:46:49 +0200 Subject: [PATCH] fix: ensure jobs are run with correct arguments and parameters (#1085) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Apparently, the `command` property in Bicep for Azure Container Apps overrides the `ENTRYPOINT` property in the `Dockerfile` 🤷 Changing to using arguments instead. Tested with manual update of the container app job. https://azureossd.github.io/2024/01/17/Container-Apps-Using-the-command-override-option/ Other things: - Added application insights connection string - Added `ASPNETCORE_ENVIRONMENT` in order to use correct appconfig-file ## Related Issue(s) - #{issue number} ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) --- .../sync-subject-resource-mappings-job/main.bicep | 15 ++++++++++++++- .../prod.bicepparam | 1 + .../staging.bicepparam | 1 + .../test.bicepparam | 1 + .azure/modules/containerAppJob/main.bicep | 6 +++--- .github/workflows/action-deploy-apps.yml | 1 + 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.azure/applications/sync-subject-resource-mappings-job/main.bicep b/.azure/applications/sync-subject-resource-mappings-job/main.bicep index 5e0559177..92491b85f 100644 --- a/.azure/applications/sync-subject-resource-mappings-job/main.bicep +++ b/.azure/applications/sync-subject-resource-mappings-job/main.bicep @@ -26,6 +26,11 @@ param environmentKeyVaultName string @minLength(9) param jobSchedule string +@description('The connection string for Application Insights') +@minLength(3) +@secure() +param appInsightConnectionString string + var namePrefix = 'dp-be-${environment}' var baseImageUrl = 'ghcr.io/digdir/dialogporten-' var tags = { @@ -46,6 +51,14 @@ var containerAppEnvVars = [ name: 'Infrastructure__DialogDbConnectionString' secretRef: 'dbconnectionstring' } + { + name: 'ASPNETCORE_ENVIRONMENT' + value: environment + } + { + name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' + value: appInsightConnectionString + } ] // https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions-deployment#example-1 @@ -70,7 +83,7 @@ module migrationJob '../../modules/containerAppJob/main.bicep' = { secrets: secrets tags: tags cronExpression: jobSchedule - command: 'sync-subject-resource-mappings' + args: 'sync-subject-resource-mappings' } } diff --git a/.azure/applications/sync-subject-resource-mappings-job/prod.bicepparam b/.azure/applications/sync-subject-resource-mappings-job/prod.bicepparam index 40267618c..20c50deda 100644 --- a/.azure/applications/sync-subject-resource-mappings-job/prod.bicepparam +++ b/.azure/applications/sync-subject-resource-mappings-job/prod.bicepparam @@ -8,3 +8,4 @@ param jobSchedule = '*/5 * * * *' // Runs every 5 minutes //secrets param containerAppEnvironmentName = readEnvironmentVariable('AZURE_CONTAINER_APP_ENVIRONMENT_NAME') param environmentKeyVaultName = readEnvironmentVariable('AZURE_ENVIRONMENT_KEY_VAULT_NAME') +param appInsightConnectionString = readEnvironmentVariable('AZURE_APP_INSIGHTS_CONNECTION_STRING') diff --git a/.azure/applications/sync-subject-resource-mappings-job/staging.bicepparam b/.azure/applications/sync-subject-resource-mappings-job/staging.bicepparam index e1e858d26..e65df009a 100644 --- a/.azure/applications/sync-subject-resource-mappings-job/staging.bicepparam +++ b/.azure/applications/sync-subject-resource-mappings-job/staging.bicepparam @@ -8,3 +8,4 @@ param jobSchedule = '*/5 * * * *' // Runs every 5 minutes //secrets param containerAppEnvironmentName = readEnvironmentVariable('AZURE_CONTAINER_APP_ENVIRONMENT_NAME') param environmentKeyVaultName = readEnvironmentVariable('AZURE_ENVIRONMENT_KEY_VAULT_NAME') +param appInsightConnectionString = readEnvironmentVariable('AZURE_APP_INSIGHTS_CONNECTION_STRING') diff --git a/.azure/applications/sync-subject-resource-mappings-job/test.bicepparam b/.azure/applications/sync-subject-resource-mappings-job/test.bicepparam index e22529190..a9de73cac 100644 --- a/.azure/applications/sync-subject-resource-mappings-job/test.bicepparam +++ b/.azure/applications/sync-subject-resource-mappings-job/test.bicepparam @@ -8,3 +8,4 @@ param jobSchedule = '*/5 * * * *' // Runs every 5 minutes //secrets param containerAppEnvironmentName = readEnvironmentVariable('AZURE_CONTAINER_APP_ENVIRONMENT_NAME') param environmentKeyVaultName = readEnvironmentVariable('AZURE_ENVIRONMENT_KEY_VAULT_NAME') +param appInsightConnectionString = readEnvironmentVariable('AZURE_APP_INSIGHTS_CONNECTION_STRING') diff --git a/.azure/modules/containerAppJob/main.bicep b/.azure/modules/containerAppJob/main.bicep index 45ed0bb0c..8a1628018 100644 --- a/.azure/modules/containerAppJob/main.bicep +++ b/.azure/modules/containerAppJob/main.bicep @@ -22,8 +22,8 @@ param tags object @description('The cron expression for the job schedule (optional)') param cronExpression string = '' -@description('The command for the job (optional)') -param command string = '' +@description('The container args for the job (optional)') +param args string = '' var isScheduled = !empty(cronExpression) @@ -64,7 +64,7 @@ resource job 'Microsoft.App/jobs@2024-03-01' = { env: environmentVariables image: image name: name - command: empty(command) ? null : [command] + args: empty(args) ? null : [args] } ] } diff --git a/.github/workflows/action-deploy-apps.yml b/.github/workflows/action-deploy-apps.yml index a610f0d0c..2be580755 100644 --- a/.github/workflows/action-deploy-apps.yml +++ b/.github/workflows/action-deploy-apps.yml @@ -256,6 +256,7 @@ jobs: # secrets AZURE_CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }} AZURE_ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }} + AZURE_APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }} with: scope: resourcegroup template: ./.azure/applications/${{ matrix.name }}/main.bicep