From 96a8ad6e019110a29c76db87637f01a1a90779b0 Mon Sep 17 00:00:00 2001 From: Wesley Camargo Date: Mon, 25 Jul 2022 14:44:30 +0200 Subject: [PATCH] dotnet Core deploy & example Added example for dotnet core apps with azure web apps --- .../appService/appService-deploy-jobs.yml | 76 ++++++++++++++----- .../appService/examples/azure-pipelines.yml | 3 +- .../dotnetCore/dotnetCore-build-jobs.yml | 5 +- .../dotnetCore/examples/azure-pipelines.yml | 11 ++- .../examples/variables/dev-vars.yml | 2 +- .../examples/variables/prd-vars.yml | 2 +- .../examples/variables/uat-vars.yml | 2 +- 7 files changed, 67 insertions(+), 34 deletions(-) diff --git a/src/cloud/azure/appService/appService-deploy-jobs.yml b/src/cloud/azure/appService/appService-deploy-jobs.yml index dd377c7..98bce53 100644 --- a/src/cloud/azure/appService/appService-deploy-jobs.yml +++ b/src/cloud/azure/appService/appService-deploy-jobs.yml @@ -10,7 +10,8 @@ jobs: - ${{ if and(eq(parameters.settings.deploy.infrastructure.enabled, 'true'), eq(parameters.resource.deploy.infrastructure.enabled, 'true')) }}: - - deployment: ${{ replace(parameters.resource.runName,'-','') }}iac + # - deployment: ${{ replace(parameters.resource.name,'-','') }}iac + - deployment: ${{ parameters.resource.name }}iac displayName: IaC - Azure App Service Deployment environment: ${{ parameters.environment }} dependsOn: resourceGroupDeploy @@ -29,30 +30,63 @@ jobs: templateLocation: 'Linked artifact' csmFile: '$(Pipeline.Workspace)/${{ parameters.resource.name }}/infrastructure/appService.json' overrideParameters: > - -servicePlanName ${{ parameters.resource.deploy.infrastructure.servicePlanName }} - -siteName ${{ parameters.resource.name }} + -servicePlanName ${{ parameters.resource.deploy.infrastructure.servicePlanName }} + -siteName ${{ parameters.resource.deploy.infrastructure.appServiceName }} deploymentMode: 'Incremental' deploymentOutputs: 'ArmOutputs' -# - ${{ if and(eq(parameters.settings.deploy.application.enabled, 'true'),eq(parameters.resource.deploy.application.enabled, 'true')) }}: -# - deployment: -# displayName: App - Azure App Service Deployment -# environment: ${{ parameters.environment }} -# ${{ if and(eq(parameters.settings.deploy.infrastructure.enabled, 'true'), eq(parameters.resource.deploy.infrastructure.enabled, 'true')) }}: -# dependsOn: ${{ replace(parameters.resource.runName,'-','') }}iac -# ${{ else }}: -# dependsOn: resourceGroupDeploy -# strategy: -# runOnce: -# deploy: -# steps: + - ${{ if and(eq(parameters.settings.deploy.application.enabled, 'true'),eq(parameters.resource.deploy.application.enabled, 'true')) }}: + - deployment: + displayName: App - Azure App Service Deployment + environment: ${{ parameters.environment }} + ${{ if and(eq(parameters.settings.deploy.infrastructure.enabled, 'true'), eq(parameters.resource.deploy.infrastructure.enabled, 'true')) }}: + dependsOn: ${{ parameters.resource.name }}iac + ${{ else }}: + dependsOn: resourceGroupDeploy + strategy: + runOnce: + deploy: + steps: + + - powershell: | + $timeoutMinutes = 2 + + $timeout = New-TimeSpan -Minutes $timeoutMinutes + $endTime = (Get-Date).Add($timeout) -# - ${{ if ne( parameters.resource.type, 'appService') }}: -# - task: AzureWebApp@1 -# inputs: -# azureSubscription: ${{ parameters.settings.azure.subscription.serviceConnection }} -# appName: ${{ parameters.resource.name }} -# package: $(Pipeline.Workspace)/${{ parameters.resource.runName }}/**/*.zip + do { + Start-Sleep -Seconds 10 + + Write-Host "##[command]Checking if App Service is available..." -ForegroundColor Blue + + $statusCode = $null + + try { + + $uri = "https://${{ parameters.resource.deploy.infrastructure.appServiceName }}.azurewebsites.net" + + $req = Invoke-WebRequest -Uri $uri + + if($null -ne $req.StatusCode){ + $statusCode = $req.StatusCode + } + Write-Output "Status Code -- $statusCode" + } catch {} + + $timeoutReached = ((Get-Date) -gt $endTime) + if ($timeoutReached) { + Write-Warning "Timeout reached" + return $false + } + } until ($statusCode -eq 200 -or $timeoutReached) + displayName: Waiting web app availability + + # - ${{ if ne( parameters.resource.type, 'appService') }}: + - task: AzureWebApp@1 + inputs: + azureSubscription: ${{ parameters.settings.azure.subscription.serviceConnection }} + appName: ${{ parameters.resource.deploy.infrastructure.appServiceName }} + package: $(Pipeline.Workspace)/${{ parameters.resource.name }}/**/*.zip # - deployment: # displayName: Azure App Service Deployment diff --git a/src/cloud/azure/appService/examples/azure-pipelines.yml b/src/cloud/azure/appService/examples/azure-pipelines.yml index 95f1553..15ed11c 100644 --- a/src/cloud/azure/appService/examples/azure-pipelines.yml +++ b/src/cloud/azure/appService/examples/azure-pipelines.yml @@ -45,12 +45,13 @@ extends: # - uat # - prd resources: - - name: example-appService-iac + - name: exampleAppService type: appService enabled: true deploy: infrastructure: enabled: true servicePlanName: $(servicePlanName) + appServiceName: $(appServiceName) application: enabled: false diff --git a/src/development/dotnetCore/dotnetCore-build-jobs.yml b/src/development/dotnetCore/dotnetCore-build-jobs.yml index a7ede30..618e614 100644 --- a/src/development/dotnetCore/dotnetCore-build-jobs.yml +++ b/src/development/dotnetCore/dotnetCore-build-jobs.yml @@ -13,7 +13,7 @@ jobs: - job: - displayName: App - ${{ parameters.resource.runName }} Build Job + displayName: App - ${{ parameters.resource.name }} Build Job variables: BuildPlatform: 'Any CPU' BuildConfiguration: 'Release' @@ -53,10 +53,9 @@ jobs: - template: ../../cloud/azure/bicep/bicep-build-tasks.yml parameters: resourceType: appService - # resource: ${{ parameters.resource }} - task: PublishPipelineArtifact@1 inputs: targetPath: '$(build.artifactstagingdirectory)' - artifact: ${{ parameters.resource.runName }} + artifact: ${{ parameters.resource.name }} publishLocation: 'pipeline' \ No newline at end of file diff --git a/src/development/dotnetCore/examples/azure-pipelines.yml b/src/development/dotnetCore/examples/azure-pipelines.yml index ed4787f..992bcf2 100644 --- a/src/development/dotnetCore/examples/azure-pipelines.yml +++ b/src/development/dotnetCore/examples/azure-pipelines.yml @@ -4,7 +4,7 @@ resources: type: github endpoint: devopsnights name: devopsnights/AzureDevOpsReleaseEngine - ref: refs/heads/feature/appService + ref: refs/heads/feature/dotnetCore trigger: branches: @@ -15,10 +15,9 @@ trigger: include: - src/development/dotnetCore/* - pool: - # vmImage: 'windows-latest' - name: default + vmImage: 'windows-latest' + # name: default extends: template: /src/main.yml@releaseEngine @@ -46,14 +45,14 @@ extends: - uat - prd resources: - - name: $(applicationName) + - name: exampleDotnetCore type: dotnetCore - runName: app-releaseengine enabled: true deploy: type: azureWebApp infrastructure: enabled: true servicePlanName: $(servicePlanName) + appServiceName: $(appServiceName) application: enabled: true diff --git a/src/development/dotnetCore/examples/variables/dev-vars.yml b/src/development/dotnetCore/examples/variables/dev-vars.yml index 436e7a7..02c1782 100644 --- a/src/development/dotnetCore/examples/variables/dev-vars.yml +++ b/src/development/dotnetCore/examples/variables/dev-vars.yml @@ -5,5 +5,5 @@ variables: resourceGroupName: rg-dotnetcore-releaseengine-dev servicePlanName: plan-dotnetcore-releaseengine-dev - applicationName: app-dotnetcore-releaseengine-dev + appServiceName: app-dotnetcore-releaseengine-dev \ No newline at end of file diff --git a/src/development/dotnetCore/examples/variables/prd-vars.yml b/src/development/dotnetCore/examples/variables/prd-vars.yml index bd066f7..5628d4a 100644 --- a/src/development/dotnetCore/examples/variables/prd-vars.yml +++ b/src/development/dotnetCore/examples/variables/prd-vars.yml @@ -5,4 +5,4 @@ variables: resourceGroupName: rg-dotnetcore-releaseengine-prd servicePlanName: plan-dotnetcore-releaseengine-prd - applicationName: app-dotnetcore-releaseengine-prd \ No newline at end of file + appServiceName: app-dotnetcore-releaseengine-prd \ No newline at end of file diff --git a/src/development/dotnetCore/examples/variables/uat-vars.yml b/src/development/dotnetCore/examples/variables/uat-vars.yml index 39bcb11..ced2cb6 100644 --- a/src/development/dotnetCore/examples/variables/uat-vars.yml +++ b/src/development/dotnetCore/examples/variables/uat-vars.yml @@ -5,4 +5,4 @@ variables: resourceGroupName: rg-dotnetcore-releaseengine-uat servicePlanName: plan-dotnetcore-releaseengine-uat - applicationName: app-dotnetcore-releaseengine-uat \ No newline at end of file + appServiceName: app-dotnetcore-releaseengine-uat \ No newline at end of file