From 43b161b41309dbe6828261e99c8b585d4b7cac3f Mon Sep 17 00:00:00 2001 From: Chris Kruining Date: Mon, 18 Nov 2024 14:25:15 +0100 Subject: [PATCH] simplify/merge workflow --- .github/workflows/app.yml | 27 ++++++++------ .github/workflows/infra.yml | 35 ------------------- infrastructure/app.bicep | 9 ++--- infrastructure/main.bicep | 6 +++- .../{prod.bicepparam => prd.bicepparam} | 2 ++ infrastructure/registry.bicep | 2 -- 6 files changed, 29 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/infra.yml rename infrastructure/params/{prod.bicepparam => prd.bicepparam} (69%) diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index 6a8f3f0..9152010 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -2,8 +2,6 @@ name: Deploy App on: push: - paths-ignore: - - infrastructure/** branches: - main # pull_request: @@ -22,8 +20,7 @@ permissions: jobs: versionize: - name: Versionize - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + name: Calculate next version runs-on: ubuntu-latest outputs: semver: ${{ steps.gitversion.outputs.SemVer }} @@ -44,7 +41,6 @@ jobs: build_and_publish: name: Build & Publish - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') runs-on: ubuntu-latest needs: versionize steps: @@ -67,12 +63,18 @@ jobs: docker push ${{ secrets.ACR_LOGIN_SERVER }}/$IMAGE_NAME:${{needs.versionize.outputs.semver}} docker push ${{ secrets.ACR_LOGIN_SERVER }}/$IMAGE_NAME:latest - create_new_revision: - name: Create & Activate new revision - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') + deploy: + name: Deploy app runs-on: ubuntu-latest - needs: build_and_publish + strategy: + matrix: + environment: [ 'prd' ] steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + infrastructure + - name: Az CLI login uses: azure/login@v2 with: @@ -85,4 +87,9 @@ jobs: with: azcliversion: 2.66.0 inlineScript: | - az containerapp update --name calque-app --resource-group rg-euw-prd-calque --image ${{ secrets.ACR_LOGIN_SERVER }}/$IMAGE_NAME:${{needs.versionize.outputs.semver}} + az deployment sub create \ + --location westeurope \ + --template-file infrastructure/main.bicep \ + --parameters infrastructure/params/${{ matrix.environment }}.bicepparam \ + --parameters version=${{ needs.versionize.outputs.semver }} \ + --parameters registryUrl=${{ secrets.ACR_LOGIN_SERVER }} \ No newline at end of file diff --git a/.github/workflows/infra.yml b/.github/workflows/infra.yml deleted file mode 100644 index 406ff7b..0000000 --- a/.github/workflows/infra.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Deploy infrastructure - -on: - push: - paths-ignore: - - src/** - branches: - - main - -permissions: - id-token: write - contents: read - -jobs: - production: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - sparse-checkout: | - infrastructure - - - name: Az CLI login - uses: azure/login@v2 - with: - client-id: ${{ secrets.CALQUE_PRD_CLIENT_ID }} - tenant-id: ${{ secrets.CALQUE_PRD_TENANT_ID }} - subscription-id: ${{ secrets.CALQUE_PRD_SUBSCRIPTION_ID }} - - - name: Deploy bicep - uses: Azure/cli@v2 - with: - azcliversion: 2.66.0 - inlineScript: | - az deployment sub create --location westeurope --template-file infrastructure/main.bicep --parameters infrastructure/params/prod.bicepparam diff --git a/infrastructure/app.bicep b/infrastructure/app.bicep index 3fa4a84..714568a 100644 --- a/infrastructure/app.bicep +++ b/infrastructure/app.bicep @@ -3,10 +3,11 @@ import { Context } from 'types.bicep' targetScope = 'resourceGroup' param context Context -param registry resource'Microsoft.ContainerRegistry/registries@2023-07-01' +param version string +@secure() +param registryUrl string var appName = 'app' -var version = 'latest' resource environment 'Microsoft.App/managedEnvironments@2024-03-01' = { name: 'cea-${context.locationAbbreviation}-${context.environment}-${context.projectName}' @@ -65,7 +66,7 @@ resource app 'Microsoft.App/containerApps@2024-03-01' = { registries: [ { identity: 'system' - server: 'acreuwprdcalque.azurecr.io' + server: registryUrl } ] } @@ -73,7 +74,7 @@ resource app 'Microsoft.App/containerApps@2024-03-01' = { template: { containers: [ { - image: 'acreuwprdcalque.azurecr.io/${context.projectName}-${appName}:${version}' + image: '${registryUrl}/${context.projectName}-${appName}:${version}' name: '${context.projectName}-${appName}' resources: { cpu: json('0.25') diff --git a/infrastructure/main.bicep b/infrastructure/main.bicep index 812756c..6e207c5 100644 --- a/infrastructure/main.bicep +++ b/infrastructure/main.bicep @@ -6,6 +6,9 @@ param locationAbbreviation string param location string param environment string param projectName string +param version string +@secure() +param registryUrl string param deployedAt string = utcNow('yyyyMMdd') var context = { @@ -42,6 +45,7 @@ module app 'app.bicep' = { scope: calqueResourceGroup params: { context: context - registry: registry.outputs.registry + version: version + registryUrl: registryUrl } } diff --git a/infrastructure/params/prod.bicepparam b/infrastructure/params/prd.bicepparam similarity index 69% rename from infrastructure/params/prod.bicepparam rename to infrastructure/params/prd.bicepparam index 539b3aa..5d93d34 100644 --- a/infrastructure/params/prod.bicepparam +++ b/infrastructure/params/prd.bicepparam @@ -4,3 +4,5 @@ param locationAbbreviation = 'euw' param location = 'westeurope' param environment = 'prd' param projectName = 'calque' +param version = 'latest' +param registryUrl = '__PLACEHOLDER__' diff --git a/infrastructure/registry.bicep b/infrastructure/registry.bicep index 2878a58..a13abbf 100644 --- a/infrastructure/registry.bicep +++ b/infrastructure/registry.bicep @@ -21,5 +21,3 @@ resource registry 'Microsoft.ContainerRegistry/registries@2023-07-01' = { } } } - -output registry resource'Microsoft.ContainerRegistry/registries@2023-07-01' = registry