-
Notifications
You must be signed in to change notification settings - Fork 11
426 lines (380 loc) · 13.3 KB
/
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
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
name: pipeline
on:
push:
branches:
- develop
- feat/*
- hotfix/*
- main
pull_request:
branches:
- develop
- feat/*
- hotfix/*
- main
env:
CONTAINER_NAME: ${{ github.repository }}
CONTAINER_REGISTRY_GHCR: ghcr.io
CONTAINER_REGISTRY_DOCKER_HUB: docker.io
CONTAINER_PLATFORMS: linux/amd64,linux/arm64/v8
# https://github.com/docker/buildx/releases
BUILDX_VERSION: 0.11.2
# https://nodejs.org/en/download/releases
NODE_VERSION: 18.17.1
# https://github.com/helm/helm/releases
HELM_VERSION: 3.12.3
# https://npmjs.com/package/snyk?activeTab=versions
SNYK_VERSION: 1.1221.0
# https://github.com/oras-project/oras/releases
ORAS_VERSION: 1.1.0
# https://github.com/rust-lang/rust/tags
RUST_VERSION: 1.72.0
jobs:
init:
name: Init
runs-on: ubuntu-22.04
outputs:
VERSION: ${{ steps.version.outputs.version }}
VERSION_FULL: ${{ steps.version.outputs.version_full }}
VERSION_WIN: ${{ steps.version.outputs.version_win }}
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
with:
# We need all Git history for "version.sh"
fetch-depth: 0
# Ensure "version.sh" submodule are up-to-date
submodules: recursive
- name: Version
id: version
run: |
echo "version=$(bash cicd/version/version.sh -g . -c)" >> $GITHUB_OUTPUT
echo "version_full=$(bash cicd/version/version.sh -g . -c -m)" >> $GITHUB_OUTPUT
echo "version_win=$(bash cicd/version/version.sh -g . -c -w)" >> $GITHUB_OUTPUT
sast-creds:
name: SAST - Credentials
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
with:
# We need all Git history for testing credentials
fetch-depth: 0
# Ensure all submodules up-to-date
submodules: recursive
- name: SAST - Credentials
uses: trufflesecurity/trufflehog@v3.63.1
with:
base: ${{ github.event.repository.default_branch }}
extra_args: --only-verified
head: HEAD
path: .
build-helm:
name: Build Helm chart
needs:
- init
- sast-creds
- sast-semgrep
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Setup Helm
uses: azure/setup-helm@v3.5
with:
version: v${{ env.HELM_VERSION }}
# Required for running "npx" CLI
- name: Setup Node
uses: actions/setup-node@v4.0.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: Package Helm chart
run: |
cp README.md cicd/helm/private-gpt
helm package \
--app-version ${{ needs.init.outputs.VERSION }} \
--dependency-update \
--destination helm-binaries \
--version ${{ needs.init.outputs.VERSION }} \
cicd/helm/private-gpt
- name: Cache Helm chart
uses: actions/upload-artifact@v3.1.3
with:
name: helm-chart
path: helm-binaries
- name: Render Helm chart locally
run: |
helm template \
--output-dir .helm-template \
--values test/helm/values.yaml \
helm-binaries/private-gpt-${{ needs.init.outputs.VERSION }}.tgz
- name: Run SAST Snyk for Helm
# Snyk can be used to break the build when it detects security issues. In this case we want to upload the issues to GitHub Security
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: |
npx --yes snyk@${{ env.SNYK_VERSION }} iac test \
--sarif-file-output=snyk.sarif \
--severity-threshold=medium \
.helm-template
- name: Upload results to GitHub Security
uses: github/codeql-action/upload-sarif@v3.24.3
with:
sarif_file: snyk.sarif
publish-helm:
name: Publish Helm chart
needs:
- build-helm
- build-images
- create-release
- init
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Download Helm chart
uses: actions/download-artifact@v3.0.2
with:
name: helm-chart
path: helm-binaries
- name: Setup node
uses: actions/setup-node@v4.0.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: Upload Helm chart to release
uses: actions/github-script@v7.0.1
with:
script: |
github.rest.repos.uploadReleaseAsset({
data: require("fs").readFileSync("helm-binaries/private-gpt-${{ needs.init.outputs.VERSION }}.tgz"),
name: "private-gpt-${{ needs.init.outputs.VERSION }}.tgz",
owner: context.repo.owner,
release_id: ${{ needs.create-release.outputs.RELEASE_ID }},
repo: context.repo.repo,
});
build-images:
name: Build & publish image "${{ matrix.src }}"
needs:
- init
- sast-creds
- sast-semgrep
runs-on: ubuntu-22.04
permissions:
# Allow to write to GitHub Security
security-events: write
# Allow to write to GitHub Packages
packages: write
strategy:
fail-fast: false
matrix:
src: [conversation-api, conversation-ui]
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Configure Git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Setup QEMU
id: setup-qemu
uses: docker/setup-qemu-action@v3.0.0
with:
platforms: ${{ env.CONTAINER_PLATFORMS }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3.0.0
with:
version: v${{ env.BUILDX_VERSION }}
# Required for running "npx" CLI
- name: Setup Node
uses: actions/setup-node@v4.0.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: Login to registry - GitHub
uses: docker/login-action@v3.0.0
with:
registry: ${{ env.CONTAINER_REGISTRY_GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to registry - Docker Hub
uses: docker/login-action@v3.0.0
with:
registry: ${{ env.CONTAINER_REGISTRY_DOCKER_HUB }}
username: clemlesne
password: ${{ secrets.DOCKER_HUB_PAT }}
- name: Container meta
id: meta
uses: docker/metadata-action@v5.0.0
with:
images: |
${{ env.CONTAINER_REGISTRY_GHCR }}/${{ env.CONTAINER_NAME }}
${{ env.CONTAINER_REGISTRY_DOCKER_HUB }}/${{ env.CONTAINER_NAME }}
flavor: |
prefix=${{ matrix.src }}-
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=schedule
type=schedule,pattern={{date 'YYYYMMDD'}}
type=semver,pattern={{version}},value=${{ needs.init.outputs.VERSION_FULL }}
type=sha
labels: |
org.opencontainers.image.documentation=https://github.com/${{ env.CONTAINER_NAME }}
org.opencontainers.image.vendor=${{ github.actor }}
- name: Store tag
id: tag
run: |
ref="${{ github.ref }}"
branch=$(echo "${ref#refs/heads/}" | sed 's/\//-/g')
tag=$(echo "${{ steps.meta.outputs.tags }}" | grep -m1 $branch)
echo "tag=$tag" >> $GITHUB_OUTPUT
- name: Build/push container
uses: docker/build-push-action@v5.0.0
with:
build-args: |
VERSION=${{ needs.init.outputs.VERSION_FULL }}
cache-from: type=gha
cache-to: type=gha
context: src/${{ matrix.src }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ env.CONTAINER_PLATFORMS }}
provenance: true
push: true
sbom: true
tags: ${{ steps.meta.outputs.tags }}
- name: Run SAST Snyk on container image
# Snyk can be used to break the build when it detects security issues. In this case we want to upload the issues to GitHub Security
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: |
npx --yes snyk@${{ env.SNYK_VERSION }} container test \
--fail-on=upgradable \
--file=src/${{ matrix.src }}/Dockerfile \
--sarif-file-output=snyk.sarif \
--severity-threshold=medium \
${{ steps.tag.outputs.tag }}
- name: Upload results to GitHub Security
uses: github/codeql-action/upload-sarif@v3.24.3
with:
sarif_file: snyk.sarif
sast-semgrep:
name: SAST - Semgrep
runs-on: ubuntu-22.04
permissions:
# Allow to write to GitHub Security
security-events: write
container:
image: returntocorp/semgrep
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Run tests
# Semgrep can be used to break the build when it detects security issues. In this case we want to upload the issues to GitHub Security
continue-on-error: true
env:
SEMGREP_RULES: p/cwe-top-25 p/owasp-top-ten p/dockerfile
run: semgrep ci --sarif --output=semgrep.sarif
- name: Upload results to GitHub Security
uses: github/codeql-action/upload-sarif@v3.24.3
with:
sarif_file: semgrep.sarif
publish-artifacthub-metadata:
name: Publish ArtifactHub metadata
# Only publish on non-scheduled default branch
if: (github.event_name != 'schedule') && (github.ref == 'refs/heads/main')
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Setup ORAS
uses: oras-project/setup-oras@v1.1.0
with:
version: ${{ env.ORAS_VERSION }}
- name: Login to registry - GitHub
uses: docker/login-action@v3.0.0
with:
registry: ${{ env.CONTAINER_REGISTRY_GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to registry - Docker Hub
uses: docker/login-action@v3.0.0
with:
registry: ${{ env.CONTAINER_REGISTRY_DOCKER_HUB }}
username: clemlesne
password: ${{ secrets.DOCKER_HUB_PAT }}
- name: Push to registry
run: |
oras push \
${{ env.CONTAINER_REGISTRY_GHCR }}/${{ env.CONTAINER_NAME }}:artifacthub.io \
artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml
oras push \
${{ env.CONTAINER_REGISTRY_DOCKER_HUB }}/${{ env.CONTAINER_NAME }}:artifacthub.io \
artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml
create-release:
name: Create release
needs:
- init
- sast-creds
- sast-semgrep
permissions:
# Allow to create releases
contents: write
runs-on: ubuntu-22.04
outputs:
RELEASE_ID: ${{ steps.create-release.outputs.result }}
# Only publish on non-scheduled main branch, as there is only one Helm repo and we cannot override an existing version
# if: (github.event_name != 'schedule') && (github.ref == 'refs/heads/main')
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Setup node
uses: actions/setup-node@v4.0.0
with:
node-version: ${{ env.NODE_VERSION }}
- name: Create release
id: create-release
uses: actions/github-script@v7.0.1
with:
script: |
const isMain = context.ref == `refs/heads/main`;
const repoName = context.repo.repo;
console.log(isMain ? 'Creating release for default branch' : 'Creating release for non-default branch');
const { data } = await github.rest.repos.createRelease({
draft: true,
generate_release_notes: true,
name: `${repoName} v${{ needs.init.outputs.VERSION }}`,
owner: context.repo.owner,
prerelease: !isMain,
repo: repoName,
tag_name: 'v${{ needs.init.outputs.VERSION }}',
target_commitish: context.ref,
});
return data.id
publish-release:
name: Publish release
permissions:
# Allow to write releases
contents: write
runs-on: ubuntu-22.04
needs:
- create-release
- init
- publish-helm
# Only publish on non-scheduled default branch
if: (github.event_name != 'schedule') && (github.ref == 'refs/heads/main')
steps:
- name: publish release
id: publish-release
uses: actions/github-script@v7.0.1
with:
script: |
github.rest.repos.updateRelease({
draft: false,
owner: context.repo.owner,
release_id: ${{ needs.create-release.outputs.RELEASE_ID }},
repo: context.repo.repo,
});