Skip to content

Commit 07da736

Browse files
committed
feat: implement security tests thanks to trivy
close #28
1 parent b8c838d commit 07da736

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ before_script:
1515
- mv 'shellcheck-v0.6.0/shellcheck' "$HOME/bin/shellcheck"
1616
- chmod +x "$HOME/bin/shellcheck"
1717
- cp -f scripts/dive "$HOME/bin/dive"
18+
- cp -f scripts/trivy "$HOME/bin/dive"
1819
- rvm install "$(cat .ruby-version)"
1920
- export PATH=$HOME/.local/bin:/usr/sbin:$PATH
2021
script:

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@ shellcheck: ## Run shellcheck on /scripts directory
5252
@find scripts/ -type f | xargs -n 1 shellcheck
5353

5454
test: ## Run tests suite
55-
@$(MAKE) pre-commit shellcheck dockerfile-lint serverspec dive
55+
@$(MAKE) pre-commit shellcheck dockerfile-lint serverspec dive trivy
56+
57+
trivy: ## Run trivy, a simple Vulnerability Scanner for Containers
58+
$(info --> Run `trivy`)
59+
@awk '/image:/ { print $$2 }' docker-compose.ci.yml \
60+
| xargs -I % -n 1 -P 1 trivy \
61+
--exit-code 1 \
62+
--no-progress \
63+
--severity HIGH,CRITICAL %

scripts/trivy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
DEBUG=${DEBUG:=0}
8+
[[ $DEBUG -eq 1 ]] && set -o xtrace
9+
10+
GITHUB_TOKEN=${GITHUB_TOKEN:=''}
11+
TRIVY_TIMEOUT_SEC=${TRIVY_TIMEOUT_SEC:='360s'}
12+
13+
export TRIVY_TIMEOUT_SEC
14+
15+
# shellcheck disable=SC2145
16+
echo "--> trivy $@"
17+
18+
# shellcheck disable=SC2046
19+
docker run --network host --rm --name "trivy_$(date +'%Y%m%d%H%M%S')" \
20+
-e GITHUB_TOKEN="${GITHUB_TOKEN}" \
21+
-v $(pwd)/.cache:/root/.cache/ \
22+
-v ~/.docker/config.json:/root/.docker/config.json:ro \
23+
-v /var/run/docker.sock:/var/run/docker.sock:ro \
24+
-t $(tty &>/dev/null && echo '-i') \
25+
aquasec/trivy:0.6.0 \
26+
"$@"

0 commit comments

Comments
 (0)