From fdcdc0e7700637afe880d0f44236fe8db70ec053 Mon Sep 17 00:00:00 2001 From: Emanuele De Cupis Date: Mon, 7 Jun 2021 12:42:17 +0200 Subject: [PATCH 1/3] [#ipv-22] update pipelines --- .devops/code-review-pipelines.yml | 29 ++++++++++------------------- .devops/deploy-pipelines.yml | 9 ++------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/.devops/code-review-pipelines.yml b/.devops/code-review-pipelines.yml index 03c17ed0..49878805 100644 --- a/.devops/code-review-pipelines.yml +++ b/.devops/code-review-pipelines.yml @@ -6,14 +6,15 @@ # - DANGER_GITHUB_API_TOKEN # -variables: - NODE_VERSION: '10.14.1' - YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn - # Automatically triggered on PR # https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#pr-trigger trigger: none +# Execute agents (jobs) on latest Ubuntu version. +# To change OS for a specific, ovverride "pool" attribute inside the job definition +pool: + vmImage: 'ubuntu-latest' + resources: repositories: - repository: pagopaCommons @@ -22,20 +23,10 @@ resources: ref: refs/tags/v14 endpoint: 'io-azure-devops-github-ro' -# This pipeline has been implemented to be run on hosted agent pools based both -# on 'windows' and 'ubuntu' virtual machine images and using the scripts defined -# in the package.json file. Since we are deploying on Azure functions on Windows -# runtime, the pipeline is currently configured to use a Windows hosted image for -# the build and deploy. -pool: - vmImage: 'ubuntu-latest' - stages: - # A) Build and code validation - stage: Build dependsOn: [] jobs: - # A1) Checkout, install module and build code - job: make_build pool: # As we deploy on Wondows machines, we use Windows to build @@ -45,15 +36,13 @@ stages: - script: | yarn build displayName: 'Build' - + - stage: Static_analysis dependsOn: [] jobs: - - job: lint steps: - template: templates/node-job-setup/template.yaml@pagopaCommons - - script: | yarn lint displayName: 'Lint' @@ -91,16 +80,18 @@ stages: DANGER_GITHUB_API_TOKEN: '$(DANGER_GITHUB_API_TOKEN)' displayName: 'Danger CI' + + # B) Run unit tests if there is a push or pull request on any branch. - stage: Test dependsOn: [] jobs: - job: unit_tests steps: - template: templates/node-job-setup/template.yaml@pagopaCommons - + - script: | yarn generate - displayName: 'Generate defintions' + displayName: 'Generate definitions' - script: | yarn test:coverage diff --git a/.devops/deploy-pipelines.yml b/.devops/deploy-pipelines.yml index fba136e7..00bcf124 100644 --- a/.devops/deploy-pipelines.yml +++ b/.devops/deploy-pipelines.yml @@ -1,9 +1,5 @@ # Azure DevOps pipeline to release a new version and deploy to production. -variables: - NODE_VERSION: '10.14.1' - YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn - parameters: - name: 'RELEASE_SEMVER' displayName: 'When packing a release, define the version bump to apply' @@ -73,6 +69,7 @@ stages: echo "We assume this reference to be a valid release: $(Build.SourceBranch). Therefore, there is no need to bundle a new release." displayName: 'Skip release bundle' + # Prepare Artifact - stage: Deploy_staging dependsOn: @@ -139,12 +136,11 @@ stages: jobs: - job: 'do_healthcheck' steps: - - checkout: none - template: templates/rest-healthcheck/template.yaml@pagopaCommons parameters: azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' appName: '$(PRODUCTION_APP_NAME)' - endpoint: 'https://$(PRODUCTION_APP_NAME)-staging.azurewebsites.net/api/info' + endpoint: 'https://$(PRODUCTION_APP_NAME)-staging.azurewebsites.net/api/v1/info' endpointType: 'private' containerInstanceResourceGroup: 'io-p-rg-common' containerInstanceVNet: 'io-p-vnet-common' @@ -158,7 +154,6 @@ stages: jobs: - job: 'do_deploy' steps: - - checkout: none - task: AzureAppServiceManage@0 inputs: azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' From eb52ce9b66df883fc2249b0a9e5b21b1bc9a210c Mon Sep 17 00:00:00 2001 From: Emanuele De Cupis Date: Mon, 7 Jun 2021 12:54:16 +0200 Subject: [PATCH 2/3] [#ipv-22] allow multiple app services to be deployed at once --- .devops/deploy-pipelines.yml | 142 +++++++++++++++++++++++------------ 1 file changed, 94 insertions(+), 48 deletions(-) diff --git a/.devops/deploy-pipelines.yml b/.devops/deploy-pipelines.yml index 00bcf124..62e962b4 100644 --- a/.devops/deploy-pipelines.yml +++ b/.devops/deploy-pipelines.yml @@ -1,5 +1,12 @@ # Azure DevOps pipeline to release a new version and deploy to production. +variables: + # Configuration to run the healthcheck container + HEALTHCHECK_CONTAINER_RG: 'io-p-rg-common' + HEALTHCHECK_CONTAINER_VNET: 'io-p-vnet-common' + HEALTHCHECK_CONTAINER_SUBNET: 'azure-devops' + HEALTHCHECK_PATH: 'api/v1/info' + parameters: - name: 'RELEASE_SEMVER' displayName: 'When packing a release, define the version bump to apply' @@ -9,6 +16,20 @@ parameters: - minor - patch default: minor + # Map of production apps to deploy to, in the form + # {logicName}: + # appname: {name of the resource} + # rg: {name of the resource group} + # Although it's a parameter, it's not intended to be edited at runtime. + # It's here because variables only handle scalar values + - name: 'PRODUCTION_APPS' + displayName: '' + type: object + default: + services: + appname: io-p-fn3-services + rg: io-p-rg-functions_services + # Only manual activations are intended trigger: none @@ -27,7 +48,7 @@ resources: - repository: pagopaCommons type: github name: pagopa/azure-pipeline-templates - ref: refs/tags/v14 + ref: refs/tags/v10 endpoint: 'io-azure-devops-github-ro' stages: @@ -71,11 +92,11 @@ stages: # Prepare Artifact - - stage: Deploy_staging + - stage: Prepare_artifact dependsOn: - Release jobs: - - job: 'prepare_artifact_and_deploy' + - job: 'prepare_artifact' steps: # Build application - template: templates/node-job-setup/template.yaml@pagopaCommons @@ -99,15 +120,14 @@ stages: - task: CopyFiles@2 inputs: SourceFolder: '$(System.DefaultWorkingDirectory)' - TargetFolder: '$(Build.ArtifactStagingDirectory)' + TargetFolder: '$(System.DefaultWorkingDirectory)/bundle' Contents: | **/* !.git/**/* !**/*.js.map !**/*.ts !.vscode/**/* - !azure-templates/**/* - !azure-pipelines.yml + !.devops/**/* !.prettierrc !.gitignore !README.md @@ -115,54 +135,80 @@ stages: !local.settings.json !test !tsconfig.json + !tslint.json + !yarn.lock + !Dangerfile.js + !CODEOWNERS + !__*/**/* displayName: 'Copy deploy files' + + - publish: $(System.DefaultWorkingDirectory)/bundle + artifact: Bundle + + # Deploy on staging slot + - ${{ each app in parameters.PRODUCTION_APPS }}: + - stage: Deploy_${{ app.Key }}_to_staging + dependsOn: + - Prepare_artifact + jobs: + - job: 'do_deploy_${{ app.Key }}' + steps: + - checkout: none + - download: current + artifact: Bundle - - task: AzureFunctionApp@1 - inputs: - azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' - resourceGroupName: '$(PRODUCTION_RESOURCE_GROUP_NAME)' - appType: 'functionApp' - appName: '$(PRODUCTION_APP_NAME)' - package: '$(Build.ArtifactStagingDirectory)/' - deploymentMethod: 'auto' - deployToSlotOrASE: true - slotName: 'staging' - displayName: Deploy to staging slot + - task: AzureFunctionApp@1 + inputs: + azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' + resourceGroupName: '${{ app.Value.rg }}' + appType: 'functionApp' + appName: '${{ app.Value.appname }}' + package: '$(Pipeline.Workspace)/Bundle' + deploymentMethod: 'auto' + deployToSlotOrASE: true + slotName: 'staging' + displayName: Deploy to staging slot # Check that the staging instance is healthy - - stage: Healthcheck - dependsOn: - - Deploy_staging - jobs: - - job: 'do_healthcheck' - steps: - - template: templates/rest-healthcheck/template.yaml@pagopaCommons - parameters: - azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' - appName: '$(PRODUCTION_APP_NAME)' - endpoint: 'https://$(PRODUCTION_APP_NAME)-staging.azurewebsites.net/api/v1/info' - endpointType: 'private' - containerInstanceResourceGroup: 'io-p-rg-common' - containerInstanceVNet: 'io-p-vnet-common' - containerInstanceSubnet: 'azure-devops' + - ${{ each app in parameters.PRODUCTION_APPS }}: + - stage: Healthcheck_${{ app.Key }} + dependsOn: + - Deploy_${{ app.Key }}_to_staging + jobs: + - job: 'do_healthcheck_${{ app.Key }}' + steps: + - checkout: none + - template: templates/rest-healthcheck/template.yaml@pagopaCommons + parameters: + azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' + appName: '${{ app.Value.appname }}' + endpoint: 'https://${{ app.Value.appname }}-staging.azurewebsites.net/$(HEALTHCHECK_PATH)' + endpointType: 'private' + containerInstanceResourceGroup: '$(HEALTHCHECK_CONTAINER_RG)' + containerInstanceVNet: '$(HEALTHCHECK_CONTAINER_VNET)' + containerInstanceSubnet: '$(HEALTHCHECK_CONTAINER_SUBNET)' # Promote the staging instance to production - - stage: Deploy_production - dependsOn: - - Healthcheck - - Deploy_staging - jobs: - - job: 'do_deploy' - steps: - - task: AzureAppServiceManage@0 - inputs: - azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' - resourceGroupName: '$(PRODUCTION_RESOURCE_GROUP_NAME)' - webAppName: '$(PRODUCTION_APP_NAME)' - sourceSlot: staging - swapWithProduction: true - displayName: Swap with production slot - + - ${{ each app in parameters.PRODUCTION_APPS }}: + - stage: Swap_${{ app.Key }}_to_production + dependsOn: + - Deploy_${{ app.Key }}_to_staging + # Wait for every healthcheck to succeed + # This implied that no app is swapped to prod if at least one healthcheck fails + - ${{ each appInner in parameters.PRODUCTION_APPS }}: + - Healthcheck_${{ appInner.Key }} + jobs: + - job: 'do_deploy_${{ app.Key }}' + steps: + - checkout: none + - task: AzureAppServiceManage@0 + inputs: + azureSubscription: '$(PRODUCTION_AZURE_SUBSCRIPTION)' + resourceGroupName: '${{ app.Value.rg }}' + webAppName: '${{ app.Value.appname }}' + sourceSlot: staging + swapWithProduction: true + displayName: Swap with production slot # Publish client SDK to NPM - stage: PublishClientSDKtoNPM From ac369d8b7b1456d3e5dc2c57fa691ba26196a87e Mon Sep 17 00:00:00 2001 From: Emanuele De Cupis Date: Mon, 7 Jun 2021 13:59:24 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- .devops/deploy-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devops/deploy-pipelines.yml b/.devops/deploy-pipelines.yml index 62e962b4..ef7104ab 100644 --- a/.devops/deploy-pipelines.yml +++ b/.devops/deploy-pipelines.yml @@ -48,7 +48,7 @@ resources: - repository: pagopaCommons type: github name: pagopa/azure-pipeline-templates - ref: refs/tags/v10 + ref: refs/tags/v14 endpoint: 'io-azure-devops-github-ro' stages: