From e3cb4269f916b40cc0ecad8c59e730821d78870b Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 2 Aug 2024 09:30:40 +0200 Subject: [PATCH 01/55] Init deployment yml file --- pipelines/summary-api-pipeline.yml | 288 +++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 pipelines/summary-api-pipeline.yml diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml new file mode 100644 index 000000000..854442450 --- /dev/null +++ b/pipelines/summary-api-pipeline.yml @@ -0,0 +1,288 @@ +name: $(date:yyyyMMdd)$(rev:.r) + +pr: none + +trigger: + branches: + include: + - master + paths: + include: + - src/Fusion.Summary.Api/* + +pool: + vmImage: ubuntu-latest + +resources: + repositories: + - repository: infra + name: equinor/fusion-infrastructure + type: github + endpoint: fusion-infrastructure + +variables: + imageTag: $(Build.BuildNumber) + fusionAcr: 'fusioncr.azurecr.io' + imageRepo: resources/fusion-summary-api + imageName: $(imageRepo):$(imageTag) + subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' + deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-test-env.yml' + fullImageName: $(fusionAcr)/$(imageName) + +stages: + - stage: BuildDockerImage + displayName: 'Build docker image' + jobs: + - job: BuildImage + steps: + - task: Docker@2 + displayName: Login to fusioncr + inputs: + command: login + containerRegistry: fusioncr + - template: templates/docker-buildx.yml@infra + parameters: + repository: $(imageRepo) + buildContext: ./src + dockerfile: src/Fusion.Summary.Api/Dockerfile + dockerPush: true + disableCache: true + tags: | + $(imageTag) + - template: templates/docker-buildx.yml@infra + parameters: + initBuilderInstance: false + repository: '' + buildContext: ./src + dockerfile: src/Fusion.Summary.Api/Dockerfile + arguments: | + --target=export + --output=type=local,dest=$(Build.ArtifactStagingDirectory) + --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) + + - task: CopyFiles@2 + displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)' + inputs: + SourceFolder: 'src/Fusion.Summary.Api/Deployment/k8s' + Contents: | + deployment-test-env.yml + TargetFolder: '$(Build.ArtifactStagingDirectory)' + + - publish: $(Build.ArtifactStagingDirectory) + artifact: 'k8s-deployment' + + - stage: DeployCI + displayName: 'Deploy to CI' + dependsOn: BuildDockerImage + condition: succeeded() + variables: + envName: 'ci' + fusionEnvironment: 'ci' + clientId: '5a842df8-3238-415d-b168-9f16a6a6031b' + + jobs: + - deployment: DeployCI + environment: fusion-ci.fusion-summary-app-ci + strategy: + runOnce: + deploy: + steps: + - task: AzurePowerShell@4 + displayName: 'Get secrets' + inputs: + azureSubscription: $(subscriptionService) + ScriptType: 'InlineScript' + FailOnStandardError: true + azurePowerShellVersion: 'LatestVersion' + Inline: | + $secretText = Get-AzKeyVaultSecret -VaultName kv-fap-resources-ci -Name AzureAd--ClientSecret -AsPlainText + Write-Output "##vso[task.setvariable variable=clientSecret;issecret=true]$($secretText)" + + - template: templates/get-appinsights-key.yml + parameters: + environment: $(envName) + + # Load the key vault url into variable, so it can be used when replacing tokens. + - template: templates/get-keyvault-url.yml + parameters: + environment: $(envName) + variableName: envKeyVaultUrl + + + - template: templates/replace-tokens.yml + parameters: + targetFiles: '$(deploymentManifest)' + + - template: templates/execute-sql-migration.yml + parameters: + artifact: 'k8s-deployment' + environment: $(envName) + + - task: KubernetesManifest@0 + displayName: Deploy to Kubernetes cluster + inputs: + action: deploy + manifests: $(deploymentManifest) + + - stage: DeployFQA + displayName: 'Deploy to FQA' + dependsOn: DeployCI + condition: succeeded() + variables: + envName: 'fqa' + fusionEnvironment: 'fqa' + clientId: '5a842df8-3238-415d-b168-9f16a6a6031b' + + jobs: + - deployment: DeployFQA + environment: fusion-resources-fqa.fusion-summary-app-fqa + strategy: + runOnce: + deploy: + steps: + - task: AzurePowerShell@4 + displayName: 'Get secrets' + inputs: + azureSubscription: $(subscriptionService) + ScriptType: 'InlineScript' + FailOnStandardError: true + azurePowerShellVersion: 'LatestVersion' + Inline: | + $secretText = Get-AzKeyVaultSecret -VaultName kv-fap-resources-fqa -Name AzureAd--ClientSecret -AsPlainText + Write-Output "##vso[task.setvariable variable=clientSecret;issecret=true]$($secretText)" + + - template: templates/get-appinsights-key.yml + parameters: + environment: $(envName) + + # Load the key vault url into variable, so it can be used when replacing tokens. + - template: templates/get-keyvault-url.yml + parameters: + environment: $(envName) + variableName: envKeyVaultUrl + + - template: templates/replace-tokens.yml + parameters: + targetFiles: '$(deploymentManifest)' + + - template: templates/execute-sql-migration.yml + parameters: + artifact: 'k8s-deployment' + environment: $(envName) + + - task: KubernetesManifest@0 + displayName: Deploy to Kubernetes cluster + inputs: + action: deploy + manifests: $(deploymentManifest) + + - stage: DeployFPRD + displayName: 'Deploy to FPRD' + dependsOn: DeployFQA + condition: succeeded() + variables: + envName: 'fprd' + fusionEnvironment: 'fprd' + clientId: '97978493-9777-4d48-b38a-67b0b9cd88d2' + + jobs: + - deployment: DeployFPRD + environment: fusion-prod.fusion-summary-app-fprd + strategy: + runOnce: + deploy: + steps: + - task: AzurePowerShell@4 + displayName: 'Get secrets' + inputs: + azureSubscription: $(subscriptionService) + ScriptType: 'InlineScript' + FailOnStandardError: true + azurePowerShellVersion: 'LatestVersion' + Inline: | + $secretText = Get-AzKeyVaultSecret -VaultName kv-fap-resources-fprd -Name AzureAd--ClientSecret -AsPlainText + Write-Output "##vso[task.setvariable variable=clientSecret;issecret=true]$($secretText)" + + - template: templates/get-appinsights-key.yml + parameters: + environment: $(envName) + + # Load the key vault url into variable, so it can be used when replacing tokens. + - template: templates/get-keyvault-url.yml + parameters: + environment: $(envName) + variableName: envKeyVaultUrl + + - template: templates/replace-tokens.yml + parameters: + targetFiles: '$(deploymentManifest)' + + - template: templates/execute-sql-migration.yml + parameters: + artifact: 'k8s-deployment' + environment: $(envName) + + - task: KubernetesManifest@0 + displayName: Deploy to Kubernetes cluster + inputs: + action: deploy + manifests: $(deploymentManifest) + + - template: templates/deploy-container-app.yml + parameters: + environment: $(envName) + fusionEnvironment: $(fusionEnvironment) + clientId: $(clientId) + imageName: $(fullImageName) + + - stage: DeployTR + displayName: 'Deploy to TR' + dependsOn: DeployFPRD + condition: succeeded() + variables: + envName: 'tr' + fusionEnvironment: 'tr' + clientId: '5a842df8-3238-415d-b168-9f16a6a6031b' + + jobs: + - deployment: DeployTR + environment: fusion-resources-tr.fusion-summary-app-tr + strategy: + runOnce: + deploy: + steps: + - task: AzurePowerShell@4 + displayName: 'Get secrets' + inputs: + azureSubscription: $(subscriptionService) + ScriptType: 'InlineScript' + FailOnStandardError: true + azurePowerShellVersion: 'LatestVersion' + Inline: | + $secretText = Get-AzKeyVaultSecret -VaultName kv-fap-resources-tr -Name AzureAd--ClientSecret -AsPlainText + Write-Output "##vso[task.setvariable variable=clientSecret;issecret=true]$($secretText)" + + - template: templates/get-appinsights-key.yml + parameters: + environment: $(envName) + + # Load the key vault url into variable, so it can be used when replacing tokens. + - template: templates/get-keyvault-url.yml + parameters: + environment: $(envName) + variableName: envKeyVaultUrl + + - template: templates/replace-tokens.yml + parameters: + targetFiles: '$(deploymentManifest)' + + - template: templates/execute-sql-migration.yml + parameters: + artifact: 'k8s-deployment' + environment: $(envName) + + - task: KubernetesManifest@0 + displayName: Deploy to Kubernetes cluster + inputs: + action: deploy + manifests: $(deploymentManifest) \ No newline at end of file From 76525cfe3484b97412bbb4fbc06f218fae0b9770 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 2 Aug 2024 09:40:02 +0200 Subject: [PATCH 02/55] Trigger pipeline --- src/Fusion.Summary.Api/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 516551114..1f5695b6f 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -107,7 +107,7 @@ app.Run(); /// -/// For testing +/// For testing. /// public partial class Program { From 0f5d3b5ba3a7f888fec9cacf61952b8384b5372e Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 2 Aug 2024 09:51:40 +0200 Subject: [PATCH 03/55] Updated summary api deployment-test-env.yml --- .../Deployment/k8s/deployment-test-env.yml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml b/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml index 91ce7ba24..9ad16ad6e 100644 --- a/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml +++ b/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml @@ -17,7 +17,7 @@ stringData: apiVersion: apps/v1 kind: Deployment metadata: - name: resources-api + name: summary-api spec: replicas: 1 strategy: @@ -27,11 +27,11 @@ spec: maxUnavailable: 50% selector: matchLabels: - app: resources-api + app: summary-api template: metadata: labels: - app: resources-api + app: summary-api spec: volumes: - name: env-secrets-volumes @@ -39,7 +39,7 @@ spec: secretName: env-secrets containers: - - name: resources-api + - name: summary-api image: {{fusionAcr}}/{{imageName}} ports: - containerPort: 80 @@ -70,7 +70,7 @@ spec: livenessProbe: httpGet: path: /_health/liveness - port: 80 + port: 8080 failureThreshold: 10 timeoutSeconds: 30 initialDelaySeconds: 60 @@ -79,7 +79,7 @@ spec: readinessProbe: httpGet: path: /_health/ready - port: 80 + port: 8080 initialDelaySeconds: 10 timeoutSeconds: 30 periodSeconds: 30 @@ -87,19 +87,19 @@ spec: kind: Service apiVersion: v1 metadata: - name: resources-api + name: summary-api spec: selector: - app: resources-api + app: summary-api ports: - port: 80 - targetPort: 80 + targetPort: 8080 --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: resources-api-fusion-ingress + name: summary-api-fusion-ingress annotations: kubernetes.io/tls-acme: "true" kubernetes.io/ingress.class: nginx @@ -112,10 +112,10 @@ metadata: spec: tls: - hosts: - - resources-api.{{ENVNAME}}.fusion-dev.net + - summary-api.{{ENVNAME}}.fusion-dev.net secretName: {{ENVNAME}}.fusion-dev.net-tls rules: - - host: resources-api.{{ENVNAME}}.fusion-dev.net + - host: summary-api.{{ENVNAME}}.fusion-dev.net http: paths: - path: / From 401870c61155b3dd01619caf44236e1a86b80ea1 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Mon, 5 Aug 2024 09:45:47 +0200 Subject: [PATCH 04/55] Change devops environments to match the fusion resources envs instead --- pipelines/summary-api-pipeline.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 854442450..11a3bfc0b 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -82,7 +82,7 @@ stages: jobs: - deployment: DeployCI - environment: fusion-ci.fusion-summary-app-ci + environment: fra-ci strategy: runOnce: deploy: @@ -135,7 +135,7 @@ stages: jobs: - deployment: DeployFQA - environment: fusion-resources-fqa.fusion-summary-app-fqa + environment: fra-fqa strategy: runOnce: deploy: @@ -187,7 +187,7 @@ stages: jobs: - deployment: DeployFPRD - environment: fusion-prod.fusion-summary-app-fprd + environment: fra-fprd strategy: runOnce: deploy: @@ -246,7 +246,7 @@ stages: jobs: - deployment: DeployTR - environment: fusion-resources-tr.fusion-summary-app-tr + environment: fra-tr strategy: runOnce: deploy: From b5a8a53ed077e13193b8cc6b0f78f6274bd5b8ba Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:51:47 +0200 Subject: [PATCH 05/55] update image name --- pipelines/summary-api-pr-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pr-pipeline.yml b/pipelines/summary-api-pr-pipeline.yml index 1d54c2616..330c515f0 100644 --- a/pipelines/summary-api-pr-pipeline.yml +++ b/pipelines/summary-api-pr-pipeline.yml @@ -20,7 +20,7 @@ resources: variables: prNumber: $(System.PullRequest.PullRequestNumber) fusionAcr: 'fusioncr.azurecr.io' - imageRepo: resources/fusion-summary-api + imageRepo: resources/fra-summary-api imageName: $(imageRepo):$(prNumber) subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-pr-env.yml' From 9ee19db2e2409259d375e335de1fef54a4ffa54e Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:58:56 +0200 Subject: [PATCH 06/55] renamed wrong pipeline --- pipelines/summary-api-pipeline.yml | 2 +- pipelines/summary-api-pr-pipeline.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 11a3bfc0b..d4c99ca76 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -23,7 +23,7 @@ resources: variables: imageTag: $(Build.BuildNumber) fusionAcr: 'fusioncr.azurecr.io' - imageRepo: resources/fusion-summary-api + imageRepo: resources/fra-summary-api imageName: $(imageRepo):$(imageTag) subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-test-env.yml' diff --git a/pipelines/summary-api-pr-pipeline.yml b/pipelines/summary-api-pr-pipeline.yml index 330c515f0..1d54c2616 100644 --- a/pipelines/summary-api-pr-pipeline.yml +++ b/pipelines/summary-api-pr-pipeline.yml @@ -20,7 +20,7 @@ resources: variables: prNumber: $(System.PullRequest.PullRequestNumber) fusionAcr: 'fusioncr.azurecr.io' - imageRepo: resources/fra-summary-api + imageRepo: resources/fusion-summary-api imageName: $(imageRepo):$(prNumber) subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-pr-env.yml' From 6c08c5e8d5f425c29cdc8d49d39d50c22a552401 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Wed, 7 Aug 2024 09:01:27 +0200 Subject: [PATCH 07/55] update image repo --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index d4c99ca76..024489674 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -23,7 +23,7 @@ resources: variables: imageTag: $(Build.BuildNumber) fusionAcr: 'fusioncr.azurecr.io' - imageRepo: resources/fra-summary-api + imageRepo: fra/fusion-summary-api imageName: $(imageRepo):$(imageTag) subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-test-env.yml' From 0c3ead424c2b7f7f0adc6421ac6759b9ef1105f2 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:20:29 +0200 Subject: [PATCH 08/55] target to publish --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 024489674..1f042e4c4 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -56,7 +56,7 @@ stages: buildContext: ./src dockerfile: src/Fusion.Summary.Api/Dockerfile arguments: | - --target=export + --target=publish --output=type=local,dest=$(Build.ArtifactStagingDirectory) --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) From f60e925936593e5a5f7e0da47da1c2ca127e3869 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:40:17 +0200 Subject: [PATCH 09/55] target to final --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 1f042e4c4..23f49b34a 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -56,7 +56,7 @@ stages: buildContext: ./src dockerfile: src/Fusion.Summary.Api/Dockerfile arguments: | - --target=publish + --target=final --output=type=local,dest=$(Build.ArtifactStagingDirectory) --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) From 4ffea89abe328417bec64f98151449866fae88c5 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:06:38 +0200 Subject: [PATCH 10/55] revert target to publish --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 23f49b34a..1f042e4c4 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -56,7 +56,7 @@ stages: buildContext: ./src dockerfile: src/Fusion.Summary.Api/Dockerfile arguments: | - --target=final + --target=publish --output=type=local,dest=$(Build.ArtifactStagingDirectory) --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) From 994cca0d1e1ae5e1d00783bbeba561f84d1a1756 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 08:09:17 +0200 Subject: [PATCH 11/55] Revert "revert target to publish" This reverts commit 4ffea89abe328417bec64f98151449866fae88c5. --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 1f042e4c4..23f49b34a 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -56,7 +56,7 @@ stages: buildContext: ./src dockerfile: src/Fusion.Summary.Api/Dockerfile arguments: | - --target=publish + --target=final --output=type=local,dest=$(Build.ArtifactStagingDirectory) --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) From 07dbefee5dcdbdec871958d89a930b957493d559 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 08:31:56 +0200 Subject: [PATCH 12/55] Use windows agnet and removed UseAppHost from dockerfile --- pipelines/summary-api-pipeline.yml | 2 +- src/Fusion.Summary.Api/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 23f49b34a..ea90ad07f 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -11,7 +11,7 @@ trigger: - src/Fusion.Summary.Api/* pool: - vmImage: ubuntu-latest + vmImage: windows-2022 resources: repositories: diff --git a/src/Fusion.Summary.Api/Dockerfile b/src/Fusion.Summary.Api/Dockerfile index 912d038da..6b6c07ff9 100644 --- a/src/Fusion.Summary.Api/Dockerfile +++ b/src/Fusion.Summary.Api/Dockerfile @@ -18,7 +18,7 @@ RUN dotnet build "./Fusion.Summary.Api.csproj" -c $BUILD_CONFIGURATION -o /app/b FROM build AS publish ARG BUILD_CONFIGURATION=Release -RUN dotnet publish "./Fusion.Summary.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false +RUN dotnet publish "./Fusion.Summary.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish FROM base AS final WORKDIR /app From 9e3a213993a1dbda42f63978ff223ef3daf3c979 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 08:53:30 +0200 Subject: [PATCH 13/55] Use ubuntu agent --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index ea90ad07f..23f49b34a 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -11,7 +11,7 @@ trigger: - src/Fusion.Summary.Api/* pool: - vmImage: windows-2022 + vmImage: ubuntu-latest resources: repositories: From ac6b538068bf4f4b4654a2c7e288b5279a4d4003 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:07:04 +0200 Subject: [PATCH 14/55] List ArtifactStagingDirectory --- pipelines/summary-api-pipeline.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 23f49b34a..809c9c1fa 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -66,7 +66,9 @@ stages: SourceFolder: 'src/Fusion.Summary.Api/Deployment/k8s' Contents: | deployment-test-env.yml - TargetFolder: '$(Build.ArtifactStagingDirectory)' + TargetFolder: '$(Build.ArtifactStagingDirectory)' + + - bash: ls -acl $(Build.ArtifactStagingDirectory) - publish: $(Build.ArtifactStagingDirectory) artifact: 'k8s-deployment' From cc0688328ab59ce36299f3164080ba2e452cfa80 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:15:35 +0200 Subject: [PATCH 15/55] Testing --- pipelines/summary-api-pipeline.yml | 45 +++++++++++++++++------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 809c9c1fa..65821bc58 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -40,25 +40,30 @@ stages: inputs: command: login containerRegistry: fusioncr - - template: templates/docker-buildx.yml@infra - parameters: - repository: $(imageRepo) - buildContext: ./src - dockerfile: src/Fusion.Summary.Api/Dockerfile - dockerPush: true - disableCache: true - tags: | - $(imageTag) - - template: templates/docker-buildx.yml@infra - parameters: - initBuilderInstance: false - repository: '' - buildContext: ./src - dockerfile: src/Fusion.Summary.Api/Dockerfile - arguments: | - --target=final - --output=type=local,dest=$(Build.ArtifactStagingDirectory) - --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) + # - template: templates/docker-buildx.yml@infra + # parameters: + # repository: $(imageRepo) + # buildContext: ./src + # dockerfile: src/Fusion.Summary.Api/Dockerfile + # dockerPush: true + # disableCache: true + # tags: | + # $(imageTag) + # - template: templates/docker-buildx.yml@infra + # parameters: + # initBuilderInstance: false + # repository: '' + # buildContext: ./src + # dockerfile: src/Fusion.Summary.Api/Dockerfile + # arguments: | + # --target=final + # --output=type=local,dest=$(Build.ArtifactStagingDirectory) + # --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) + + - bash: ls -acl src/ + - bash: ls -acl src/Fusion.Summary.Api/ + - bash: ls -acl src/Fusion.Summary.Api/Deployment + - bash: ls -acl src/Fusion.Summary.Api/Deployment/k8s - task: CopyFiles@2 displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)' @@ -69,6 +74,8 @@ stages: TargetFolder: '$(Build.ArtifactStagingDirectory)' - bash: ls -acl $(Build.ArtifactStagingDirectory) + + - bash: echo "test" >> $(Build.ArtifactStagingDirectory)/testFile - publish: $(Build.ArtifactStagingDirectory) artifact: 'k8s-deployment' From 55af2215a23fbb83cb44c22c88f171d32b7ce4b0 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:31:39 +0200 Subject: [PATCH 16/55] Testing --- pipelines/summary-api-pipeline.yml | 45 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 65821bc58..1c93a8024 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -40,25 +40,25 @@ stages: inputs: command: login containerRegistry: fusioncr - # - template: templates/docker-buildx.yml@infra - # parameters: - # repository: $(imageRepo) - # buildContext: ./src - # dockerfile: src/Fusion.Summary.Api/Dockerfile - # dockerPush: true - # disableCache: true - # tags: | - # $(imageTag) - # - template: templates/docker-buildx.yml@infra - # parameters: - # initBuilderInstance: false - # repository: '' - # buildContext: ./src - # dockerfile: src/Fusion.Summary.Api/Dockerfile - # arguments: | - # --target=final - # --output=type=local,dest=$(Build.ArtifactStagingDirectory) - # --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) + - template: templates/docker-buildx.yml@infra + parameters: + repository: $(imageRepo) + buildContext: ./src + dockerfile: src/Fusion.Summary.Api/Dockerfile + dockerPush: true + disableCache: true + tags: | + $(imageTag) + - template: templates/docker-buildx.yml@infra + parameters: + initBuilderInstance: false + repository: '' + buildContext: ./src + dockerfile: src/Fusion.Summary.Api/Dockerfile + arguments: | + --target=final + --output=type=local,dest=$(Build.ArtifactStagingDirectory) + --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) - bash: ls -acl src/ - bash: ls -acl src/Fusion.Summary.Api/ @@ -76,7 +76,12 @@ stages: - bash: ls -acl $(Build.ArtifactStagingDirectory) - bash: echo "test" >> $(Build.ArtifactStagingDirectory)/testFile - + + - bash: ls -acl /home/vsts/work/1/a/lib/ + - bash: ls -acl /home/vsts/work/1/a/lib/ssl/ + - bash: ls -acl /home/vsts/work/1/a/lib/ssl/private + + - publish: $(Build.ArtifactStagingDirectory) artifact: 'k8s-deployment' From e572b84ab62f951cf1372d9dfff3f900637b1c09 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:36:48 +0200 Subject: [PATCH 17/55] Testing --- pipelines/summary-api-pipeline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 1c93a8024..a25b81ae1 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -80,6 +80,7 @@ stages: - bash: ls -acl /home/vsts/work/1/a/lib/ - bash: ls -acl /home/vsts/work/1/a/lib/ssl/ - bash: ls -acl /home/vsts/work/1/a/lib/ssl/private + - bash: ls -acl /etc/ssl/private - publish: $(Build.ArtifactStagingDirectory) From 9a7204329b87e94854811dc03ec057c148ded878 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:45:09 +0200 Subject: [PATCH 18/55] Testing --- pipelines/summary-api-pipeline.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index a25b81ae1..c69a14e5c 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -57,7 +57,7 @@ stages: dockerfile: src/Fusion.Summary.Api/Dockerfile arguments: | --target=final - --output=type=local,dest=$(Build.ArtifactStagingDirectory) + --output=type=local,dest=$(Build.ArtifactStagingDirectory)/output --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) - bash: ls -acl src/ @@ -66,24 +66,24 @@ stages: - bash: ls -acl src/Fusion.Summary.Api/Deployment/k8s - task: CopyFiles@2 - displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)' + displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)/output' inputs: SourceFolder: 'src/Fusion.Summary.Api/Deployment/k8s' Contents: | deployment-test-env.yml - TargetFolder: '$(Build.ArtifactStagingDirectory)' + TargetFolder: '$(Build.ArtifactStagingDirectory)/output' - bash: ls -acl $(Build.ArtifactStagingDirectory) + - bash: ls -acl $(Build.ArtifactStagingDirectory)/output - bash: echo "test" >> $(Build.ArtifactStagingDirectory)/testFile - bash: ls -acl /home/vsts/work/1/a/lib/ - bash: ls -acl /home/vsts/work/1/a/lib/ssl/ - bash: ls -acl /home/vsts/work/1/a/lib/ssl/private - - bash: ls -acl /etc/ssl/private - - publish: $(Build.ArtifactStagingDirectory) + - publish: $(Build.ArtifactStagingDirectory)/output artifact: 'k8s-deployment' - stage: DeployCI From 2e4918ef84c268411cae1eceb934885b6124050b Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:48:30 +0200 Subject: [PATCH 19/55] Testing --- pipelines/summary-api-pipeline.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index c69a14e5c..4cbe8081e 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -78,10 +78,6 @@ stages: - bash: echo "test" >> $(Build.ArtifactStagingDirectory)/testFile - - bash: ls -acl /home/vsts/work/1/a/lib/ - - bash: ls -acl /home/vsts/work/1/a/lib/ssl/ - - bash: ls -acl /home/vsts/work/1/a/lib/ssl/private - - publish: $(Build.ArtifactStagingDirectory)/output artifact: 'k8s-deployment' From 9b18ce6643c81443cf236f609ab9eae0996a513e Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:13:01 +0200 Subject: [PATCH 20/55] Testing resources --- pipelines/api-pipeline.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pipelines/api-pipeline.yml b/pipelines/api-pipeline.yml index 5d526b2f1..3116a7b88 100644 --- a/pipelines/api-pipeline.yml +++ b/pipelines/api-pipeline.yml @@ -68,6 +68,9 @@ stages: deployment-test-env.yml TargetFolder: '$(Build.ArtifactStagingDirectory)' + - bash: ls -acl $(Build.ArtifactStagingDirectory) + + - publish: $(Build.ArtifactStagingDirectory) artifact: 'k8s-deployment' From 1551c97c171d01fbadc577328fc13a83cffa5b26 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:17:19 +0200 Subject: [PATCH 21/55] testing --- pipelines/summary-api-pipeline.yml | 19 +++++-------------- src/Fusion.Summary.Api/Dockerfile | 9 +++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 4cbe8081e..582332df8 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -56,30 +56,21 @@ stages: buildContext: ./src dockerfile: src/Fusion.Summary.Api/Dockerfile arguments: | - --target=final - --output=type=local,dest=$(Build.ArtifactStagingDirectory)/output + --target=export + --output=type=local,dest=$(Build.ArtifactStagingDirectory) --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(imageTag) - - bash: ls -acl src/ - - bash: ls -acl src/Fusion.Summary.Api/ - - bash: ls -acl src/Fusion.Summary.Api/Deployment - - bash: ls -acl src/Fusion.Summary.Api/Deployment/k8s - - task: CopyFiles@2 - displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)/output' + displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)' inputs: SourceFolder: 'src/Fusion.Summary.Api/Deployment/k8s' Contents: | deployment-test-env.yml - TargetFolder: '$(Build.ArtifactStagingDirectory)/output' + TargetFolder: '$(Build.ArtifactStagingDirectory)' - bash: ls -acl $(Build.ArtifactStagingDirectory) - - bash: ls -acl $(Build.ArtifactStagingDirectory)/output - - - bash: echo "test" >> $(Build.ArtifactStagingDirectory)/testFile - - - publish: $(Build.ArtifactStagingDirectory)/output + - publish: $(Build.ArtifactStagingDirectory) artifact: 'k8s-deployment' - stage: DeployCI diff --git a/src/Fusion.Summary.Api/Dockerfile b/src/Fusion.Summary.Api/Dockerfile index 6b6c07ff9..a4dc8d4db 100644 --- a/src/Fusion.Summary.Api/Dockerfile +++ b/src/Fusion.Summary.Api/Dockerfile @@ -17,8 +17,17 @@ WORKDIR "/src/Fusion.Summary.Api" RUN dotnet build "./Fusion.Summary.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish + +## Set an variable to indicate build +ENV IS_DOCKER_BUILD=true + ARG BUILD_CONFIGURATION=Release +RUN dotnet tool restore RUN dotnet publish "./Fusion.Summary.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish +RUN dotnet ef migrations script --idempotent --output "/migrations/migration.sql" --configuration Release --no-build + +FROM scratch as export +COPY --from=publish /migrations/migration.sql db-migration.sql FROM base AS final WORKDIR /app From 1477e89454de03709f4fa410592b7b4c40968d64 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:18:33 +0200 Subject: [PATCH 22/55] COPY --from=publish /migrations . --- src/Fusion.Summary.Api/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Fusion.Summary.Api/Dockerfile b/src/Fusion.Summary.Api/Dockerfile index a4dc8d4db..af2dc56ba 100644 --- a/src/Fusion.Summary.Api/Dockerfile +++ b/src/Fusion.Summary.Api/Dockerfile @@ -32,4 +32,5 @@ COPY --from=publish /migrations/migration.sql db-migration.sql FROM base AS final WORKDIR /app COPY --from=publish /app/publish . +COPY --from=publish /migrations . ENTRYPOINT ["dotnet", "Fusion.Summary.Api.dll"] \ No newline at end of file From 4cbf44fe8a34623619597057b8a40a3de3629d1c Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:21:03 +0200 Subject: [PATCH 23/55] ef tools test --- src/Fusion.Summary.Api/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Dockerfile b/src/Fusion.Summary.Api/Dockerfile index af2dc56ba..2ed4fa748 100644 --- a/src/Fusion.Summary.Api/Dockerfile +++ b/src/Fusion.Summary.Api/Dockerfile @@ -22,7 +22,8 @@ FROM build AS publish ENV IS_DOCKER_BUILD=true ARG BUILD_CONFIGURATION=Release -RUN dotnet tool restore +RUN dotnet tool install --global dotnet-ef +ENV PATH="$PATH:/root/.dotnet/tools" RUN dotnet publish "./Fusion.Summary.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish RUN dotnet ef migrations script --idempotent --output "/migrations/migration.sql" --configuration Release --no-build From c98a5eec20515928da9a55dfd84f7fdeed938b1a Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:44:54 +0200 Subject: [PATCH 24/55] Use windows agent --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 582332df8..3b51e4094 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -11,7 +11,7 @@ trigger: - src/Fusion.Summary.Api/* pool: - vmImage: ubuntu-latest + vmImage: windows-2022 resources: repositories: From c78c68c5f6353de1925b0730c004c9db768c2657 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:47:16 +0200 Subject: [PATCH 25/55] Revert "Use windows agent" This reverts commit c98a5eec20515928da9a55dfd84f7fdeed938b1a. --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 3b51e4094..582332df8 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -11,7 +11,7 @@ trigger: - src/Fusion.Summary.Api/* pool: - vmImage: windows-2022 + vmImage: ubuntu-latest resources: repositories: From cf11c48600ab895b05290baede0c2fccfa348c55 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:29:42 +0200 Subject: [PATCH 26/55] Azurepwsh@5 --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 582332df8..24a94b99c 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -89,7 +89,7 @@ stages: runOnce: deploy: steps: - - task: AzurePowerShell@4 + - task: AzurePowerShell@5 displayName: 'Get secrets' inputs: azureSubscription: $(subscriptionService) From 00193986ca1f61b7dcab0a8064fa9210efaca3b4 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:34:19 +0200 Subject: [PATCH 27/55] Azurepwsh@5 for templates --- pipelines/templates/get-appinsights-key.yml | 2 +- pipelines/templates/get-keyvault-url.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/templates/get-appinsights-key.yml b/pipelines/templates/get-appinsights-key.yml index 6150e35d3..37eb7c32e 100644 --- a/pipelines/templates/get-appinsights-key.yml +++ b/pipelines/templates/get-appinsights-key.yml @@ -4,7 +4,7 @@ parameters: variableName: 'instrumentationKey' steps: -- task: AzurePowerShell@4 +- task: AzurePowerShell@5 displayName: 'Get Application Insights telemetry key for ${{ parameters.environment }}' inputs: azureSubscription: $(subscriptionService) diff --git a/pipelines/templates/get-keyvault-url.yml b/pipelines/templates/get-keyvault-url.yml index 68a791190..65370f6e9 100644 --- a/pipelines/templates/get-keyvault-url.yml +++ b/pipelines/templates/get-keyvault-url.yml @@ -4,7 +4,7 @@ parameters: variableName: 'envKeyVaultUrl' steps: -- task: AzurePowerShell@4 +- task: AzurePowerShell@5 displayName: 'Get key vault url for environment ${{ parameters.environment }}' inputs: azureSubscription: $(subscriptionService) From a7ebaf1030d70a6a87ccd25ef9a124277fa4430b Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:38:00 +0200 Subject: [PATCH 28/55] Azurepwsh@5 for templates --- pipelines/templates/execute-sql-migration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/templates/execute-sql-migration.yml b/pipelines/templates/execute-sql-migration.yml index 7c69b3929..dc9c46e6f 100644 --- a/pipelines/templates/execute-sql-migration.yml +++ b/pipelines/templates/execute-sql-migration.yml @@ -10,7 +10,7 @@ steps: # inputs: # buildType: 'current' - - task: AzurePowerShell@4 + - task: AzurePowerShell@5 displayName: 'Execute sql migrations' inputs: azureSubscription: ${{ parameters.azureSubscription }} From f3e877694d31e7d46fbda8335bf25bec34cd76f6 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:41:50 +0200 Subject: [PATCH 29/55] Updated sql db target tag --- pipelines/api-pipeline.yml | 7 ++++++- pipelines/summary-api-pipeline.yml | 7 ++++++- pipelines/templates/execute-sql-migration.yml | 8 +++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pipelines/api-pipeline.yml b/pipelines/api-pipeline.yml index 3116a7b88..ccb0fb93a 100644 --- a/pipelines/api-pipeline.yml +++ b/pipelines/api-pipeline.yml @@ -28,6 +28,7 @@ variables: subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-test-env.yml' fullImageName: $(fusionAcr)/$(imageName) + dbTagPrefix: resources stages: - stage: BuildDockerImage @@ -119,7 +120,8 @@ stages: - template: templates/execute-sql-migration.yml parameters: artifact: 'k8s-deployment' - environment: $(envName) + environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -172,6 +174,7 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -224,6 +227,7 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -283,6 +287,7 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 24a94b99c..e6763b4e1 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -28,6 +28,7 @@ variables: subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-test-env.yml' fullImageName: $(fusionAcr)/$(imageName) + dbTagPrefix: resources stages: - stage: BuildDockerImage @@ -118,7 +119,8 @@ stages: - template: templates/execute-sql-migration.yml parameters: artifact: 'k8s-deployment' - environment: $(envName) + environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -171,6 +173,7 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -223,6 +226,7 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -282,6 +286,7 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster diff --git a/pipelines/templates/execute-sql-migration.yml b/pipelines/templates/execute-sql-migration.yml index dc9c46e6f..f0566744d 100644 --- a/pipelines/templates/execute-sql-migration.yml +++ b/pipelines/templates/execute-sql-migration.yml @@ -3,6 +3,7 @@ parameters: sqlFile: '' artifact: 'drop' environment: '' + dbTagPrefix: '' steps: # - task: DownloadPipelineArtifact@2 @@ -24,12 +25,17 @@ steps: if (-not [string]::IsNullOrEmpty($overrideFileName)) { $sqlFile = $overrideFileName } + + $dbTagPrefix = "${{ parameters.dbTagPrefix }}" + if ($dbTagPrefix -eq '') { + throw "dbTagPrefix is required" + } ## Use access token to access database - the service principal should be located in the sql server admin group. $context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext $token = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, "https://database.windows.net/") - $dbResource = Get-AzResource -TagName fusion-app-component-id -TagValue "resources-api-db-${{ parameters.environment }}" | select -First 1 + $dbResource = Get-AzResource -TagName fusion-app-component-id -TagValue "${{ parameters.dbTagPrefix }}-api-db-${{ parameters.environment }}" | select -First 1 $db = Get-AzSqlDatabase -DatabaseName $dbResource.Name.Split("/")[1] -ResourceGroupName $dbResource.ResourceGroupName -ServerName $dbResource.Name.Split("/")[0] $sqlServer = Get-AzSqlServer -ServerName $db.ServerName -ResourceGroupName $db.ResourceGroupName From 38c09dca4a401458a418514522c18a8f2b802d33 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:18:43 +0200 Subject: [PATCH 30/55] TMP removed sql migration --- pipelines/summary-api-pipeline.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index e6763b4e1..a41a7011e 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -116,11 +116,11 @@ stages: parameters: targetFiles: '$(deploymentManifest)' - - template: templates/execute-sql-migration.yml - parameters: - artifact: 'k8s-deployment' - environment: $(envName) - dbTagPrefix: $(dbTagPrefix) + # - template: templates/execute-sql-migration.yml + # parameters: + # artifact: 'k8s-deployment' + # environment: $(envName) + # dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster From adcfe618beb98fc0c57b580e1ca51c9733d71659 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:51:05 +0200 Subject: [PATCH 31/55] Added sql exec to steps --- pipelines/summary-api-pipeline.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index a41a7011e..43d1be004 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -28,7 +28,7 @@ variables: subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-test-env.yml' fullImageName: $(fusionAcr)/$(imageName) - dbTagPrefix: resources + dbTagPrefix: summary stages: - stage: BuildDockerImage @@ -116,11 +116,11 @@ stages: parameters: targetFiles: '$(deploymentManifest)' - # - template: templates/execute-sql-migration.yml - # parameters: - # artifact: 'k8s-deployment' - # environment: $(envName) - # dbTagPrefix: $(dbTagPrefix) + - template: templates/execute-sql-migration.yml + parameters: + artifact: 'k8s-deployment' + environment: $(envName) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster From ced1951ff7e21b06a43ac57ad53564560f325f9d Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:59:05 +0200 Subject: [PATCH 32/55] replaced tab with spaces --- pipelines/templates/execute-sql-migration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/templates/execute-sql-migration.yml b/pipelines/templates/execute-sql-migration.yml index f0566744d..6db4ce5a9 100644 --- a/pipelines/templates/execute-sql-migration.yml +++ b/pipelines/templates/execute-sql-migration.yml @@ -3,7 +3,7 @@ parameters: sqlFile: '' artifact: 'drop' environment: '' - dbTagPrefix: '' + dbTagPrefix: '' steps: # - task: DownloadPipelineArtifact@2 From c0987e464ca44450d88769e2fc2fecadff59d5f3 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:08:38 +0200 Subject: [PATCH 33/55] Changed env --- pipelines/summary-api-pipeline.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 43d1be004..8be044faa 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -85,7 +85,7 @@ stages: jobs: - deployment: DeployCI - environment: fra-ci + environment: fusion-ci strategy: runOnce: deploy: @@ -139,7 +139,7 @@ stages: jobs: - deployment: DeployFQA - environment: fra-fqa + environment: fusion-fqa strategy: runOnce: deploy: @@ -192,7 +192,7 @@ stages: jobs: - deployment: DeployFPRD - environment: fra-fprd + environment: fusion-fprd strategy: runOnce: deploy: From f8266d87ed6f8d239c2b915b48dff1c86c1e84fa Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:11:27 +0200 Subject: [PATCH 34/55] env typo --- pipelines/summary-api-pipeline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 8be044faa..c4242f679 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -192,7 +192,7 @@ stages: jobs: - deployment: DeployFPRD - environment: fusion-fprd + environment: fusion-prod strategy: runOnce: deploy: @@ -252,7 +252,7 @@ stages: jobs: - deployment: DeployTR - environment: fra-tr + environment: fusion-tr strategy: runOnce: deploy: From 241544f430954372698a36eaf688b5052375ede2 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:53:25 +0200 Subject: [PATCH 35/55] env fusion-resources-app-ci --- pipelines/summary-api-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index c4242f679..4ae47246b 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -85,7 +85,7 @@ stages: jobs: - deployment: DeployCI - environment: fusion-ci + environment: fusion-ci.fusion-resources-app-ci strategy: runOnce: deploy: From 1869cfb1b6a40ece17c3562b09ac915ae928ff2d Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:02:08 +0200 Subject: [PATCH 36/55] Updated healthcehck endpoint --- src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml b/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml index 9ad16ad6e..852af22d2 100644 --- a/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml +++ b/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml @@ -78,7 +78,7 @@ spec: readinessProbe: httpGet: - path: /_health/ready + path: /_health/readiness port: 8080 initialDelaySeconds: 10 timeoutSeconds: 30 From 57315121084eb0a797028d21f8ae7cdb7c4677ba Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:08:14 +0200 Subject: [PATCH 37/55] Updated service selector --- src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml b/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml index 852af22d2..4eaebd2c9 100644 --- a/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml +++ b/src/Fusion.Summary.Api/Deployment/k8s/deployment-test-env.yml @@ -122,6 +122,6 @@ spec: pathType: Prefix backend: service: - name: resources-api + name: summary-api port: number: 80 \ No newline at end of file From 3aadcbfdbe623ab57f2d5d762e89311e57a1d55e Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:17:13 +0200 Subject: [PATCH 38/55] Add real db health check --- src/Fusion.Summary.Api/Program.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 1f5695b6f..8895f4aca 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -26,9 +26,7 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddHealthChecks() .AddCheck("liveness", () => HealthCheckResult.Healthy()) - .AddCheck("db", () => HealthCheckResult.Healthy(), tags: ["ready"]); -// TODO: Add a real health check, when database is added -// .AddDbContextCheck("db", tags: new[] { "ready" }); + .AddDbContextCheck("db", tags: new[] { "ready" }); builder.Services From 3e7fc803bf9a03a44f99309067eb06432736f22d Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 16 Aug 2024 09:36:40 +0200 Subject: [PATCH 39/55] Revert "Add real db health check" This reverts commit 3aadcbfdbe623ab57f2d5d762e89311e57a1d55e. --- src/Fusion.Summary.Api/Program.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 8895f4aca..1f5695b6f 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -26,7 +26,9 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddHealthChecks() .AddCheck("liveness", () => HealthCheckResult.Healthy()) - .AddDbContextCheck("db", tags: new[] { "ready" }); + .AddCheck("db", () => HealthCheckResult.Healthy(), tags: ["ready"]); +// TODO: Add a real health check, when database is added +// .AddDbContextCheck("db", tags: new[] { "ready" }); builder.Services From d08868ecd7288a21162e7f447af3caa5583e22ba Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 16 Aug 2024 09:53:43 +0200 Subject: [PATCH 40/55] Updated summary api pipeline to match updated structure --- pipelines/summary-api-pipeline.yml | 49 +++++++++++++++++++----------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/pipelines/summary-api-pipeline.yml b/pipelines/summary-api-pipeline.yml index 4ae47246b..e897538dc 100644 --- a/pipelines/summary-api-pipeline.yml +++ b/pipelines/summary-api-pipeline.yml @@ -25,7 +25,8 @@ variables: fusionAcr: 'fusioncr.azurecr.io' imageRepo: fra/fusion-summary-api imageName: $(imageRepo):$(imageTag) - subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' + subscriptionServiceNonProd: 'FRA Automation Non-Prod' + subscriptionServiceProd: 'FRA Automation Prod' deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-test-env.yml' fullImageName: $(fusionAcr)/$(imageName) dbTagPrefix: summary @@ -67,9 +68,7 @@ stages: SourceFolder: 'src/Fusion.Summary.Api/Deployment/k8s' Contents: | deployment-test-env.yml - TargetFolder: '$(Build.ArtifactStagingDirectory)' - - - bash: ls -acl $(Build.ArtifactStagingDirectory) + TargetFolder: '$(Build.ArtifactStagingDirectory)' - publish: $(Build.ArtifactStagingDirectory) artifact: 'k8s-deployment' @@ -93,7 +92,7 @@ stages: - task: AzurePowerShell@5 displayName: 'Get secrets' inputs: - azureSubscription: $(subscriptionService) + azureSubscription: $(subscriptionServiceNonProd) ScriptType: 'InlineScript' FailOnStandardError: true azurePowerShellVersion: 'LatestVersion' @@ -104,12 +103,15 @@ stages: - template: templates/get-appinsights-key.yml parameters: environment: $(envName) + azureSubscription: $(subscriptionServiceNonProd) + # Load the key vault url into variable, so it can be used when replacing tokens. - template: templates/get-keyvault-url.yml parameters: environment: $(envName) variableName: envKeyVaultUrl + azureSubscription: $(subscriptionServiceNonProd) - template: templates/replace-tokens.yml @@ -120,7 +122,8 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) - dbTagPrefix: $(dbTagPrefix) + azureSubscription: $(subscriptionServiceNonProd) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -139,15 +142,15 @@ stages: jobs: - deployment: DeployFQA - environment: fusion-fqa + environment: fusion-fqa.fusion-resources-app-fqa strategy: runOnce: deploy: steps: - - task: AzurePowerShell@4 + - task: AzurePowerShell@5 displayName: 'Get secrets' inputs: - azureSubscription: $(subscriptionService) + azureSubscription: $(subscriptionServiceNonProd) ScriptType: 'InlineScript' FailOnStandardError: true azurePowerShellVersion: 'LatestVersion' @@ -158,12 +161,14 @@ stages: - template: templates/get-appinsights-key.yml parameters: environment: $(envName) + azureSubscription: $(subscriptionServiceNonProd) # Load the key vault url into variable, so it can be used when replacing tokens. - template: templates/get-keyvault-url.yml parameters: environment: $(envName) variableName: envKeyVaultUrl + azureSubscription: $(subscriptionServiceNonProd) - template: templates/replace-tokens.yml parameters: @@ -173,7 +178,8 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) - dbTagPrefix: $(dbTagPrefix) + azureSubscription: $(subscriptionServiceNonProd) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -192,15 +198,15 @@ stages: jobs: - deployment: DeployFPRD - environment: fusion-prod + environment: fusion-prod.fusion-resources-app-fprd strategy: runOnce: deploy: steps: - - task: AzurePowerShell@4 + - task: AzurePowerShell@5 displayName: 'Get secrets' inputs: - azureSubscription: $(subscriptionService) + azureSubscription: $(subscriptionServiceProd) ScriptType: 'InlineScript' FailOnStandardError: true azurePowerShellVersion: 'LatestVersion' @@ -211,12 +217,14 @@ stages: - template: templates/get-appinsights-key.yml parameters: environment: $(envName) + azureSubscription: $(subscriptionServiceProd) # Load the key vault url into variable, so it can be used when replacing tokens. - template: templates/get-keyvault-url.yml parameters: environment: $(envName) variableName: envKeyVaultUrl + azureSubscription: $(subscriptionServiceProd) - template: templates/replace-tokens.yml parameters: @@ -226,7 +234,8 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) - dbTagPrefix: $(dbTagPrefix) + azureSubscription: $(subscriptionServiceProd) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster @@ -236,6 +245,7 @@ stages: - template: templates/deploy-container-app.yml parameters: + azureSubscription: $(subscriptionServiceProd) environment: $(envName) fusionEnvironment: $(fusionEnvironment) clientId: $(clientId) @@ -252,15 +262,15 @@ stages: jobs: - deployment: DeployTR - environment: fusion-tr + environment: fusion-tr.fusion-resources-app-tr strategy: runOnce: deploy: steps: - - task: AzurePowerShell@4 + - task: AzurePowerShell@5 displayName: 'Get secrets' inputs: - azureSubscription: $(subscriptionService) + azureSubscription: $(subscriptionServiceNonProd) ScriptType: 'InlineScript' FailOnStandardError: true azurePowerShellVersion: 'LatestVersion' @@ -271,12 +281,14 @@ stages: - template: templates/get-appinsights-key.yml parameters: environment: $(envName) + azureSubscription: $(subscriptionServiceNonProd) # Load the key vault url into variable, so it can be used when replacing tokens. - template: templates/get-keyvault-url.yml parameters: environment: $(envName) variableName: envKeyVaultUrl + azureSubscription: $(subscriptionServiceNonProd) - template: templates/replace-tokens.yml parameters: @@ -286,7 +298,8 @@ stages: parameters: artifact: 'k8s-deployment' environment: $(envName) - dbTagPrefix: $(dbTagPrefix) + azureSubscription: $(subscriptionServiceNonProd) + dbTagPrefix: $(dbTagPrefix) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster From 1943a58361da5fce659ce2759e1435ddfa8e0498 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:50:42 +0200 Subject: [PATCH 41/55] Updated summary PR pipeline to deploy PR DB --- pipelines/pr-cleanup-pipeline.yml | 2 +- pipelines/summary-api-pr-pipeline.yml | 36 ++++++++++++++++++- .../Deployment/k8s/deployment-pr-env.yml | 4 ++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pipelines/pr-cleanup-pipeline.yml b/pipelines/pr-cleanup-pipeline.yml index 3581c1263..3b109edbd 100644 --- a/pipelines/pr-cleanup-pipeline.yml +++ b/pipelines/pr-cleanup-pipeline.yml @@ -42,7 +42,7 @@ jobs: Inline: | $activePRs = "$(activePrs)".Split(",") - $prDbs = Get-AzResource -ResourceType "Microsoft.Sql/servers/databases" -Tag @{"fusion-app-env" = "pr" } -ResourceGroupName Fusion-SQL-Test | Where-Object { $_.Tags["fusion-app"] -eq "resources" } + $prDbs = Get-AzResource -ResourceType "Microsoft.Sql/servers/databases" -Tag @{"fusion-app-env" = "pr" } -ResourceGroupName Fusion-SQL-Test | Where-Object { $_.Tags["fusion-app"] -eq "resources" -or $_.Tags["fusion-app"] -eq "summary" } foreach ($db in $prDbs) { if ($db.Tags["fusion-app-env"] -ne "pr") { diff --git a/pipelines/summary-api-pr-pipeline.yml b/pipelines/summary-api-pr-pipeline.yml index 1d54c2616..135b856a2 100644 --- a/pipelines/summary-api-pr-pipeline.yml +++ b/pipelines/summary-api-pr-pipeline.yml @@ -22,7 +22,8 @@ variables: fusionAcr: 'fusioncr.azurecr.io' imageRepo: resources/fusion-summary-api imageName: $(imageRepo):$(prNumber) - subscriptionService: 'PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe)' + subscriptionService: 'FRA Automation Non-Prod' + subscriptionServiceCore: PROJECT_PORTAL (63b791ae-b2bc-41a1-ac66-806c4e69bffe) deploymentManifest: '$(Pipeline.Workspace)/k8s-deployment/deployment-pr-env.yml' fullImageName: $(fusionAcr)/$(imageName) buildNr: $(Build.BuildNumber) @@ -98,6 +99,39 @@ stages: $secretText = Get-AzKeyVaultSecret -VaultName kv-fap-resources-pr -Name AzureAd--ClientSecret -AsPlainText Write-Output "##vso[task.setvariable variable=clientSecret;issecret=true]$($secretText)" + ## MUST RUN THIS AS THE CORE SERVICE PRINCIPAL, UNTILL NEW DB DEPLOY IS ESTABLISHED + - task: AzurePowerShell@5 + displayName: 'Provision database' + inputs: + azureSubscription: $(subscriptionServiceCore) + ScriptType: 'InlineScript' + FailOnStandardError: true + azurePowerShellVersion: 'LatestVersion' + Inline: | + Import-Module FusionPS + + $dbName = "sqldb-fapp-fra-summary-db-PR-$(prNumber)" + $tags = @{ + "pr" = "$(prNumber)" + "fusion-app-component-id" = "summary-api-db-pr-$(prNumber)" + "fusion-app" = "summary" + "fusion-app-env" = "pr" + } + + New-FusionSqlDatabaseV2 ` + -InfraEnv Test ` + -DatabaseName $dbName ` + -SourceDatabase sqldb-fapp-fra-summary-db-CI ` + -Tags $tags + + Set-FusionAzSqlDatabaseAccess ` + -InfraEnv Test ` + -Environment PR ` + -DatabaseName $dbName + + $connectionString = Get-FusionSqlServerConnectionString -InfraEnv Test -DatabaseName $dbName + Write-Output "##vso[task.setvariable variable=dbConnectionString]$($connectionString)" + - template: templates/get-appinsights-key.yml parameters: environment: $(envName) diff --git a/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml b/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml index cf72a9a77..37fc506b2 100644 --- a/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml +++ b/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml @@ -65,7 +65,9 @@ spec: - name: AzureAd__ClientId value: "{{clientId}}" - name: BuildNr - value: "{{buildNr}}" + value: "{{buildNr}}" + - name: ConnectionStrings__SummaryDbContext + value: "{{dbConnectionString}}" args: - /server From 58040161b503bf8eec06203215566b279a8f518d Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:00:06 +0200 Subject: [PATCH 42/55] Run migration for PR db --- pipelines/summary-api-pr-pipeline.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pipelines/summary-api-pr-pipeline.yml b/pipelines/summary-api-pr-pipeline.yml index 135b856a2..e75e24e8b 100644 --- a/pipelines/summary-api-pr-pipeline.yml +++ b/pipelines/summary-api-pr-pipeline.yml @@ -145,6 +145,12 @@ stages: - template: templates/replace-tokens.yml parameters: targetFiles: '$(deploymentManifest)' + + - template: templates/execute-sql-migration.yml + parameters: + artifact: 'k8s-deployment' + environment: '$(envName)-$(prNumber)' + azureSubscription: $(subscriptionService) - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster From 2b4d101d8f648e26da45c6b7dd1176dc97527ab2 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:11:58 +0200 Subject: [PATCH 43/55] Changed PR env to fra-pr.fusion-resources-app-pr --- pipelines/summary-api-pr-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/summary-api-pr-pipeline.yml b/pipelines/summary-api-pr-pipeline.yml index e75e24e8b..fc0388299 100644 --- a/pipelines/summary-api-pr-pipeline.yml +++ b/pipelines/summary-api-pr-pipeline.yml @@ -81,7 +81,7 @@ stages: jobs: - deployment: DeployPR displayName: 'Deploy API to PR' - environment: fusion-summary-pr.fusion-summary-app-pr + environment: fra-pr.fusion-resources-app-pr strategy: runOnce: deploy: From a4555f46a6abb8d2343fe77cf95d24ed8baba322 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:29:09 +0200 Subject: [PATCH 44/55] Added dbTagPrefix to execute-sql-migration pr --- pipelines/summary-api-pr-pipeline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/pipelines/summary-api-pr-pipeline.yml b/pipelines/summary-api-pr-pipeline.yml index fc0388299..2a36d78d9 100644 --- a/pipelines/summary-api-pr-pipeline.yml +++ b/pipelines/summary-api-pr-pipeline.yml @@ -151,6 +151,7 @@ stages: artifact: 'k8s-deployment' environment: '$(envName)-$(prNumber)' azureSubscription: $(subscriptionService) + dbTagPrefix: 'summary' - task: KubernetesManifest@0 displayName: Deploy to Kubernetes cluster From 06bfa507ab9b930bd064463c41ada5f882178fd5 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:41:51 +0200 Subject: [PATCH 45/55] Trigger PR pipeline --- src/Fusion.Summary.Api/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 928dc4bb0..5f3858339 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -117,7 +117,7 @@ app.Run(); /// -/// For testing. +/// For testing /// public partial class Program { From baff765dc3bccf0cfaa0b9aaa1284e2b7686f7d5 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:47:51 +0200 Subject: [PATCH 46/55] AzurePowerShell@5 --- pipelines/summary-api-pr-pipeline.yml | 2 +- src/Fusion.Summary.Api/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines/summary-api-pr-pipeline.yml b/pipelines/summary-api-pr-pipeline.yml index 2a36d78d9..4179369fe 100644 --- a/pipelines/summary-api-pr-pipeline.yml +++ b/pipelines/summary-api-pr-pipeline.yml @@ -88,7 +88,7 @@ stages: steps: - template: templates/install-fusion-ps.yml - - task: AzurePowerShell@4 + - task: AzurePowerShell@5 displayName: 'Get secrets' inputs: azureSubscription: $(subscriptionService) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 5f3858339..928dc4bb0 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -117,7 +117,7 @@ app.Run(); /// -/// For testing +/// For testing. /// public partial class Program { From c602aac516cc87de161cc2aaa0aee1db225f89e1 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:58:23 +0200 Subject: [PATCH 47/55] Add migration.sql script to ArtifactStagingDirectory --- pipelines/summary-api-pr-pipeline.yml | 12 ++++++++++++ src/Fusion.Summary.Api/Program.cs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pipelines/summary-api-pr-pipeline.yml b/pipelines/summary-api-pr-pipeline.yml index 4179369fe..03007aa36 100644 --- a/pipelines/summary-api-pr-pipeline.yml +++ b/pipelines/summary-api-pr-pipeline.yml @@ -46,6 +46,7 @@ stages: inputs: command: login containerRegistry: fusioncachecr + - template: templates/docker-buildx.yml@infra parameters: repository: $(imageRepo) @@ -59,6 +60,17 @@ stages: tags: | $(prNumber) + - template: templates/docker-buildx.yml@infra + parameters: + initBuilderInstance: false + repository: '' + buildContext: ./src + dockerfile: src/Fusion.Summary.Api/Dockerfile + arguments: | + --target=export + --output=type=local,dest=$(Build.ArtifactStagingDirectory) + --cache-from=type=registry,ref=fusioncachecr.azurecr.io/$(imageRepo):$(prNumber) + - task: CopyFiles@2 displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)' inputs: diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 928dc4bb0..5f3858339 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -117,7 +117,7 @@ app.Run(); /// -/// For testing. +/// For testing /// public partial class Program { From 15e9ede0c1d53eca0d0f61248a85c28a19ecc20a Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:05:13 +0200 Subject: [PATCH 48/55] Print databaseConnectionString --- src/Fusion.Summary.Api/Program.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 5f3858339..3b19899b8 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -30,6 +30,10 @@ var fusionEnvironment = builder.Configuration["FUSION_ENVIRONMENT"]; var databaseConnectionString = builder.Configuration.GetConnectionString(nameof(SummaryDbContext))!; +// TESTING +Console.WriteLine(databaseConnectionString); +// TESTING + builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddHealthChecks() @@ -117,7 +121,7 @@ app.Run(); /// -/// For testing +/// For testing. /// public partial class Program { From 77ff989db98146588db456708bc69a52ac63f920 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:38:52 +0200 Subject: [PATCH 49/55] Use enablePullRequestEnv --- src/Fusion.Summary.Api/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 3b19899b8..9b1472ec2 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -76,7 +76,7 @@ }); builder.Services.AddApplicationInsightsTelemetry(); -builder.Services.AddSqlDbContext(databaseConnectionString, enablePullRequestEnv: false) +builder.Services.AddSqlDbContext(databaseConnectionString) .AddSqlTokenProvider() .AddAccessTokenSupport(); builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())); From e9fc6daf231c988254e84f3b6a7c9bcb0f1199b1 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:53:28 +0200 Subject: [PATCH 50/55] More testing --- .../Deployment/k8s/deployment-pr-env.yml | 2 -- src/Fusion.Summary.Api/Program.cs | 13 ++++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml b/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml index 37fc506b2..2f133913d 100644 --- a/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml +++ b/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml @@ -66,8 +66,6 @@ spec: value: "{{clientId}}" - name: BuildNr value: "{{buildNr}}" - - name: ConnectionStrings__SummaryDbContext - value: "{{dbConnectionString}}" args: - /server diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 9b1472ec2..9da909918 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -38,9 +38,8 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddHealthChecks() .AddCheck("liveness", () => HealthCheckResult.Healthy()) - .AddCheck("db", () => HealthCheckResult.Healthy(), tags: ["ready"]); -// TODO: Add a real health check, when database is added in deployment pipelines and PR pipelines -// .AddDbContextCheck("db", tags: new[] { "ready" }); + .AddCheck("db", () => HealthCheckResult.Healthy(), tags: ["ready"]) + .AddDbContextCheck("db", tags: new[] { "ready" }); builder.Services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) @@ -118,6 +117,14 @@ #endregion Health probes +// TESTING +using var scope = app.Services.CreateScope(); +var dbContext = scope.ServiceProvider.GetRequiredService(); +Console.WriteLine(dbContext.Database.GetConnectionString()); + +// TESTING + + app.Run(); /// From 01ae8c6b6fcee6d7c5209d8c3a76dbcdcda62581 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:58:28 +0200 Subject: [PATCH 51/55] Fixed typo --- src/Fusion.Summary.Api/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index 9da909918..d54e57e85 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -38,7 +38,6 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddHealthChecks() .AddCheck("liveness", () => HealthCheckResult.Healthy()) - .AddCheck("db", () => HealthCheckResult.Healthy(), tags: ["ready"]) .AddDbContextCheck("db", tags: new[] { "ready" }); builder.Services From 3667e45141e23648d5d000c677ac61dde26670ee Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 23 Aug 2024 08:48:43 +0200 Subject: [PATCH 52/55] Add PULL_REQUEST_ID env --- src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml | 2 ++ src/Fusion.Summary.Api/Program.cs | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml b/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml index 2f133913d..211f25610 100644 --- a/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml +++ b/src/Fusion.Summary.Api/Deployment/k8s/deployment-pr-env.yml @@ -66,6 +66,8 @@ spec: value: "{{clientId}}" - name: BuildNr value: "{{buildNr}}" + - name: PULL_REQUEST_ID + value: "{{prNumber}}" args: - /server diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index d54e57e85..fa0fcf5e0 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -30,10 +30,6 @@ var fusionEnvironment = builder.Configuration["FUSION_ENVIRONMENT"]; var databaseConnectionString = builder.Configuration.GetConnectionString(nameof(SummaryDbContext))!; -// TESTING -Console.WriteLine(databaseConnectionString); -// TESTING - builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddHealthChecks() @@ -116,7 +112,7 @@ #endregion Health probes -// TESTING +// TODO: TESTING using var scope = app.Services.CreateScope(); var dbContext = scope.ServiceProvider.GetRequiredService(); Console.WriteLine(dbContext.Database.GetConnectionString()); From 8a2a64fc35bd72e245100e08c339ae2073c03a62 Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Fri, 23 Aug 2024 08:57:17 +0200 Subject: [PATCH 53/55] Removed testing variables --- src/Fusion.Summary.Api/Program.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Fusion.Summary.Api/Program.cs b/src/Fusion.Summary.Api/Program.cs index fa0fcf5e0..4a7192148 100644 --- a/src/Fusion.Summary.Api/Program.cs +++ b/src/Fusion.Summary.Api/Program.cs @@ -112,14 +112,6 @@ #endregion Health probes -// TODO: TESTING -using var scope = app.Services.CreateScope(); -var dbContext = scope.ServiceProvider.GetRequiredService(); -Console.WriteLine(dbContext.Database.GetConnectionString()); - -// TESTING - - app.Run(); /// From 36d89719b08ad605d577cdbb16af3ffc30001f8d Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:06:31 +0200 Subject: [PATCH 54/55] Trigger resources PR pipeline --- src/backend/api/Fusion.Resources.Api/Startup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/api/Fusion.Resources.Api/Startup.cs b/src/backend/api/Fusion.Resources.Api/Startup.cs index 10b72aa24..e7b22b035 100644 --- a/src/backend/api/Fusion.Resources.Api/Startup.cs +++ b/src/backend/api/Fusion.Resources.Api/Startup.cs @@ -182,7 +182,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseDeveloperExceptionPage(); } - //app.UseMiddleware(); + //app.UseMiddleware(); app.UseMiddleware(); app.UseMiddleware(); From 3b449438c57356b677aee2a4df7d4e2e835f9b5e Mon Sep 17 00:00:00 2001 From: Jonathan Idland Olsnes <73334350+Jonathanio123@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:19:19 +0200 Subject: [PATCH 55/55] Fix missing dbTagPrefix from api-pr-pipeline.yml --- pipelines/api-pr-pipeline.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/pipelines/api-pr-pipeline.yml b/pipelines/api-pr-pipeline.yml index 8dcdd6720..6a241b576 100644 --- a/pipelines/api-pr-pipeline.yml +++ b/pipelines/api-pr-pipeline.yml @@ -160,6 +160,7 @@ stages: artifact: 'k8s-deployment' environment: '$(envName)-$(prNumber)' azureSubscription: $(subscriptionService) + dbTagPrefix: resources - task: KubernetesManifest@0