-
Notifications
You must be signed in to change notification settings - Fork 5
465 lines (455 loc) · 15.9 KB
/
pipeline.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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
name: "Build"
on:
pull_request:
push:
branches:
- master
tags:
- "v*"
workflow_dispatch: {}
jobs:
#
# Building Stage
#
generate-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.generate-version.outputs.version }}
is-public-build: ${{ steps.generate-version.outputs.is-public-build }}
steps:
- name: Detect Version
id: generate-version
run: |
$ref = '${{ github.ref }}'
if ($ref.StartsWith('refs/tags/v'))
{
$version = ($ref -split '/v' | Select-Object -Last 1)
$isPublicBuild = $true
}
else
{
$version = "0.0.1"
$isPublicBuild = $false
}
Write-Host "Detected version: '$version'."
"version=$version" >> $env:GITHUB_OUTPUT
"is-public-build=$isPublicBuild" >> $env:GITHUB_OUTPUT
shell: pwsh
build-image:
runs-on: ubuntu-latest
needs: generate-version
permissions:
packages: write
outputs:
digest: ${{ steps.build.outputs.digest }}
env:
IMAGE_NAME: ghcr.io/contrast-security-oss/agent-operator/operator
BUILD_VERSION: ${{ needs.generate-version.outputs.version }}
IS_PUBLIC_BUILD: ${{ needs.generate-version.outputs.is-public-build }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: docker/setup-buildx-action@v3
id: buildx
with:
install: true
version: latest
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=trunk-artifact,enable=${{ github.ref == 'refs/heads/master' }}
type=raw,value=pr-artifact,enable=${{ github.event_name == 'pull_request' }}
type=raw,value=dispatch-artifact,enable=${{ github.event_name == 'workflow_dispatch' }}
type=raw,value=release-artifact,enable=${{ needs.generate-version.outputs.version != '0.0.1' }}
- uses: docker/build-push-action@v6
id: build
with:
file: Dockerfile
context: .
push: ${{ github.event_name != 'pull_request' }} # don't push the image for PR builds
cache-from: ${{ github.actor != 'dependabot[bot]' && format('type=registry,ref={0}:cache', env.IMAGE_NAME) || ''}}
cache-to: ${{ github.actor != 'dependabot[bot]' && format('type=registry,ref={0}:cache,mode=max', env.IMAGE_NAME) || ''}}
build-args: |
BUILD_VERSION=${{ env.BUILD_VERSION }}
IS_PUBLIC_BUILD=${{ env.IS_PUBLIC_BUILD }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-manifests:
runs-on: ubuntu-latest
needs: generate-version
env:
BUILD_VERSION: ${{ needs.generate-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: imranismail/setup-kustomize@v2
- name: Generate Manifests (Prod)
run: |
set -xe
cd ./manifests/install/prod
kustomize edit set image 'contrast/agent-operator:${{ env.BUILD_VERSION }}'
cat ../../license-header.yaml > ./install-prod.yaml
kustomize build ./ >> ./install-prod.yaml
shell: bash
- name: Generate Manifests (Prod-Quay)
run: |
set -xe
cd ./manifests/install/prod-quay
kustomize edit set image 'quay.io/contrast/agent-operator:${{ env.BUILD_VERSION }}'
cat ../../license-header.yaml > ./install-prod-quay.yaml
kustomize build ./ >> ./install-prod-quay.yaml
shell: bash
- name: Stage Manifests
run: |
set -xe
cp manifests/install/prod/install-prod.yaml ./install-prod.yaml
cp manifests/install/prod-quay/install-prod-quay.yaml ./install-prod-quay.yaml
shell: bash
- name: Publish (Artifacts)
uses: actions/upload-artifact@v4
with:
name: manifests
path: |
install-prod.yaml
install-prod-quay.yaml
retention-days: 7
build-helm-chart:
runs-on: ubuntu-latest
needs: generate-version
env:
BUILD_VERSION: ${{ needs.generate-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: imranismail/setup-kustomize@v2
- uses: azure/setup-helm@v4
with:
version: v3.10.1
token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Chart
run: |
set -xe
pwsh ./manifests/helm/build.ps1 \
-AppVersion ${{ env.BUILD_VERSION }} \
-ChartVersion ${{ env.BUILD_VERSION }}
shell: bash
- name: Render Manifests
run: |
set -xe
helm template test \
./manifests/helm/dist/contrast-agent-operator-${{ env.BUILD_VERSION }}.tgz \
--values ./manifests/helm/values.testing.yaml \
--include-crds \
| tee ./manifests/helm/dist/output.yaml
shell: bash
- name: Publish (Chart)
uses: actions/upload-artifact@v4
with:
name: helm-chart
path: |
manifests/helm/dist/*.tgz
retention-days: 7
- name: Publish (Manifests)
uses: actions/upload-artifact@v4
with:
name: helm-manifests
path: |
manifests/helm/dist/output.yaml
retention-days: 7
test-image:
runs-on: ubuntu-latest
needs:
- build-image
strategy:
matrix:
k3s-version:
- '1.30' # EOL: 2025-06-28
- '1.29' # EOL: 2025-02-28
- '1.28' # EOL: 2024-10-28
- '1.27' # EOL: 2024-06-28
- '1.26' # EOL: 2024-02-28
fail-fast: false
env:
IMAGE: ghcr.io/contrast-security-oss/agent-operator/operator@${{ needs.build-image.outputs.digest }}
if: ${{ github.event_name != 'pull_request' }} # should match push logic in build-image
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: nolar/setup-k3d-k3s@v1
name: Deploy K3d
with:
version: v${{ matrix.k3s-version }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Import Images
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 5
command: |
set -xe
docker pull ${{ env.IMAGE }}
docker tag ${{ env.IMAGE }} local/agent-operator:latest
k3d image import local/agent-operator:latest --mode direct
docker pull busybox:stable
k3d image import busybox:stable --mode direct
docker pull k8s.gcr.io/pause:3.3
k3d image import k8s.gcr.io/pause:3.3 --mode direct
shell: bash
- name: Deploy Manifests
run: |
set -xe
kubectl apply -k manifests/install/testing
kubectl --namespace testing-agent-operator wait --for=condition=Available --timeout=30s deployment contrast-agent-operator
kubectl apply -k manifests/examples/testing
shell: bash
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Execute Functional Tests
run: |
set -xe
dotnet test ./tests/Contrast.K8s.AgentOperator.FunctionalTests/Contrast.K8s.AgentOperator.FunctionalTests.csproj
shell: bash
- name: Dump Operator Logs
uses: nick-fields/retry@v3
if: ${{ always() }}
with:
timeout_minutes: 10
max_attempts: 5
command: |
set -xe
kubectl --namespace testing-agent-operator get events --sort-by=.metadata.creationTimestamp
kubectl --namespace testing-agent-operator get deployment contrast-agent-operator -o yaml
kubectl --namespace testing-agent-operator logs deployment/contrast-agent-operator
shell: bash
test-manifests:
runs-on: ubuntu-latest
needs:
- build-manifests
- build-helm-chart
strategy:
matrix:
artifact:
- manifests
- helm-manifests
k3s-version:
- '1.30' # EOL: 2025-06-28
- '1.29' # EOL: 2025-02-28
- '1.28' # EOL: 2024-10-28
- '1.27' # EOL: 2024-06-28
- '1.26' # EOL: 2024-02-28
fail-fast: false
steps:
- name: Setup Pluto
uses: FairwindsOps/pluto/github-action@master
- name: Setup Polaris
uses: fairwindsops/polaris/.github/actions/setup-polaris@master
with:
version: 7.2.0
- name: Setup Kubeconform
run: |
set -xe
wget https://github.com/yannh/kubeconform/releases/latest/download/kubeconform-linux-amd64.tar.gz
tar xf kubeconform-linux-amd64.tar.gz
sudo install kubeconform /usr/local/bin/kubeconform
- name: Download Manifests
uses: actions/download-artifact@v4
id: download-artifacts
with:
name: ${{ matrix.artifact }}
path: ./artifacts
- name: Validate Manifests
run: |
set -xe
which kubeconform
which pluto
which polaris
for manifest in ./artifacts/*.yaml;
do
# https://github.com/yannh/kubeconform/issues/100#issuecomment-1096832969
# Skipping the custom manifests for now.
kubeconform \
--verbose \
--summary \
--kubernetes-version ${{ matrix.k3s-version }}.0 \
-schema-location "default" \
-schema-location "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{ .NormalizedKubernetesVersion }}/{{ .ResourceKind }}{{ .KindSuffix }}.json" \
-ignore-missing-schemas \
$manifest
pluto detect \
--output wide \
--target-versions k8s=v${{ matrix.k3s-version }}.0 \
$manifest
done
polaris audit \
--audit-path ./artifacts/ \
--set-exit-code-on-danger \
--set-exit-code-below-score 90
shell: bash
#
# Release Internal Stage
#
release-internal:
runs-on: ubuntu-latest
environment: internal
concurrency:
group: internal
needs:
- generate-version
- build-image
- test-image
- test-manifests
permissions:
packages: write
env:
BUILD_VERSION: ${{ needs.generate-version.outputs.version }}
IMAGE_NAME: ghcr.io/contrast-security-oss/agent-operator/operator
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v4
- name: Login (GitHub)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=${{ env.BUILD_VERSION }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.BUILD_VERSION }}
type=semver,pattern={{major}},value=${{ env.BUILD_VERSION }}
type=raw,latest
- name: Tag for Release
uses: akhilerm/[email protected]
with:
src: ghcr.io/contrast-security-oss/agent-operator/operator@${{ needs.build-image.outputs.digest }}
dst: |
${{ steps.meta.outputs.tags }}
#
# Release Public Stage
#
release-public:
runs-on: ubuntu-latest
environment: public
concurrency:
group: public
cancel-in-progress: true
needs:
- generate-version
- build-image
- release-internal
permissions:
contents: write
packages: write
env:
BUILD_VERSION: ${{ needs.generate-version.outputs.version }}
if: ${{ needs.generate-version.outputs.version != '0.0.1' }}
steps:
- uses: actions/checkout@v4
- name: Login (GitHub)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login (Dockerhub)
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PAT }}
- name: Login (Quay)
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Docker Meta
id: dockerhub-meta
uses: docker/metadata-action@v5
with:
images: |
docker.io/contrast/agent-operator
quay.io/contrast/agent-operator
ghcr.io/contrast-security-oss/agent-operator/operator
tags: |
type=semver,pattern={{version}},value=${{ env.BUILD_VERSION }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.BUILD_VERSION }}
type=semver,pattern={{major}},value=${{ env.BUILD_VERSION }}
type=raw,latest
- name: Tag for Release
uses: akhilerm/[email protected]
with:
src: ghcr.io/contrast-security-oss/agent-operator/operator@${{ needs.build-image.outputs.digest }}
dst: |
${{ steps.dockerhub-meta.outputs.tags }}
${{ steps.quay-meta.outputs.tags }}
- uses: actions/download-artifact@v4
id: download-artifacts
with:
name: manifests
path: ./artifacts
- name: Publish
uses: ncipollo/release-action@v1
with:
body: |
Version v${{ env.BUILD_VERSION }} released!
```
contrast/agent-operator:${{ env.BUILD_VERSION }}
contrast/agent-operator@${{ needs.build-image.outputs.digest }}
quay.io/contrast/agent-operator:${{ env.BUILD_VERSION }}
quay.io/contrast/agent-operator@${{ needs.build-image.outputs.digest }}
```
artifacts: ${{ steps.download-artifacts.outputs.download-path }}/*.yaml
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
- name: Publish Helm Chart
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GH_PR_WRITE_PAT }}
repository: Contrast-Security-OSS/helm-charts
event-type: oob-update
client-payload: |
{
"type": "agent-operator",
"runId": "${{ github.run_id }}",
"artifactName": "helm-chart"
}
# - name: Create Sentry Release
# uses: getsentry/action-release@v1
# with:
# environment: production
# ignore_empty: true
# # BUILD_VERSION is the semantic version, but the operator will send the .NET version i.e. X.X.X.X.
# version: agent-operator@${{ env.BUILD_VERSION }}.0
# env:
# SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
# SENTRY_ORG: sentry
# SENTRY_PROJECT: agent-operator
# SENTRY_URL: https://sentry.prod.dotnet.contsec.com
- uses: act10ns/slack@v2
with:
status: ${{ job.status }}
message: |-
Version <https://github.com/Contrast-Security-OSS/agent-operator/releases/tag/v${{ env.BUILD_VERSION }}|v${{ env.BUILD_VERSION }}> of the agent-operator was released!
fallback: |-
[GitHub] Version v${{ env.BUILD_VERSION }} of the agent-operator was released!
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}