Skip to content

Commit

Permalink
Always run all infra steps regardless of changes (#472)
Browse files Browse the repository at this point in the history
* remove check for changes

* fix image tag

* upgrade azure identity

* use correct name for app db access

---------

Co-authored-by: Hammerbeck <andreas.hammerbeck@digdir.no>
  • Loading branch information
Andreass2 and Hammerbeck committed Jun 19, 2024
1 parent ad539ea commit 05b734f
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .azure/applications/api/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module databaseAccess '../../modules/postgreSql/AddAdministrationAccess.bicep' =
params: {
tenantId: appIdentity.outputs.tenantId
principalId: appIdentity.outputs.principalId
appName: appIdentity.name
appName: appIdentity.outputs.name
namePrefix: namePrefix
}
}
Expand Down
2 changes: 0 additions & 2 deletions .azure/applications/migration/main.bicep
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
param namePrefix string
param location string
param appVersion string

@secure()
param keyVaultUrl string

@secure()
param keyVaultName string

Expand Down
1 change: 0 additions & 1 deletion .azure/infrastructure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ module postgresql '../modules/postgreSql/create.bicep' = {
administratorLoginPassword: brokerPgAdminPassword
sku: postgresSku
tenantId: tenantId
test_client_id: test_client_id
environment: environment
}
}
Expand Down
2 changes: 1 addition & 1 deletion .azure/modules/identity/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
param namePrefix string
param location string


resource userAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: '${namePrefix}-app-identity'
location: location
Expand All @@ -11,3 +10,4 @@ output id string = userAssignedIdentity.id
output clientId string = userAssignedIdentity.properties.clientId
output principalId string = userAssignedIdentity.properties.principalId
output tenantId string = userAssignedIdentity.properties.tenantId
output name string = userAssignedIdentity.name
3 changes: 1 addition & 2 deletions .azure/modules/migrationJob/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ param containerAppEnvId string
param command string[]
param environmentVariables { name: string, value: string?, secretRef: string? }[] = []
param secrets { name: string, keyVaultUrl: string, identity: string }[] = []
param volumes { name: string, storageName: string, storageType: string, mountOptions: string}[] = []
param volumes { name: string, storageName: string, storageType: string, mountOptions: string }[] = []
param volumeMounts { mountPath: string, subPath: string, volumeName: string }[] = []
param principalId string

Expand Down Expand Up @@ -44,5 +44,4 @@ resource job 'Microsoft.App/jobs@2024-03-01' = {
}
}
}

output name string = job.name
16 changes: 1 addition & 15 deletions .azure/modules/postgreSql/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ param srcKeyVault object
param administratorLoginPassword string
@secure()
param tenantId string
@secure()
param test_client_id string

var databaseName = 'brokerdb'
var databaseUser = 'adminuser'
Expand Down Expand Up @@ -75,7 +73,7 @@ resource configurations 'Microsoft.DBforPostgreSQL/flexibleServers/configuration
}
}

resource database 'Microsoft.DBforPostgreSQL/flexibleServers/databases@2023-06-01-preview' = {
resource database 'Microsoft.DBforPostgreSQL/flexibleServers/databases@2023-12-01-preview' = {
name: databaseName
parent: postgres
properties: {
Expand All @@ -102,15 +100,3 @@ module adoConnectionString '../keyvault/upsertSecret.bicep' = {
secretValue: 'Host=${postgres.properties.fullyQualifiedDomainName};Database=${databaseName};Port=5432;Username=${namePrefix}-app-identity;Ssl Mode=Require;Trust Server Certificate=True;Maximum Pool Size=${poolSize};'
}
}

resource databaseAccess 'Microsoft.DBforPostgreSQL/flexibleServers/administrators@2022-12-01' =
if (environment == 'test') {
name: test_client_id
parent: postgres
dependsOn: [allowAzureAccess] // Needs to depend on allowAzureAccess to avoid updating at the same time
properties: {
principalType: 'Group'
tenantId: tenantId
principalName: 'Altinn-30-Broker-Test-Developers'
}
}
44 changes: 0 additions & 44 deletions .github/actions/check-for-changes/action.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/actions/migrate-database/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
AZURE_TENANT_ID:
description: "Tenant ID for the service principal"
required: true
AZURE_SUBSCRIPTION_ID:
AZURE_SUBSCRIPTION_ID:
description: "Subscription ID for the service principal"
required: true
AZURE_ENVIRONMENT_KEY_VAULT_NAME:
Expand Down Expand Up @@ -81,7 +81,7 @@ runs:
./.github/tools/containerAppJobVerifier.sh ${{ steps.migration-job.outputs.name }} '${{ inputs.AZURE_NAME_PREFIX }}-rg' ${{ steps.get-version.outputs.imageTag }}
- name: Logout from azure
shell: bash
shell: bash
if: ${{failure() || success()}}
continue-on-error: true
run: az logout
10 changes: 4 additions & 6 deletions .github/actions/publish-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inputs:
dockerImageBaseName:
description: "Base image name for docker images"
required: true
imageTag:
description: "Tag for the image"
required: true
GITHUB_TOKEN:
description: "GitHub token"
required: true
Expand All @@ -15,11 +18,6 @@ runs:
using: "composite"
steps:
- uses: actions/checkout@v4

- name: Get version
id: get-version
uses: ./.github/actions/get-current-version

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -31,6 +29,6 @@ runs:
shell: bash
run: |
# Construct the image tag using the Git hash
IMAGE="${{ inputs.dockerImageBaseName }}:${{ steps.get-version.outputs.imageTag }}"
IMAGE="${{ inputs.dockerImageBaseName }}:${{ inputs.imageTag }}"
docker build . --tag $IMAGE
docker push $IMAGE
11 changes: 7 additions & 4 deletions .github/actions/release-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ inputs:
environment:
description: "Github environment to deploy from"
required: true
AZURE_SUBSCRIPTION_ID:
imageTag:
description: "Tag for the image"
required: true
AZURE_SUBSCRIPTION_ID:
description: "Subscription ID for the service principal"
required: true
AZURE_ENVIRONMENT_KEY_VAULT_NAME:
Expand Down Expand Up @@ -44,12 +47,12 @@ runs:
- name: Get version
id: get-version
uses: ./.github/actions/get-current-version

- name: Deploy app
uses: azure/arm-deploy@v2
id: deploy
env:
IMAGE_TAG: ${{ steps.get-version.outputs.imageTag }}
IMAGE_TAG: ${{ inputs.imageTag }}
ENVIRONMENT: ${{ inputs.environment }}
KEY_VAULT_NAME: ${{ inputs.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}
KEY_VAULT_URL: https://${{ inputs.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}.vault.azure.net
Expand All @@ -61,7 +64,7 @@ runs:
resourceGroupName: ${{ inputs.AZURE_NAME_PREFIX }}-rg
template: ./.azure/applications/api/main.bicep
deploymentMode: Incremental
deploymentName: ${{ inputs.AZURE_NAME_PREFIX }}-${{ steps.get-version.outputs.imageTag }}
deploymentName: ${{ inputs.AZURE_NAME_PREFIX }}-${{ inputs.imageTag }}
region: ${{ inputs.region }}
failOnStdErr: false
parameters: ./.azure/applications/api/params.bicepparam
Expand Down
48 changes: 3 additions & 45 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,13 @@ on:
- "Test/**" # ignore changes to tests

jobs:
check-for-changes:
name: Check for changes
runs-on: ubuntu-latest
outputs:
hasAzureChanges: ${{ steps.check-for-changes.outputs.hasAzureChanges }}
hasBackendChanges: ${{ steps.check-for-changes.outputs.hasBackendChanges }}
hasMigrationChanges: ${{ steps.check-for-changes.outputs.hasMigrationChanges }}
steps:
- uses: actions/checkout@v4

- name: "Check for changes"
id: check-for-changes
uses: ./.github/actions/check-for-changes

- name: "Inform about infrastructure skip"
if: ${{ steps.check-for-changes.outputs.hasAzureChanges != 'true' }}
run: echo "::warning file=.github/workflows/ci-cd.yaml,line=1,col=1::Infrastructure-as-code did not change. Infrastructure update will be skipped."

- name: "Inform about publish skip"
if: ${{ steps.check-for-changes.outputs.hasBackendChanges != 'true' }}
run: echo "::warning file=.github/workflows/ci-cd.yaml,line=1,col=1::Code not changed. Will not publish and release new version."

- name: "Inform about database migration skip"
if: ${{ steps.check-for-changes.outputs.hasMigrationChanges != 'true' }}
run: echo "::warning file=.github/workflows/ci-cd.yaml,line=1,col=1::Migrations did not change. No migration will run."

test:
name: QA
uses: ./.github/workflows/test-application.yml
needs: [check-for-changes]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasMigrationChanges == 'true' }}

publish:
name: Publish
runs-on: ubuntu-latest
needs: [check-for-changes]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' }}
permissions:
packages: write
contents: read
Expand All @@ -60,24 +30,19 @@ jobs:
uses: ./.github/workflows/deploy-to-environment.yml
if: always() && !failure() && !cancelled()
needs: [
publish,
check-for-changes
publish
]
permissions:
id-token: write
contents: read
secrets: inherit
with:
environment: test
hasAzureChanges: ${{ needs.check-for-changes.outputs.hasAzureChanges }}
hasBackendChanges: ${{ needs.check-for-changes.outputs.hasBackendChanges }}
hasMigrationChanges: ${{ needs.check-for-changes.outputs.hasMigrationChanges }}

deploy-staging:
name: Staging
needs: [
deploy-test,
check-for-changes
]
uses: ./.github/workflows/deploy-to-environment.yml
if: (!failure() && !cancelled())
Expand All @@ -87,15 +52,11 @@ jobs:
secrets: inherit
with:
environment: staging
hasAzureChanges: ${{ needs.check-for-changes.outputs.hasAzureChanges }}
hasBackendChanges: ${{ needs.check-for-changes.outputs.hasBackendChanges }}
hasMigrationChanges: ${{ needs.check-for-changes.outputs.hasMigrationChanges }}

deploy-production:
name: Production
needs: [
deploy-staging,
check-for-changes
]
uses: ./.github/workflows/deploy-to-environment.yml
if: (!failure() && !cancelled())
Expand All @@ -105,15 +66,12 @@ jobs:
secrets: inherit
with:
environment: production
hasAzureChanges: ${{ needs.check-for-changes.outputs.hasAzureChanges }}
hasBackendChanges: ${{ needs.check-for-changes.outputs.hasBackendChanges }}
hasMigrationChanges: ${{ needs.check-for-changes.outputs.hasMigrationChanges }}

release-to-git:
name: Release to git
runs-on: ubuntu-latest
needs: [check-for-changes, deploy-production]
if: ${{ needs.check-for-changes.outputs.hasBackendChanges == 'true' && !failure() && !cancelled()}}
needs: [deploy-production]
if: ${{ !failure() && !cancelled()}}
permissions:
id-token: write
contents: write
Expand Down
Loading

0 comments on commit 05b734f

Please sign in to comment.