-
Notifications
You must be signed in to change notification settings - Fork 33
/
.drone.yml
424 lines (386 loc) · 11.7 KB
/
.drone.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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# Copyright (c) 2022 SIGHUP s.r.l All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
name: license
kind: pipeline
type: docker
steps:
- name: check
image: docker.io/library/golang:1.17.3
pull: always
commands:
- go get -u github.com/google/addlicense
- addlicense -c "SIGHUP s.r.l" -v -l bsd -check -ignore 'chart/**' .
trigger:
ref:
exclude:
- refs/tags/gatekeeper-policy-manager-*
---
name: policeman
kind: pipeline
type: docker
depends_on:
- license
steps:
- name: lint
image: quay.io/sighup/policeman
pull: always
environment:
FILTER_REGEX_EXCLUDE: (app/static-content/semantic.min.css|chart/|tests/e2e/)
# Identifies false positives like missing 'selector'.
# Doing this is valid for Kustomize patches
VALIDATE_KUBERNETES_KUBEVAL: "false"
# Some duplicated code is intended.
VALIDATE_JSCPD: "false"
TYPESCRIPT_DEFAULT_STYLE: "prettier"
depends_on:
- clone
- name: render
image: quay.io/sighup/e2e-testing:1.1.0_0.11.0_3.12.0_1.9.4_1.29.1_3.5.3_4.33.3
pull: always
depends_on:
- clone
commands:
- kustomize build . > gpm.yaml
- helm template --set config.secretKey=e2e chart > rendered_chart.yaml
- name: check-deprecated-apis
image: us-docker.pkg.dev/fairwinds-ops/oss/pluto:v5
pull: always
depends_on:
- render
commands:
# we use --ignore-deprecations because we don't want the CI to fail when the API has not been removed yet.
- /pluto detect gpm.yaml --ignore-deprecations --target-versions=k8s=v1.31.0
- /pluto detect rendered_chart.yaml --ignore-deprecations --target-versions=k8s=v1.31.0
trigger:
ref:
exclude:
- refs/tags/gatekeeper-policy-manager-*
---
name: build
kind: pipeline
type: docker
depends_on:
- policeman
trigger:
ref:
include:
- refs/tags/**
- refs/heads/**
exclude:
- refs/tags/gatekeeper-policy-manager-*
steps:
- name: build
image: docker:dind
pull: always
environment:
CONTAINER_IMAGE_NAME: gatekeeper-policy-manager
CONTAINER_IMAGE_TAG: test-${DRONE_BUILD_NUMBER}
DOCKERFILE: Dockerfile
BUILD_CONTEXT: "."
volumes:
- name: dockerconfig
path: /root/.docker/config.json
- name: dockersock
path: /var/run/docker.sock
commands:
- "apk add git"
- "docker buildx create --name sighup-builder --use"
# I have disabled armv7 because the build takess too long and the pipeline goes in timeout.
# - "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --pull -f $${DOCKERFILE} -t $${CONTAINER_IMAGE_NAME}:$${CONTAINER_IMAGE_TAG} $${BUILD_CONTEXT}"
- "docker buildx build --platform linux/amd64,linux/arm64 --pull -f $${DOCKERFILE} -t $${CONTAINER_IMAGE_NAME}:$${CONTAINER_IMAGE_TAG} $${BUILD_CONTEXT}"
- "docker buildx build --load -t $${CONTAINER_IMAGE_NAME}:$${CONTAINER_IMAGE_TAG} $${BUILD_CONTEXT}"
volumes:
- name: dockerconfig
host:
path: /root/.docker/config.json
- name: dockersock
host:
path: /var/run/docker.sock
---
name: e2e
kind: pipeline
type: docker
depends_on:
- build
trigger:
ref:
include:
- refs/tags/**
- refs/heads/main
- refs/heads/snyk-**
- refs/heads/dependabot/**
exclude:
- refs/tags/gatekeeper-policy-manager-*
steps:
- name: kind
image: docker:dind
pull: always
environment:
KIND_VERSION: v0.24.0
CLUSTER_VERSION: v1.31.0
LOAD_IMAGE: gatekeeper-policy-manager:test-${DRONE_BUILD_NUMBER}
CLUSTER_NAME: ${DRONE_REPO_NAME}-${DRONE_BUILD_NUMBER}
volumes:
- name: dockerconfig
path: /root/.docker/config.json
- name: dockersock
path: /var/run/docker.sock
commands:
- wget -qO /usr/local/bin/kind "https://kind.sigs.k8s.io/dl/$${KIND_VERSION}/kind-$(uname)-amd64"
- wget -qO /usr/local/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/$${CLUSTER_VERSION}/bin/linux/amd64/kubectl"
- chmod +x /usr/local/bin/kind /usr/local/bin/kubectl
- kind create cluster --name $${CLUSTER_NAME} --image registry.sighup.io/fury/kindest/node:$${CLUSTER_VERSION}
- kind load docker-image $${LOAD_IMAGE} --name $${CLUSTER_NAME}
- kind get kubeconfig --name $${CLUSTER_NAME} > kubeconfig.yml
- name: tests
image: quay.io/sighup/e2e-testing:1.1.0_1.31.1_3.10.0_4.33.3
pull: always
network_mode: host
environment:
LOAD_IMAGE: gatekeeper-policy-manager:test-${DRONE_BUILD_NUMBER}
commands:
- export KUBECONFIG=$PWD/kubeconfig.yml
- cd tests
- kustomize edit set image quay.io/sighup/gatekeeper-policy-manager=$${LOAD_IMAGE}
- cd -
- bats -t tests/tests.sh
- name: gpm-port-forward
image: quay.io/sighup/e2e-testing:1.1.0_1.31.1_3.10.0_4.33.3
pull: always
network_mode: host
detach: true
commands:
- export KUBECONFIG=$PWD/kubeconfig.yml
- kubectl port-forward svc/gatekeeper-policy-manager 8080:80 -n gatekeeper-system
- name: ui-tests
image: mcr.microsoft.com/playwright:v1.30.0-focal
pull: always
network_mode: host
commands:
- cd tests/e2e && yarn install && yarn test
- name: echo-diff-images
image: mcr.microsoft.com/playwright:v1.30.0-focal
commands:
- for f in tests/e2e/test-results/*/*diff.png; do echo $f; base64 -w 0 $f; echo; done;
- "echo 'Use base64 to decode the images and see the diff'"
when:
status:
- failure
- name: kind-destroy
image: docker:dind
pull: always
environment:
KIND_VERSION: v0.24.0
CLUSTER_NAME: ${DRONE_REPO_NAME}-${DRONE_BUILD_NUMBER}
volumes:
- name: dockerconfig
path: /root/.docker/config.json
- name: dockersock
path: /var/run/docker.sock
commands:
- wget -qO /usr/local/bin/kind "https://kind.sigs.k8s.io/dl/$${KIND_VERSION}/kind-$(uname)-amd64"
- chmod +x /usr/local/bin/kind
- kind delete cluster --name $${CLUSTER_NAME}
- rm kubeconfig.yml
when:
status:
- success
- failure
volumes:
- name: dockerconfig
host:
path: /root/.docker/config.json
- name: dockersock
host:
path: /var/run/docker.sock
---
name: release
kind: pipeline
type: docker
depends_on:
- license
- policeman
- e2e
trigger:
ref:
include:
- refs/tags/**
- refs/heads/**
exclude:
- refs/heads/dependabot/**
- refs/heads/snyk-**
- refs/tags/gatekeeper-policy-manager-*
steps:
- name: prepare-tar-gz
image: alpine:latest
pull: always
depends_on: [clone]
commands:
- tar -zcvf gatekeeper-policy-manager-${DRONE_TAG}.tar.gz manifests/ kustomization.yaml LICENSE README.md
when:
ref:
include:
- refs/tags/**
- name: prepare-release-notes
image: quay.io/sighup/fury-release-notes-plugin:3.7_2.8.4
pull: always
depends_on: [clone]
settings:
release_notes_file_path: release-notes.md
when:
ref:
include:
- refs/tags/**
exclude:
- refs/tags/gatekeeper-policy-manager-* # Exclude helm chart releases
- name: registry-sha
image: docker:dind
pull: always
depends_on: [clone]
environment:
username:
from_secret: quay_username
password:
from_secret: quay_password
registry: quay.io
repo: quay.io/sighup/gatekeeper-policy-manager
container_image_name: gatekeeper-policy-manager
container_image_tag: test-${DRONE_BUILD_NUMBER}
DOCKERFILE: Dockerfile
BUILD_CONTEXT: "."
volumes:
- name: dockersock
path: /var/run/docker.sock
commands:
- "apk add git"
- "docker login $${registry} -u $${username} -p $${password}"
- "docker buildx create --name sighup-builder --use"
- "docker buildx build --platform linux/amd64,linux/arm64 --pull --push -f $${DOCKERFILE} -t $${repo}:${DRONE_COMMIT_SHA} -t $${repo}:unstable $${BUILD_CONTEXT}"
# - "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 --pull --push -f $${DOCKERFILE} -t $${repo}:unstable -t $${repo}:go -t $${repo}:${DRONE_COMMIT_SHA} $${BUILD_CONTEXT}"
# - docker rmi $${container_image_name}:$${container_image_tag}
when:
event:
- push
- name: registry-tag
image: docker:dind
pull: always
depends_on: [clone]
environment:
username:
from_secret: quay_username
password:
from_secret: quay_password
registry: quay.io
repo: quay.io/sighup/gatekeeper-policy-manager
container_image_name: gatekeeper-policy-manager
container_image_tag: test-${DRONE_BUILD_NUMBER}
DOCKERFILE: Dockerfile
BUILD_CONTEXT: "."
volumes:
- name: dockersock
path: /var/run/docker.sock
commands:
- "apk add git"
- "docker login $${registry} -u $${username} -p $${password}"
- "docker buildx create --name sighup-builder --use"
- "docker buildx build --platform linux/amd64,linux/arm64 --pull --push -f $${DOCKERFILE} -t $${repo}:latest -t $${repo}:${DRONE_TAG} $${BUILD_CONTEXT}"
when:
event:
- tag
- name: publish-prerelease
image: plugins/github-release
pull: always
depends_on:
- prepare-tar-gz
- prepare-release-notes
- registry-tag
settings:
api_key:
from_secret: c3p0
file_exists: overwrite
files:
- gatekeeper-policy-manager-${DRONE_TAG}.tar.gz
prerelease: true
overwrite: true
title: "Release Candidate ${DRONE_TAG}"
note: release-notes.md
checksum:
- md5
- sha256
when:
ref:
include:
- refs/tags/v**-rc**
- name: publish-stable
image: plugins/github-release
pull: always
depends_on:
- prepare-tar-gz
- prepare-release-notes
- registry-tag
settings:
api_key:
from_secret: c3p0
file_exists: overwrite
files:
- gatekeeper-policy-manager-${DRONE_TAG}.tar.gz
prerelease: false
overwrite: true
title: "Release ${DRONE_TAG}"
note: release-notes.md
checksum:
- md5
- sha256
when:
ref:
exclude:
- refs/tags/v**-rc**
include:
- refs/tags/v**
volumes:
- name: dockersock
host:
path: /var/run/docker.sock
---
name: release-helm-chart
kind: pipeline
type: docker
depends_on:
- "release"
trigger:
ref:
include:
# Trigger the Helm Chart Releaser only when tagging
- refs/tags/**
exclude:
# These kind of tags are generated by `cr` in this pipeline
# we exclude them to avoid a loop.
- refs/tags/gatekeeper-policy-manager-*
steps:
# We need to manually fetch the gh-pages branch because Drone by default
# only checksout the current branch with a minimal depth
# see: https://docs.drone.io/pipeline/docker/syntax/cloning/
- name: fetch-gh-pages-branch
image: alpine/git
commands:
- git fetch origin gh-pages
# We use GitHub Pages as Helm Repository and `cr` (Chart Releaser)
# to help us publish the chart.
- name: chart-releaser
image: quay.io/helmpack/chart-releaser:v1.4.0
environment:
CR_OWNER: sighupio
CR_GIT_REPO: gatekeeper-policy-manager
CR_TOKEN:
from_secret: c3p0
commands:
# For some reason we need to manually create the folder each time
# see: https://github.com/helm/chart-releaser/issues/187
- mkdir -p .cr-index
# Package the chart into a tar.gz
- cr package ./chart
# Upload the tar.gz to a GitHub release
- cr upload --skip-existing
# Update the index.yaml and push it to GitHub Pages
- cr index --push