-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (105 loc) · 3.61 KB
/
main.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
name: Release Containerimage
on:
push:
branches:
- main
workflow_dispatch:
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
scanners: 'vuln,secret,config'
ignore-unfixed: false
format: 'sarif'
exit-code: '1'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
category: 'code'
build-test-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: checkout
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build (and test) project with Maven
run: mvn -B package --file pom.xml
# set the env.BRANCH_NAME variable
- uses: nelonoel/[email protected]
- name: Set outputs
id: vars
run: echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Set image name
run: echo "IMAGE_ID=$(echo ${{ github.repository }} | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
# set the env.COMMIT variable
- run: echo "COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
#, enable=${{ github.ref != 'refs/heads/main' }}
# type=raw,value=${{ github.head_ref }}-${{ github.sha }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ env.IMAGE_ID }}
tags: |
type=schedule
type=ref,event=branch
type=raw,value=${{ github.head_ref }}
type=raw,value=latest,enable={{is_default_branch}}
- run : echo "${{ steps.meta.outputs.tags }}"
- name: Buildah Action
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: mega-backend
tags: ${{ steps.meta.outputs.tags }}
buildArgs: COMMIT=${{ env.COMMIT}}, BRANCH=${{ env.BRANCH_NAME}}, VERSION=${{ env.COMMIT}}
containerfiles: |
./Containerfile
- name: Log in to the GitHub Container registry
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: push image to trivy
run: |
buildah push ${{ steps.build-image.outputs.image-with-tag }} oci:./mega-backend-oci
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
input: 'mega-backend-oci'
format: 'sarif'
ignore-unfixed: false
severity: 'CRITICAL,HIGH'
exit-code: '1'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
category: 'container'
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Push to GitHub Container Repository
id: push-to-ghcr
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.REGISTRY }}