forked from MicrosoftLearning/eShopOnWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eshoponweb-cd-webapp-dockercompose.yml
83 lines (76 loc) · 2.9 KB
/
eshoponweb-cd-webapp-dockercompose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#NOT WORKING YET
#NAME THE PIPELINE SAME AS FILE (WITHOUT ".yml")
#locally docker compose works, deploying to Azure WebApp is succesful but something still fails
# trigger: none
resources:
repositories:
- repository: self
trigger: none
variables:
tag: '$(Build.BuildId)'
resource-group: 'AZ400-EWebShop-NAME'
location: 'centralus'
templateFile: '.ado/IaC/app-plan.bicep'
subscriptionid: 'YOUR-SUBSCRIPTION-ID'
azureserviceconnection: 'azure subs'
webappname: 'az400-webapp-compose-NAME'
composeFile: 'docker-compose-webapp.yml'
acr-login-server: 'YOUR-ACR.azurecr.io'
acr-username: 'YOUR-ACR'
stages:
- stage: Deploy
displayName: Docker Compose to WebApp
jobs:
- job: Deploy
pool:
vmImage: ubuntu-latest
steps:
# Deploy App Service Plan using Bicep
- task: AzureResourceManagerTemplateDeployment@3
displayName: Deploy App Service Plan Bicep
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: $(azureserviceconnection)
subscriptionId: $(subscriptionid)
action: 'Create Or Update Resource Group'
resourceGroupName: '$(resource-group)'
location: '$(location)'
templateLocation: 'Linked artifact'
csmFile: '$(templateFile)'
deploymentMode: 'Incremental'
deploymentOutputs: 'asp-json'
#Parse App Service Plan variable
- task: PowerShell@2
displayName: Parse Bicep Output
inputs:
targetType: 'inline'
script: |
$var=ConvertFrom-Json '$(asp-json)'
$value=$var.asplan.value
Write-Host "##vso[task.setvariable variable=appserviceplan;]$value"
echo $appserviceplan
#Replace tokens in Docker Compose file
- task: qetza.replacetokens.replacetokens-task.replacetokens@3
inputs:
targetFiles: 'docker-compose-webapp.yml'
encoding: 'auto'
writeBOM: true
actionOnMissing: 'warn'
keepToken: false
actionOnNoFiles: 'continue'
enableTransforms: false
tokenPrefix: '__'
tokenSuffix: '__'
enableRecursion: false
useLegacyPattern: false
enableTelemetry: true
#Docker Login into private ACR (TODO alternative, using Docker task and docker ADO Service Connection)
#Deploy using Docker Compose
- task: AzureCLI@2
inputs:
azureSubscription: '$(azureserviceconnection)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp create --resource-group $(resource-group) --plan $(appserviceplan) --name $(webappname) --multicontainer-config-type compose --multicontainer-config-file $(composeFile)
az webapp config container set --resource-group $(resource-group) --name $(webappname) --docker-registry-server-user $(acr-username) --docker-registry-server-password $(acr-secret) --docker-registry-server-url https://$(acr-login-server)