forked from F5Networks/k8s-bigip-ctlr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yaml
239 lines (234 loc) · 10.5 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
# 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'
redhat_tag: '$(BUILD_VERSION)-rhel7'
docker_version: '$(BUILD_VERSION)'
docker_repo: 'f5networks/k8s-bigip-ctlr'
chartPath: 'incubator'
chartRepoName: 'charts'
chartOrganization: F5Networks
helmVersion: 'v3.5.4'
chartsUpdated: False
operatorUpdated: False
operatorImageName: 'f5networks/f5-cis-operator-devel'
operatorBundleImageName: 'f5networks/f5-cis-operator-bundle-devel'
operatorIndexImage: 'f5networks/f5-cis-operator-index-devel'
stages:
- stage: PreCheck
jobs:
- job: Preverification
steps:
- task: CmdLine@2
displayName: Check Go format and Suspicious constructs
inputs:
script: 'make verify'
- task: CmdLine@2
displayName: Check documentation
inputs:
script: 'make docs'
- stage: ContainerImage
dependsOn: PreCheck
jobs:
- job: BuildContainerImage
steps:
- 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.SourceVersion)
arguments: "--build-arg BUILD_INFO=azure-$(Build.BuildId)-$(Build.SourceVersion) --build-arg BUILD_VERSION=$(BUILD_VERSION) --build-arg RUN_TESTS=$(RUN_TESTS) --build-arg COVERALLS_TOKEN=$(COVERALLS_TOKEN)"
- task: Docker@2
displayName: Push image to Quay
inputs:
command: push
containerRegistry: $(quayConnection)
repository: $(imageName)
tags: $(Build.SourceVersion)
- script: |
set -ex
podman pull --authfile $(DOCKER_CONFIG)/config.json $(quay_path):$(Build.SourceVersion)
podman tag $(quay_path):$(Build.SourceVersion) scan.connect.redhat.com/$(REDHAT_PRJ_ID)/$(redhat_prj_name):$(redhat_tag)
podman push --authfile $(DOCKER_CONFIG)/config.json scan.connect.redhat.com/$(REDHAT_PRJ_ID)/$(redhat_prj_name):$(redhat_tag)
condition: and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/tags/'))
displayName: 'Push image to Redhat'
continueOnError: true
- script: |
set -ex
docker pull $(quay_path):$(Build.SourceVersion)
docker tag $(quay_path):$(Build.SourceVersion) $(docker_repo):latest
docker tag $(quay_path):$(Build.SourceVersion) $(docker_repo):$(docker_version)
patch_version=`echo $(docker_version) | awk -F '.' '{print $3}'`
if [ "${patch_version}" == "0" ] ; then
stripped_version=`echo $(docker_version) | rev | cut -c3- | rev`
docker tag $(quay_path):$(Build.SourceVersion) $(docker_repo):${stripped_version}
docker push $(docker_repo):${stripped_version}
fi
docker push $(docker_repo):latest
docker push $(docker_repo):$(docker_version)
displayName: 'Push image to DockerHub'
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
- stage: Charts
dependsOn: PreCheck
jobs:
- job: BuildCharts
steps:
- script: |
git diff HEAD HEAD~ --name-only | grep "helm-charts/\|docs/config_examples/customResourceDefinitions/customresourcedefinitions.yml"
if [ $? == 0 ] ; then echo "##vso[task.setvariable variable=chartsUpdated]True"; fi
git diff HEAD HEAD~ --name-only | grep "helm-charts/\|docs/config_examples/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/config_examples/customResourceDefinitions/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
pip install -r ./build-tools/py-requirements.txt
python ./build-tools/helm-clusterrole-gen.py
helm lint --strict ./helm-charts/f5-bigip-ctlr --set 'args.bigip_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)
cp -rf .deploy/*.tgz /tmp/$(chartRepoName)/$(chartPath)/
pushd /tmp/$(chartRepoName)
git config user.email "[email protected]"
git config user.name "cisbotctlr"
helm repo index --url https://$(chartOrganization).github.io/$(chartRepoName)/$(chartPath) $(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: PreCheck
jobs:
- job: BuildOperator
steps:
- script: |
git diff HEAD HEAD~ --name-only | grep "helm-charts/\|operator/"
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: 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.9/opm-linux.tar.gz
tar xvf opm-linux.tar.gz
./opm 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'))