-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
179 lines (160 loc) · 6 KB
/
azure-pipelines.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
trigger:
branches:
include:
- '*'
paths:
include:
- '*'
variables:
MAJOR_VERSION: 0
MINOR_VERSION: 0
PATCH_VERSION: 1
name: $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION).$(Rev:r)
stages:
- stage: SetBuildNumber
displayName: 'Set build number'
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: SetBuildNumber
displayName: 'Set build number'
steps:
- checkout: none
- task: PowerShell@2
displayName: Set build number
inputs:
targetType: 'inline'
script: |
$branchName = "$(Build.SourceBranchName)";
$buildTrigger = "$(Build.Reason)";
$buildVersion = "$(Build.BuildNumber)";
Write-Host "Branch name: $branchName";
Write-Host "Build trigger: $buildTrigger";
Write-Host "Build version: $buildVersion";
if (-not($buildVersion.Contains($branchName) -or $buildVersion.Contains($buildTrigger))) {
$nugetPkgVersion = $buildVersion;
if (-not([string]::IsNullOrWhiteSpace($branchName)) -and ($branchName -ne "main")) {
$nugetPkgVersion = "$nugetPkgVersion-$branchName";
}
Write-Host "Package version: $nugetPkgVersion";
Write-Host "##vso[build.updateBuildNumber]$nugetPkgVersion";
}
else {
Write-Host "Package version: $buildVersion";
}
- stage: OrderApi
displayName: 'CI/CD: Order API'
dependsOn: SetBuildNumber
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: BuildOrderApi
displayName: 'CI: Order API'
steps:
- task: Docker@2
displayName: 'Docker login'
inputs:
containerRegistry: 'Dapr Container Registry'
command: 'login'
- task: Docker@2
displayName: 'Docker build'
inputs:
containerRegistry: 'Dapr Container Registry'
repository: 'dapr-demo/order-api'
command: 'build'
Dockerfile: '$(Build.SourcesDirectory)/src/OrderApi/Dockerfile'
buildContext: '$(Build.SourcesDirectory)/src'
tags: '$(Build.BuildNumber)'
- task: Docker@2
displayName: 'Docker push'
inputs:
containerRegistry: 'Dapr Container Registry'
repository: 'dapr-demo/order-api'
command: 'push'
tags: '$(Build.BuildNumber)'
- task: Bash@3
displayName: 'Tag latest'
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
inputs:
targetType: 'inline'
script: 'docker tag daprcontainerappsregistry12345.azurecr.io/dapr-demo/order-api:$(Build.BuildNumber) daprcontainerappsregistry12345.azurecr.io/dapr-demo/order-api:latest'
- task: Docker@2
displayName: 'Docker push latest'
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
inputs:
containerRegistry: 'Dapr Container Registry'
repository: 'dapr-demo/order-api'
command: 'push'
tags: 'latest'
- job: DeployOrderApi
displayName: 'CD: Order API'
dependsOn: BuildOrderApi
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
steps:
- checkout: none
- task: AzureContainerApps@0
displayName: 'Deploy container app revision'
inputs:
azureSubscription: 'Free Trial(85e5b8d9-d15f-4db3-bfaf-c97182b7cc0b)'
acrName: 'daprcontainerappsregistry12345'
containerAppName: 'dapr-demo-order-api'
resourceGroup: 'dapr-container-apps-environment'
imageToDeploy: 'daprcontainerappsregistry12345.azurecr.io/dapr-demo/order-api:$(Build.BuildNumber)'
- stage: GarbageCollector
displayName: 'CI/CD: Garbage Collector'
dependsOn: SetBuildNumber
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: BuildOrderGarbageCollector
displayName: 'CI: Garbage Collector'
steps:
- task: Docker@2
displayName: 'Docker login'
inputs:
containerRegistry: 'Dapr Container Registry'
command: 'login'
- task: Docker@2
displayName: 'Docker build'
inputs:
containerRegistry: 'Dapr Container Registry'
repository: 'dapr-demo/garbage-collector'
command: 'build'
Dockerfile: '$(Build.SourcesDirectory)/src/GarbageCollector/Dockerfile'
buildContext: '$(Build.SourcesDirectory)/src'
tags: '$(Build.BuildNumber)'
- task: Docker@2
displayName: 'Docker push'
inputs:
containerRegistry: 'Dapr Container Registry'
repository: 'dapr-demo/garbage-collector'
command: 'push'
tags: '$(Build.BuildNumber)'
- task: Bash@3
displayName: 'Tag latest'
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
inputs:
targetType: 'inline'
script: 'docker tag daprcontainerappsregistry12345.azurecr.io/dapr-demo/garbage-collector:$(Build.BuildNumber) daprcontainerappsregistry12345.azurecr.io/dapr-demo/garbage-collector:latest'
- task: Docker@2
displayName: 'Docker push latest'
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
inputs:
containerRegistry: 'Dapr Container Registry'
repository: 'dapr-demo/garbage-collector'
command: 'push'
tags: 'latest'
- job: DeployGarbageCollector
displayName: 'CD: Garbage Collector'
dependsOn: BuildOrderGarbageCollector
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
steps:
- checkout: none
- task: AzureContainerApps@0
displayName: 'Deploy container app revision'
inputs:
azureSubscription: 'Free Trial(85e5b8d9-d15f-4db3-bfaf-c97182b7cc0b)'
acrName: 'daprcontainerappsregistry12345'
containerAppName: 'dapr-demo-garbage-collector'
resourceGroup: 'dapr-container-apps-environment'
imageToDeploy: 'daprcontainerappsregistry12345.azurecr.io/dapr-demo/garbage-collector:$(Build.BuildNumber)'