Skip to content

Commit d48e06f

Browse files
committed
run trivy vulnerability scanner on the 'latest' docker image
- run trivy from makefile so that it can be run both locally and through github actions - usage: make test_trivy TRIVY_TARGET_DOCKER_IMAGE=regist.ry/user/image:tag - tested by downgrading the base image to alpine 3.15.7 and verifying that vulnerabilities are reported (https://github.com/nodiscc/Shaarli/actions/runs/4860040980/jobs/8663400103) - TEMP/TESTING only push image to ghcr.io, run trivy on trivy branch/docker tag as well as master - ref. shaarli#1531
1 parent 88b76c4 commit d48e06f

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

.github/workflows/docker-latest.yml

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Build/push Docker image (master/latest)
22
on:
33
push:
4-
branches: [ master ]
4+
branches: [ master, trivy ]
55
jobs:
66
docker-build:
77
runs-on: ubuntu-latest
@@ -11,11 +11,11 @@ jobs:
1111
- name: Set up Docker Buildx
1212
uses: docker/setup-buildx-action@v2
1313

14-
- name: Login to DockerHub
15-
uses: docker/login-action@v2
16-
with:
17-
username: ${{ secrets.DOCKERHUB_USERNAME }}
18-
password: ${{ secrets.DOCKERHUB_TOKEN }}
14+
# - name: Login to DockerHub
15+
# uses: docker/login-action@v2
16+
# with:
17+
# username: ${{ secrets.DOCKERHUB_USERNAME }}
18+
# password: ${{ secrets.DOCKERHUB_TOKEN }}
1919
- name: Login to GitHub Container Registry
2020
uses: docker/login-action@v2
2121
with:
@@ -35,9 +35,11 @@ jobs:
3535
with:
3636
context: .
3737
push: true
38-
platforms: linux/amd64,linux/arm64,linux/arm/v7
39-
tags: |
40-
${{ secrets.DOCKER_IMAGE }}:latest
41-
ghcr.io/${{ secrets.DOCKER_IMAGE }}:latest
38+
# tags: |
39+
# ${{ secrets.DOCKER_IMAGE }}:trivy
40+
# ghcr.io/${{ secrets.DOCKER_IMAGE }}:trivy
41+
tags: ghcr.io/${{ secrets.DOCKER_IMAGE }}:trivy
4242
- name: Image digest
4343
run: echo ${{ steps.docker_build.outputs.digest }}
44+
- name: Run trivy image scanner
45+
run: make test_trivy TRIVY_TARGET_DOCKER_IMAGE=ghcr.io/${{ secrets.DOCKER_IMAGE }}:trivy

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ locale_test_%:
8282
--bootstrap tests/languages/bootstrap.php \
8383
--testsuite language-$(firstword $(subst _, ,$*))
8484

85+
# trivy version (https://github.com/aquasecurity/trivy/releases)
86+
TRIVY_VERSION=0.39.0
87+
# default docker image to scan with trivy
88+
TRIVY_TARGET_DOCKER_IMAGE=ghcr.io/shaarli/shaarli:latest
89+
test_trivy:
90+
wget --quiet --continue -O trivy_$(TRIVY_VERSION)_Linux-64bit.tar.gz https://github.com/aquasecurity/trivy/releases/download/v$(TRIVY_VERSION)/trivy_$(TRIVY_VERSION)_Linux-64bit.tar.gz
91+
tar -zxf trivy_$(TRIVY_VERSION)_Linux-64bit.tar.gz
92+
./trivy image $(TRIVY_TARGET_DOCKER_IMAGE)
93+
8594
all_tests: test locale_test_de_DE locale_test_en_US locale_test_fr_FR
8695
@# --The current version is not compatible with PHP 7.2
8796
@#$(BIN)/phpcov merge --html coverage coverage

0 commit comments

Comments
 (0)