Skip to content

Commit 3e45967

Browse files
committed
Add Trivy to CI for every PR
1 parent 4542d5b commit 3e45967

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed

.github/workflows/ci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: CI Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- dev
8+
paths-ignore:
9+
- '**.md'
10+
11+
jobs:
12+
image-test:
13+
name: Image Test
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Lower case for ghcr
18+
id: ghcr_string
19+
uses: ASzc/change-string-case-action@v1
20+
with:
21+
string: ${{ github.event.repository.full_name }}
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v1
25+
26+
- name: Cache Docker layers
27+
uses: actions/cache@v2
28+
with:
29+
path: /tmp/.buildx-cache
30+
key: ${{ runner.os }}-buildx-${{ github.sha }}
31+
restore-keys: |
32+
${{ runner.os }}-buildx-
33+
34+
- name: Build image for testing
35+
uses: docker/build-push-action@v2
36+
with:
37+
context: .
38+
platforms: linux/amd64
39+
load: true
40+
tags: |
41+
${{ steps.ghcr_string.outputs.lowercase }}
42+
cache-from: type=local,src=/tmp/.buildx-cache
43+
cache-to: type=local,dest=/tmp/.buildx-cache-new
44+
45+
- name: Move cache
46+
run: |
47+
rm -rf /tmp/.buildx-cache
48+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
49+
50+
- name: Install trivy
51+
run: |
52+
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
53+
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
54+
sudo apt-get update
55+
sudo apt-get install trivy -y
56+
57+
- name: Scan for CVEs
58+
uses: mathiasvr/command-output@v1
59+
id: trivy
60+
with:
61+
run: |
62+
trivy image --no-progress --severity "HIGH,CRITICAL" ${{ steps.ghcr_string.outputs.lowercase }}
63+
64+
- name: Comment CVE info on PR
65+
uses: thollander/actions-comment-pull-request@v1
66+
with:
67+
message: |
68+
```
69+
${{ steps.trivy.outputs.stdout }}
70+
```
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:15.14.0-alpine3.10
1+
FROM node:16-alpine3.15 as builder
22

33
VOLUME [ "/data" ]
44

@@ -7,15 +7,27 @@ ENV DB_TYPE=$DB_TYPE
77

88
RUN apk add --no-cache python3 py3-pip make gcc g++
99

10+
COPY . /app
11+
1012
COPY package.json yarn.lock /app/
1113

1214
WORKDIR /app
1315

14-
RUN yarn
16+
RUN yarn install --frozen-lockfile && npx browserslist@latest --update-db
17+
RUN npm run build:without-migrate
1518

16-
COPY . /app
19+
FROM node:16-alpine3.15 as runner
1720

18-
RUN npm run build:without-migrate
21+
ENV NODE_ENV=production
22+
ARG DB_TYPE=sqlite
23+
ENV DB_TYPE=$DB_TYPE
24+
25+
WORKDIR /app
26+
27+
COPY --from=builder /app/node_modules ./node_modules
28+
COPY --from=builder /app/public ./public
29+
COPY --from=builder /app/.next ./.next
30+
COPY . /app
1931

2032
EXPOSE 3000/tcp
2133

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5469,9 +5469,9 @@ typeorm@^0.2.30:
54695469
zen-observable-ts "^1.0.0"
54705470

54715471
typescript@^4.1.3:
5472-
version "4.2.4"
5473-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
5474-
integrity sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==
5472+
version "4.7.4"
5473+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
5474+
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==
54755475

54765476
typescript@~4.1.3:
54775477
version "4.1.5"

0 commit comments

Comments
 (0)