-
Notifications
You must be signed in to change notification settings - Fork 11
/
azure-pipelines.yml
172 lines (160 loc) · 5.74 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
# Deploy to Azure Kubernetes Service
# Build and push image to Azure Container Registry; Deploy to Azure Kubernetes Service
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
- group: EPlast
# Container registry service connection established during pipeline creation
- name: dockerRegistryServiceConnection
# value: '5aab2e73-307d-46b2-8421-8ac50de15018'
value: '88435167-4a39-4ca0-9290-a2ef27d3ff17'
# value: 'a4044132-4df5-4427-8b71-97bb4e8a3dda'
- name: imageRepository
value: 'eplastapi'
- name: containerRegistry
value: 'eplast.azurecr.io'
- name: dockerfilePath
value: '**/Dockerfile'
- name: tag
value: '$(Build.BuildId)'
- name: imagePullSecret
# value: 'eplast1348122b-auth'
value: 'azdev-sa-3a5f0b-token-rqwl2'
# Agent VM image name
- name: vmImageName
value: 'ubuntu-latest'
# Name of the new namespace being created to deploy the PR changes.
- name: k8sNamespaceForPR
value: 'review-app-$(System.PullRequest.PullRequestId)'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build
inputs:
command: build
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
repository: $(imageRepository)
tags: |
$(tag)
arguments: --build-arg ASPNETCORE_ENVIRONMENT=$(Aspnetcore_Environment)
- upload: manifests
artifact: manifests
- task: Docker@2
displayName: Push
inputs:
command: push
containerRegistry: $(dockerRegistryServiceConnection)
repository: $(imageRepository)
tags: |
$(tag)
- upload: manifests
artifact: manifests
- stage: Test
displayName: Test stage
dependsOn: []
jobs:
- job: Test
displayName: Test
pool:
vmImage: 'windows-2022'
steps:
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
projects: 'EPlast/EPlast.sln'
- task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: sonarcloud
organization: 'ita-social-projects'
projectKey: 'ita-social-projects-eplast'
projectName: 'EPlast '
extraProperties: |
sonar.inclusions= EPlast/EPlast.BLL/Services/**, EPlast/EPlast.WebApi/Controllers/**, EPlast/EPlast.BLL/Handlers/**
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Build.SourcesDirectory)/**/*.trx
- task: DotNetCoreCLI@2
displayName: Build
inputs:
projects: 'EPlast/EPlast.sln'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'Add package coverlet.msbuild'
inputs:
command: custom
projects: |
EPlast/EPlast.XUnitTest/EPlast.XUnitTest.csproj
EPlast/EPlast.Tests/EPlast.Tests.csproj
custom: add
arguments: 'package coverlet.msbuild'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: |
EPlast/EPlast.XUnitTest/EPlast.XUnitTest.csproj
EPlast/EPlast.Tests/EPlast.Tests.csproj
arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[EPlast.WebApi]*Controllers*%2c[EPlast.BLL]*Services*%2c[EPlast.BLL]*Handlers*" /p:Exclude="[EPlast.XUnitTest]*%2c[EPlast.Tests]*" --logger trx'
publishTestResults: false
- task: SonarSource.sonarcloud.ce096e50-6155-4de8-8800-4221aaeed4a1.SonarCloudAnalyze@1
displayName: 'Run Code Analysis'
- task: SonarSource.sonarcloud.38b27399-a642-40af-bb7d-9971f69712e8.SonarCloudPublish@1
displayName: 'Publish Quality Gate Result'
- stage: Deploy
displayName: Deploy stage
dependsOn:
- Build
- Test
jobs:
- deployment: Deploy
condition: and(succeeded(), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/')))
displayName: Deploy
pool:
vmImage: $(vmImageName)
environment: 'EPlast.eplast'
strategy:
runOnce:
deploy:
steps:
- task: qetza.replacetokens.replacetokens-task.replacetokens@3
displayName: Replace tokens in **/*
inputs:
rootDirectory: $(Pipeline.Workspace)/manifests
targetFiles: '**/*.yml'
keepToken: true
tokenPrefix: ___
tokenSuffix: ___
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
kubernetesServiceConnection: 'EPlast-eplast-ServiceConnection'
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
kubernetesServiceConnection: 'EPlast-eplast-ServiceConnection'
manifests: |
$(Pipeline.Workspace)/manifests/test/deployment.yml
$(Pipeline.Workspace)/manifests/test/service.yml
$(Pipeline.Workspace)/manifests/test/ingress-prod.yml
$(Pipeline.Workspace)/manifests/test/redis-master-deployment.yaml
$(Pipeline.Workspace)/manifests/test/redis-master-service.yaml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository):$(tag)