|
| 1 | +parameters: |
| 2 | + - name: appName |
| 3 | + type: string |
| 4 | + - name: resourceGroup |
| 5 | + type: string |
| 6 | + - name: appDir |
| 7 | + type: string |
| 8 | + |
| 9 | +steps: |
| 10 | + - checkout: self |
| 11 | + |
| 12 | + - task: AzureCLI@2 |
| 13 | + displayName: 'Create Resource Group' |
| 14 | + inputs: |
| 15 | + azureSubscription: '$(serviceConnection)' |
| 16 | + scriptType: 'bash' |
| 17 | + scriptLocation: 'inlineScript' |
| 18 | + inlineScript: | |
| 19 | + az group create --name ${{ parameters.resourceGroup }} --location $(location) |
| 20 | +
|
| 21 | + - task: AzureCLI@2 |
| 22 | + displayName: 'Deploy Infrastructure' |
| 23 | + name: infra |
| 24 | + inputs: |
| 25 | + azureSubscription: '$(serviceConnection)' |
| 26 | + scriptType: 'bash' |
| 27 | + scriptLocation: 'inlineScript' |
| 28 | + inlineScript: | |
| 29 | + outputs=$(az deployment group create \ |
| 30 | + --resource-group ${{ parameters.resourceGroup }} \ |
| 31 | + --template-file ${{ parameters.appDir }}/infra/main.bicep \ |
| 32 | + --parameters appName=${{ parameters.appName }} \ |
| 33 | + --query 'properties.outputs' -o json) |
| 34 | + acrName=$(echo $outputs | jq -r '.acrName.value') |
| 35 | + appServiceName=$(echo $outputs | jq -r '.appServiceName.value') |
| 36 | + echo "##vso[task.setvariable variable=acrName;isoutput=true]$acrName" |
| 37 | + echo "##vso[task.setvariable variable=appServiceName;isoutput=true]$appServiceName" |
| 38 | +
|
| 39 | + - task: AzureCLI@2 |
| 40 | + displayName: 'Build and Push to ACR' |
| 41 | + inputs: |
| 42 | + azureSubscription: '$(serviceConnection)' |
| 43 | + scriptType: 'bash' |
| 44 | + scriptLocation: 'inlineScript' |
| 45 | + inlineScript: | |
| 46 | + az acr build \ |
| 47 | + --registry $(infra.acrName) \ |
| 48 | + --image ${{ parameters.appName }}:$(Build.BuildId) \ |
| 49 | + --image ${{ parameters.appName }}:latest \ |
| 50 | + ${{ parameters.appDir }} |
| 51 | +
|
| 52 | + - task: AzureCLI@2 |
| 53 | + displayName: 'Deploy to Web App for Containers' |
| 54 | + inputs: |
| 55 | + azureSubscription: '$(serviceConnection)' |
| 56 | + scriptType: 'bash' |
| 57 | + scriptLocation: 'inlineScript' |
| 58 | + inlineScript: | |
| 59 | + az webapp config container set \ |
| 60 | + --name $(infra.appServiceName) \ |
| 61 | + --resource-group ${{ parameters.resourceGroup }} \ |
| 62 | + --container-image-name $(infra.acrName).azurecr.io/${{ parameters.appName }}:$(Build.BuildId) |
| 63 | +
|
| 64 | + - task: AzureCLI@2 |
| 65 | + displayName: 'Health Check' |
| 66 | + inputs: |
| 67 | + azureSubscription: '$(serviceConnection)' |
| 68 | + scriptType: 'bash' |
| 69 | + scriptLocation: 'inlineScript' |
| 70 | + inlineScript: | |
| 71 | + APP_URL=$(az webapp show -g ${{ parameters.resourceGroup }} -n $(infra.appServiceName) --query defaultHostName -o tsv) |
| 72 | + sleep 30 |
| 73 | + curl -sf --retry 5 --retry-delay 10 "https://$APP_URL" || exit 1 |
| 74 | + echo "✅ ${{ parameters.appName }} deployed to https://$APP_URL" |
0 commit comments