@@ -10,29 +10,9 @@ on: # yamllint disable-line rule:truthy
10
10
11
11
env :
12
12
IMAGE_NAME : algorithm-exercises-js
13
+ ARTIFACT_NAME : algorithm-exercises-js_${{ github.sha }}
13
14
14
15
jobs :
15
- security :
16
- name : " Snyk Container"
17
- runs-on : ubuntu-latest
18
- steps :
19
- - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
20
-
21
- - name : Run Snyk to check Docker image for vulnerabilities
22
- # Snyk can be used to break the build when it detects vulnerabilities.
23
- # In this case we want to upload the issues to GitHub Code Scanning
24
- continue-on-error : true
25
- uses : snyk/actions/docker@master
26
- env :
27
- # yamllint disable rule:line-length
28
- # In order to use the Snyk Action you will need to have a Snyk API token.
29
- # See https://docs.snyk.io/integrations/ci-cd-integrations/github-actions-integration#getting-your-snyk-token
30
- # or you can sign up for free at https://snyk.io/login
31
- # yamllint enable rule:line-length
32
- SNYK_TOKEN : ${{ secrets.SNYK_TOKEN }}
33
- with :
34
- image : ${{ env.IMAGE_NAME }}:${{ github.sha }}
35
- args : --file=Dockerfile
36
16
37
17
build :
38
18
name : " Build & Test in Docker"
@@ -60,65 +40,100 @@ jobs:
60
40
context : .
61
41
target : lint
62
42
outputs : |
63
- type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_lint.tar
43
+ type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_lint.tar
64
44
tags : |
65
45
${{ env.IMAGE_NAME }}:lint
66
46
- name : " LINT: Upload artifact"
67
47
uses : actions/upload-artifact@v4
68
48
with :
69
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_lint
70
- path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_lint.tar
49
+ name : ${{ env.ARTIFACT_NAME }}_lint
50
+ path : /tmp/${{ env.ARTIFACT_NAME }}_lint.tar
71
51
72
52
- name : " TEST: Build and push"
73
53
uses : docker/build-push-action@v6
74
54
with :
75
55
context : .
76
56
target : testing
77
57
outputs : |
78
- type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_test.tar
58
+ type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_test.tar
79
59
tags : |
80
60
${{ env.IMAGE_NAME }}:test
81
61
- name : " TEST: Upload artifact"
82
62
uses : actions/upload-artifact@v4
83
63
with :
84
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_test
85
- path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_test.tar
64
+ name : ${{ env.ARTIFACT_NAME }}_test
65
+ path : /tmp/${{ env.ARTIFACT_NAME }}_test.tar
86
66
87
67
- name : " PRODUCTION: Build and push"
88
68
uses : docker/build-push-action@v6
89
69
with :
90
70
context : .
91
71
target : production
92
72
outputs : |
93
- type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
73
+ type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_prod.tar
94
74
tags : |
95
75
${{ env.IMAGE_NAME }}:latest
96
76
${{ env.IMAGE_NAME }}:${{ github.sha }}
97
77
- name : " PRODUCTION: Upload artifact"
98
78
uses : actions/upload-artifact@v4
99
79
with :
100
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
101
- path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
80
+ name : ${{ env.ARTIFACT_NAME }}_prod
81
+ path : /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
102
82
103
83
lint :
104
84
name : " Run in docker: LINT"
105
85
runs-on : ubuntu-latest
106
86
needs : build
107
87
steps :
88
+ - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
89
+
108
90
- name : Download artifact
109
91
uses : actions/download-artifact@v4
110
92
with :
111
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
93
+ name : ${{ env.ARTIFACT_NAME }}_lint
112
94
path : /tmp/
113
95
114
96
- name : Load image
115
97
run : |
116
- docker load --input /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod .tar
98
+ docker load --input /tmp/${{ env.ARTIFACT_NAME }}_lint .tar
117
99
docker image ls -a
118
100
119
101
- name : Run lint
120
102
run : |
121
- make compose/lint
103
+ docker run --rm -it ${{ env.IMAGE_NAME }}:lint make lint
104
+
105
+ security :
106
+ name : " Snyk Container"
107
+ runs-on : ubuntu-latest
108
+ needs : build
109
+ steps :
110
+ - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
111
+ - name : Download artifact
112
+ uses : actions/download-artifact@v4
113
+ with :
114
+ name : ${{ env.ARTIFACT_NAME }}_prod
115
+ path : /tmp/
116
+
117
+ - name : Load image
118
+ run : |
119
+ docker load --input /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
120
+ docker image ls -a
121
+
122
+ - name : Run Snyk to check Docker image for vulnerabilities
123
+ # Snyk can be used to break the build when it detects vulnerabilities.
124
+ # In this case we want to upload the issues to GitHub Code Scanning
125
+ continue-on-error : true
126
+ uses : snyk/actions/docker@master
127
+ env :
128
+ # yamllint disable rule:line-length
129
+ # In order to use the Snyk Action you will need to have a Snyk API token.
130
+ # See https://docs.snyk.io/integrations/ci-cd-integrations/github-actions-integration#getting-your-snyk-token
131
+ # or you can sign up for free at https://snyk.io/login
132
+ # yamllint enable rule:line-length
133
+ SNYK_TOKEN : ${{ secrets.SNYK_TOKEN }}
134
+ with :
135
+ image : ${{ env.IMAGE_NAME }}:${{ github.sha }}
136
+ args : --file=Dockerfile
122
137
123
138
scan :
124
139
name : " Trivy"
@@ -128,12 +143,12 @@ jobs:
128
143
- name : Download artifact
129
144
uses : actions/download-artifact@v4
130
145
with :
131
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
146
+ name : ${{ env.ARTIFACT_NAME }}_prod
132
147
path : /tmp/
133
148
134
149
- name : Load image
135
150
run : |
136
- docker load --input /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
151
+ docker load --input /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
137
152
docker image ls -a
138
153
139
154
- name : Run Trivy vulnerability scanner
0 commit comments