-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-pipeline.yaml
178 lines (158 loc) · 4.44 KB
/
demo-pipeline.yaml
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
####
#
# Azure Pipeline for Todo API Server
#
# Displays usage of the Anchore integration with Azure DevOps
#
#####
trigger:
- master
- dev
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
- name: acrDcarServiceConnection
value: dcar
- name: acrProdServiceConnection
value: demoProduction
- name: prodRegistry
value: 'anchoredemo.azurecr.io'
- name: acrStagingServiceConnection
value: demoStaging
- name: stagingRegistry
value: 'demostaging.azurecr.io'
- name: imageRepository
value: 'todoapi'
- name: dockerfilePath
value: 'Dockerfile'
- name: tag
value: '$(Build.BuildId)'
- name: prodImage
value: '$(prodRegistry)/$(imageRepository)'
# Agent VM image name
- name: vmImageName
value: 'ubuntu-latest'
# Anchore stuff
- name: anchoreUser
value: 'admin'
- name: anchoreUrl
value: 'http://23.100.36.77/v1/'
- group: AnchoreCreds
# anchorepass ^
- name: k8sImagePullSecret
value: 'demo-pull-secret'
- name: clusterName
value: 'demo'
- name: namespace
value: 'todoapi'
stages:
- stage: Staging
displayName: Build and push to staging registry
jobs:
- job: Staging
displayName: Staging
pool:
name: 'Default'
# vmImage: $(vmImageName)
steps:
- script: |
cp /home/agent/golang/go1.14.3.linux-amd64.tar.gz $(Build.SourcesDirectory)
displayName: Copy golang tarball
- task: Docker@2
displayName: Login to the \"DCAR\"
inputs:
command: login
containerRegistry: $(acrDcarServiceConnection)
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(acrStagingServiceConnection)
tags: |
$(tag)
- stage: Scan
displayName: Scan the staged image
dependsOn: Staging
jobs:
- job: Scan
displayName: Scan
pool:
name: 'Default'
steps:
- task: AnchoreEnterprise@0
inputs:
image: '$(stagingRegistry)/$(imageRepository):$(tag)'
url: $(anchoreUrl)
username: $(anchoreUser)
password: $(anchorepass)
dockerfile: Dockerfile
- stage: Production
displayName: Push to production registry
dependsOn: Scan
jobs:
- job: Production
displayName: Production
pool:
name: 'Default'
# vmImage: $(vmImageName)
steps:
- script: |
cp /home/agent/golang/go1.14.3.linux-amd64.tar.gz $(Build.SourcesDirectory)
displayName: Copy golang tarball
- task: Docker@2
displayName: Login to the \"DCAR\"
inputs:
command: login
containerRegistry: $(acrDcarServiceConnection)
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(acrProdServiceConnection)
tags: |
$(tag)
- task: PublishPipelineArtifact@1
inputs:
artifactName: 'manifests'
path: 'manifests'
- stage: Deploy
displayName: Deploy to AKS
dependsOn: Production
jobs:
- deployment: Deploy
displayName: Deploy to AKS
environment: $(clusterName).todoapi
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact@2
inputs:
artifactName: 'manifests'
downloadPath: '$(System.ArtifactsDirectory)/manifests'
- task: KubernetesManifest@0
displayName: Create secret to pull image
inputs:
action: createSecret
secretName: $(k8sImagePullSecret)
dockerRegistryEndpoint: $(acrProdServiceConnection)
kubernetesServiceConnection: $(clusterName)
- task: KubernetesManifest@0
displayName: Deploy to AKS
inputs:
action: deploy
namespace: $(namespace)
manifests: |
$(System.ArtifactsDirectory)/manifests/deploy.yaml
$(System.ArtifactsDirectory)/manifests/svc.yaml
$(System.ArtifactsDirectory)/manifests/pvc.yaml
imagePullSecrets: |
$(k8sImagePullSecret)
containers: |
$(prodImage):$(tag)
kubernetesServiceConnection: $(clusterName)