-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (99 loc) · 3.29 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
name: Container release pipeline
on:
push:
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
pull_request:
types:
- opened
schedule:
- cron: "0 0 * * 0" # weekly at sunday night
# Avoid running this workflow multiple times at the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
IMAGE_NAME: rouhim/sons-of-the-forest-server
IMAGE_TAG: latest
jobs:
check-containerfile:
name: Check container file
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'config'
hide-progress: false
format: 'table'
exit-code: '1'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
build-test-push-image:
needs: check-containerfile
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build container image
uses: docker/build-push-action@v6
with:
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
platforms: linux/amd64
context: container-data
file: container-data/Containerfile
load: true
push: false
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: image
image-ref: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
format: 'table'
exit-code: '1'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
- name: Test the built image
run: |
mkdir -p config/ data/
chmod 777 config/ data/
timeout 10m bash .github/workflows/test-image.sh
- name: Build and push container image
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
with:
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
platforms: linux/amd64
context: container-data
file: container-data/Containerfile
load: false
push: true
- name: Update docker hub description
if: github.ref == 'refs/heads/main'
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.IMAGE_NAME }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: image
image-ref: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
exit-code: '0'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
format: 'sarif'
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'