12
12
IMAGE_NAME : algorithm-exercises-js
13
13
14
14
jobs :
15
-
16
- build :
17
- name : " Build & Test in Docker"
18
-
15
+ security :
16
+ name : " Snyk Container"
19
17
runs-on : ubuntu-latest
20
-
21
18
steps :
22
19
- uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
23
- - name : Build the Docker image
24
- run : make compose/rebuild
25
- - name : Lint in Docker image
26
- run : make compose/lint
27
- - name : Test in Docker image
28
- run : make compose/test
29
- - name : Run in Docker image
30
- run : make compose/run
31
- - name : Tag Docker image
32
- run : >
33
- docker tag
34
- ${{ env.IMAGE_NAME }}:latest
35
- ${{ env.IMAGE_NAME }}:${{ github.sha }}
36
20
37
21
- name : Run Snyk to check Docker image for vulnerabilities
38
22
# Snyk can be used to break the build when it detects vulnerabilities.
@@ -49,9 +33,122 @@ jobs:
49
33
with :
50
34
image : ${{ env.IMAGE_NAME }}:${{ github.sha }}
51
35
args : --file=Dockerfile
52
- # yamllint disable rule:comments-indentation
53
- # - name: Upload result to GitHub Code Scanning
54
- # uses: github/codeql-action/upload-sarif@v2
55
- # with:
56
- # sarif_file: snyk.sarif
57
- # yamllint enable rule:comments-indentation
36
+
37
+ build :
38
+ name : " Build & Test in Docker"
39
+ runs-on : ubuntu-latest
40
+ steps :
41
+ - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
42
+
43
+ # - name: Build the Docker image
44
+ # run: make compose/rebuild
45
+ # - name: Image List
46
+ # run: docker image ls -a
47
+ # - name: Lint in Docker image
48
+ # run: make compose/lint
49
+ # - name: Test in Docker image
50
+ # run: make compose/test
51
+ # - name: Run in Docker image
52
+ # run: make compose/run
53
+
54
+ - name : Set up Docker Buildx
55
+ uses : docker/setup-buildx-action@v3
56
+
57
+ - name : " LINT: Build and push"
58
+ uses : docker/build-push-action@v6
59
+ with :
60
+ context : .
61
+ target : lint
62
+ outputs : |
63
+ type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_lint.tar
64
+ tags : |
65
+ ${{ env.IMAGE_NAME }}:lint
66
+ - name : " LINT: Upload artifact"
67
+ uses : actions/upload-artifact@v4
68
+ with :
69
+ name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_lint
70
+ path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_lint.tar
71
+
72
+ - name : " TEST: Build and push"
73
+ uses : docker/build-push-action@v6
74
+ with :
75
+ context : .
76
+ target : testing
77
+ outputs : |
78
+ type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_test.tar
79
+ tags : |
80
+ ${{ env.IMAGE_NAME }}:test
81
+ - name : " TEST: Upload artifact"
82
+ uses : actions/upload-artifact@v4
83
+ with :
84
+ name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_test
85
+ path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_test.tar
86
+
87
+ - name : " PRODUCTION: Build and push"
88
+ uses : docker/build-push-action@v6
89
+ with :
90
+ context : .
91
+ target : production
92
+ outputs : |
93
+ type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
94
+ tags : |
95
+ ${{ env.IMAGE_NAME }}:latest
96
+ ${{ env.IMAGE_NAME }}:${{ github.sha }}
97
+ - name : " PRODUCTION: Upload artifact"
98
+ uses : actions/upload-artifact@v4
99
+ with :
100
+ name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
101
+ path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
102
+
103
+ lint :
104
+ name : " Run in docker: LINT"
105
+ runs-on : ubuntu-latest
106
+ needs : build
107
+ steps :
108
+ - name : Download artifact
109
+ uses : actions/download-artifact@v4
110
+ with :
111
+ name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
112
+ path : /tmp/
113
+
114
+ - name : Load image
115
+ run : |
116
+ docker load --input /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
117
+ docker image ls -a
118
+
119
+ - name : Run lint
120
+ run : |
121
+ make compose/lint
122
+
123
+ scan :
124
+ name : " Trivy"
125
+ runs-on : ubuntu-latest
126
+ needs : build
127
+ steps :
128
+ - name : Download artifact
129
+ uses : actions/download-artifact@v4
130
+ with :
131
+ name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
132
+ path : /tmp/
133
+
134
+ - name : Load image
135
+ run : |
136
+ docker load --input /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
137
+ docker image ls -a
138
+
139
+ - name : Run Trivy vulnerability scanner
140
+ uses :
aquasecurity/[email protected]
141
+ with :
142
+ image-ref : ${{ env.IMAGE_NAME }}:${{ github.sha }}
143
+ format : ' table'
144
+ exit-code : ' 1'
145
+ ignore-unfixed : true
146
+ vuln-type : ' os,library'
147
+ severity : ' CRITICAL,HIGH'
148
+
149
+ # yamllint disable rule:comments-indentation
150
+ # - name: Upload Trivy scan results to GitHub Security tab
151
+ # uses: github/codeql-action/upload-sarif@v2
152
+ # with:
153
+ # sarif_file: 'trivy-results.sarif'
154
+ # yamllint enable rule:comments-indentation
0 commit comments