-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (76 loc) · 2.56 KB
/
build-test-push-training.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
name: Build, Test and Push Training Servcie to GitHub Container Registry
on:
push:
branches: ["feature/ml-training-service" ]
pull_request:
branches: [ "main", "dev" ]
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
build-and-push-image:
strategy:
matrix:
component: [ training ]
runs-on: ubuntu-20.04
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to the Container Registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine Semantic Version
uses: paulhatch/semantic-version@v5.4.0
id: semantic-version
with:
tag_prefix: "v"
major_pattern: "(MAJOR-${{ matrix.component }})"
minor_pattern: "(MINOR-${{ matrix.component }})"
change_path: "${{ matrix.component }}-service"
version_format: "v${major}.${minor}.${patch}+${increment}"
namespace: ${{ matrix.component }}
- name: Build Docker Image
id: docker-build
uses: docker/build-push-action@v5.3.0
with:
context: ./${{ matrix.component }}-service
load: true
file: ./${{ matrix.component }}-service/Dockerfile
- name: Run Trivy Vulnerability Scanner
id: scan
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ steps.docker-build.outputs.imageid }}
format: 'table'
severity: HIGH,CRITICAL
exit-code: 1
- name: Upload SARIF file
if: ${{ steps.scan.outputs.sarif != '' }}
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: Extract Metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.component }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
type=raw,value=${{ steps.semantic-version.outputs.version }}
- name: Push Docker Image
id: docker-push
uses: docker/build-push-action@v5.3.0
with:
context: ./${{ matrix.component }}-service
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}