-
Notifications
You must be signed in to change notification settings - Fork 195
/
azure-pipelines.yaml
335 lines (330 loc) · 15.8 KB
/
azure-pipelines.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
branches:
include:
- master
tags:
include:
- v*
pool:
vmImage: 'ubuntu-latest'
variables:
imageName: 'f5networks/k8s-bigip-ctlr-devel'
quayConnection: 'quay-bot'
redhatConnection: 'redhat-bot'
dockerConnection: 'docker-bot'
scanConnection: 'cis-scan-bot'
quay_path: 'quay.io/f5networks/k8s-bigip-ctlr-devel'
redhat_prj_name: 'cntr-ingress-svcs'
docker_repo: 'f5networks/k8s-bigip-ctlr'
chartPath: 'incubator'
chartRepoName: 'k8s-bigip-ctlr'
chartOrganization: F5Networks
helmVersion: 'v3.6.3'
chartsUpdated: False
operatorUpdated: False
operatorImageName: 'f5networks/f5-cis-operator-devel'
operatorBundleImageName: 'f5networks/f5-cis-operator-bundle-devel'
operatorIndexImage: 'f5networks/f5-cis-operator-index-devel'
goVersion: 1.22.7
stages:
- stage: VerifyFormatting
dependsOn: []
jobs:
- job: VerifyFormatting
steps:
- task: GoTool@0
inputs:
version: $(goVersion)
displayName: Install Go
- task: CmdLine@2
displayName: Check Go format and Suspicious constructs
inputs:
script: 'make verify'
- stage: RunUnitTests
dependsOn: []
jobs:
- job: RunUnitTests
steps:
- task: CmdLine@2
displayName: Check for unit tests
inputs:
script: |
docker run -t -v $(System.DefaultWorkingDirectory):/go/src/github.com/F5Networks/k8s-bigip-ctlr -w /go/src/github.com/F5Networks/k8s-bigip-ctlr --rm golang:$(goVersion) make test
- task: PublishTestResults@2
displayName: Publish Test Results
inputs:
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
- stage: RunCoverage
dependsOn: []
jobs:
- job: RunCoverage
steps:
- task: CmdLine@2
displayName: Check for Coverage
inputs:
script: |
docker run -t -v $(System.DefaultWorkingDirectory):/go/src/github.com/F5Networks/k8s-bigip-ctlr -w /go/src/github.com/F5Networks/k8s-bigip-ctlr --rm golang:$(goVersion) make coverage
mkdir -p $(System.DefaultWorkingDirectory)/coverage
cp -r coverage.html $(System.DefaultWorkingDirectory)/coverage
- stage: CheckDocumentation
dependsOn: []
jobs:
- job: CheckDocumentation
steps:
- task: CmdLine@2
displayName: Check documentation
inputs:
script: 'make docs'
- stage: ContainerImage
dependsOn:
- VerifyFormatting
- RunUnitTests
- RunCoverage
jobs:
- job: BuildContainerImage
steps:
- script: |
FILE_VALUE=$(cat next-version.txt)
echo "##vso[task.setvariable variable=BUILD_VERSION]$FILE_VALUE"
displayName: Set CIS Version
- script: echo $(BUILD_VERSION)
displayName: 'Display the variable value'
- task: Docker@2
displayName: Login to redhat registry
inputs:
command: login
containerRegistry: $(redhatConnection)
- task: Docker@2
displayName: Login to quay registry
inputs:
command: login
containerRegistry: $(quayConnection)
- task: Docker@2
displayName: Login to docker registry
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
inputs:
command: login
containerRegistry: $(dockerConnection)
- task: Docker@2
displayName: Login to scan registry
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
inputs:
command: login
containerRegistry: $(scanConnection)
- task: Docker@2
displayName: Build from Red Hat Universal Base Image
inputs:
command: build
containerRegistry: $(quayConnection)
repository: $(imageName)
Dockerfile: build-tools/Dockerfile.ubi
buildContext: .
tags: "$(BUILD_VERSION)-$(Build.SourceVersion)"
arguments: "--build-arg BUILD_INFO=azure-$(Build.BuildId)-$(Build.SourceVersion) --build-arg BUILD_VERSION=$(BUILD_VERSION)"
- task: Docker@2
displayName: Push image to Quay
inputs:
command: push
containerRegistry: $(quayConnection)
repository: $(imageName)
tags: "$(BUILD_VERSION)-$(Build.SourceVersion)"
- script: |
set -ex
podman pull --authfile $(DOCKER_CONFIG)/config.json $(quay_path):$(BUILD_VERSION)-$(Build.SourceVersion)
podman tag $(quay_path):$(BUILD_VERSION)-$(Build.SourceVersion) scan.connect.redhat.com/$(REDHAT_PRJ_ID)/$(redhat_prj_name):$(BUILD_VERSION)-ubi8
podman push --authfile $(DOCKER_CONFIG)/config.json scan.connect.redhat.com/$(REDHAT_PRJ_ID)/$(redhat_prj_name):$(BUILD_VERSION)-ubi8
condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/tags/'))
displayName: 'Push image to Redhat'
continueOnError: true
- script: |
set -ex
docker pull $(quay_path):$(BUILD_VERSION)-$(Build.SourceVersion)
docker tag $(quay_path):$(BUILD_VERSION)-$(Build.SourceVersion) $(docker_repo):$(BUILD_VERSION)
patch_version=`echo $(BUILD_VERSION) | awk -F '.' '{print $3}'`
if [ "${patch_version}" == "0" ] ; then
stripped_version=`echo $(BUILD_VERSION) | rev | cut -c3- | rev`
docker tag $(quay_path):$(BUILD_VERSION)-$(Build.SourceVersion) $(docker_repo):${stripped_version}
docker push $(docker_repo):${stripped_version}
fi
docker push $(docker_repo):$(BUILD_VERSION)
displayName: 'Push image to DockerHub'
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
- stage: ScanContainerImage
dependsOn: ContainerImage
jobs:
- job: ScanContainerImage
steps:
- script: |
FILE_VALUE=$(cat next-version.txt)
echo "##vso[task.setvariable variable=BUILD_VERSION]$FILE_VALUE"
displayName: Set CIS Version
- script: echo $(BUILD_VERSION)
displayName: 'Display the variable value'
- task: CmdLine@2
displayName: Install Trivy
inputs:
script: |
sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy
- task: CmdLine@2
displayName: "Run trivy scan"
inputs:
script: |
trivy image --timeout 10m --format template --template "@junit.tpl" -o test.xml --severity HIGH,CRITICAL $(quay_path):$(BUILD_VERSION)-$(Build.SourceVersion)
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/test.xml'
mergeTestResults: true
failTaskOnFailedTests: false
testRunTitle: 'Trivy - Vulnerabilities Summary'
- stage: Charts
dependsOn: []
jobs:
- job: BuildCharts
steps:
- script: |
FILE_VALUE=$(cat next-version.txt)
echo "##vso[task.setvariable variable=BUILD_VERSION]$FILE_VALUE"
displayName: Set CIS Version
- script: |
git diff HEAD HEAD~ --name-only | grep "helm-charts/\|docs/cis-20.x/config_examples/customResourceDefinitions"
if [ $? == 0 ] ; then echo "##vso[task.setvariable variable=chartsUpdated]True"; fi
git diff HEAD HEAD~ --name-only | grep "helm-charts/\|docs/cis-20.x/rbac/clusterrole.yaml"
if [ $? == 0 ] ; then echo "##vso[task.setvariable variable=chartsUpdated]True"; fi
displayName: Check Helm changes
- script: echo '##vso[task.setvariable variable=chartPath]stable'
displayName: "Set the helm chart release directory as stable if the Build.SourceBranch starts with 'refs/tags/' "
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
- script: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh --version $helmVersion
displayName: Install Helm
failOnStderr: true
condition: and(succeeded(), or(startsWith(variables['build.sourceBranch'], 'refs/tags/'), eq(variables['chartsUpdated'], 'True')) )
- task: UsePythonVersion@0
displayName: Install Python
inputs:
versionSpec: '3.8'
addToPath: true
architecture: 'x64'
condition: and(succeeded(), or(startsWith(variables['build.sourceBranch'], 'refs/tags/'), eq(variables['chartsUpdated'], 'True')) )
- script: |
mkdir -p ./helm-charts/f5-bigip-ctlr/crds
cp ./docs/cis-20.x/config_examples/customResourceDefinitions/$(chartPath)/customresourcedefinitions.yml ./helm-charts/f5-bigip-ctlr/crds/f5-bigip-ctlr-customresourcedefinitions.yml
sed -i '/^metadata:/r ./helm-charts/labels.txt' ./helm-charts/f5-bigip-ctlr/crds/f5-bigip-ctlr-customresourcedefinitions.yml
# Use sed to insert the annotations
sed -i "/name: deployconfigs.cis.f5.com/a\ annotations:\n \"helm.sh/hook\": crd-install" ./helm-charts/f5-bigip-ctlr/crds/f5-bigip-ctlr-customresourcedefinitions.yml
pip install --disable-pip-version-check -r ./build-tools/py-requirements.txt
python ./build-tools/helm-clusterrole-gen.py
helm lint --strict ./helm-charts/f5-bigip-ctlr --set 'args.cm_url=https://example.com'
helm package ./helm-charts/f5-bigip-ctlr --destination .deploy/
displayName: Package Helm Chart
failOnStderr: true
condition: and(succeeded(), or(startsWith(variables['build.sourceBranch'], 'refs/tags/'), eq(variables['chartsUpdated'], 'True')) )
- script: |
set -ex
git clone --single-branch --branch gh-pages https://$(PAT)@github.com/$(chartOrganization)/$(chartRepoName).git /tmp/$(chartRepoName)
mkdir -p /tmp/$(chartRepoName)/helm-charts/$(chartPath)
cp -rf .deploy/*.tgz /tmp/$(chartRepoName)/helm-charts/$(chartPath)/
cp -rf helm-charts/f5-bigip-ctlr/README.md /tmp/$(chartRepoName)/helm-charts/
cp -rf README.md /tmp/$(chartRepoName)/
pushd /tmp/$(chartRepoName)
git config user.email "[email protected]"
git config user.name "cisbotctlr"
helm repo index --url https://$(chartOrganization).github.io/$(chartRepoName)/helm-charts/$(chartPath) helm-charts/$(chartPath)
git add --all
git commit -m 'Updating charts for CIS Release v$(BUILD_VERSION) and Build Info azure-$(Build.BuildId)-$(Build.SourceVersion) in $(chartPath)'
git push origin gh-pages
popd
displayName: Upload charts
condition: and(succeeded(), or(startsWith(variables['build.sourceBranch'], 'refs/tags/'), eq(variables['chartsUpdated'], 'True')) )
- stage: Operator
dependsOn: []
jobs:
- job: BuildOperator
steps:
- script: |
git diff HEAD HEAD~ --name-only | grep "helm-charts/\|f5-bigip-ctlr-operator/\|docs/cis-20.x/rbac/clusterrole.yaml"
if [ $? == 0 ] ; then echo "##vso[task.setvariable variable=operatorUpdated]True"; fi
displayName: Check Operator changes
- task: Docker@2
displayName: Login to quay registry
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
inputs:
command: login
containerRegistry: $(quayConnection)
- task: Docker@2
displayName: Login to redhat registry
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
inputs:
command: login
containerRegistry: $(redhatConnection)
- task: UsePythonVersion@0
displayName: Install Python
inputs:
versionSpec: '3.8'
addToPath: true
architecture: 'x64'
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
- script: |
pip install --disable-pip-version-check -r ./build-tools/py-requirements.txt
python ./build-tools/helm-clusterrole-gen.py
displayName: 'Generate the ClusterRole file'
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
- task: Docker@2
displayName: Build Operator Image for test
inputs:
command: build
containerRegistry: $(quayConnection)
repository: $(operatorImageName)
Dockerfile: f5-bigip-ctlr-operator/Dockerfile
buildContext: .
tags: $(Build.SourceVersion)
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
- task: Docker@2
displayName: Push image to Quay for testing
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
inputs:
command: push
containerRegistry: $(quayConnection)
repository: $(operatorImageName)
tags: $(Build.SourceVersion)
- script: |
sed -i 's|registry.connect.redhat.com/f5networks/k8s-bigip-ctlr-operator:latest|quay.io/$(operatorImageName):$(Build.SourceVersion)|g' ./f5-bigip-ctlr-operator/bundle/manifests/f5-bigip-ctlr-operator.clusterserviceversion.yaml
displayName: 'Prepare the charts repo for bunding with operator'
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
- task: Docker@2
displayName: Build Operator Bundle for test
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
inputs:
command: build
containerRegistry: $(quayConnection)
repository: $(operatorBundleImageName)
Dockerfile: f5-bigip-ctlr-operator/bundle.Dockerfile
buildContext: f5-bigip-ctlr-operator
tags: $(Build.SourceVersion)
- task: Docker@2
displayName: Push Operator Bundle image to Quay for testing
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))
inputs:
command: push
containerRegistry: $(quayConnection)
repository: $(operatorBundleImageName)
tags: $(Build.SourceVersion)
- script: |
wget http://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest-4.16/opm-linux.tar.gz
tar xvf opm-linux.tar.gz
./opm-rhel8 index add --bundles quay.io/$(operatorBundleImageName):$(Build.SourceVersion) --tag quay.io/$(operatorIndexImage):$(Build.SourceVersion)
podman push quay.io/$(operatorIndexImage):$(Build.SourceVersion)
displayName: Updating the operator index image
condition: and(succeeded(), eq(variables['operatorUpdated'], 'True'))