Skip to content

Commit ada1db0

Browse files
committed
Download the Trivy binary rather than compile it
This is significantly faster and aligns with the upstream action for GitHub: github.com/aquasecurity/[email protected]
1 parent 9ca3593 commit ada1db0

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

.gitlab-ci.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ spec:
1313
description: >
1414
The CPU architectures on which to run tests
1515
16-
# TODO(retention): We can increase the retention on scheduled pipelines after
17-
# https://gitlab.com/groups/gitlab-org/-/epics/16321
16+
# https://docs.gitlab.com/ci/yaml#artifactsexpire_in
1817
retention:
1918
type: string
2019
default: 2d # Enough time to find and address MR failures the following day
2120
description: >
22-
How long to keep reports; see https://docs.gitlab.com/ci/yaml#artifactsexpire_in
21+
How long to keep reports
2322
---
2423

2524
# https://docs.gitlab.com/ci/yaml/workflow
@@ -35,7 +34,6 @@ variables:
3534
# Show the duration of individual script items in the job log.
3635
FF_SCRIPT_SECTIONS: 'true'
3736

38-
# See: [.github/workflows/lint.yaml]
3937
# This uses a specific minor version of golangci-lint to ensure new code conforms
4038
# to the rules we set when this release branch was cut. We do not want new rules
4139
# suggesting sweeping changes to our release branches.
@@ -95,7 +93,6 @@ golang-lint:
9593
reports:
9694
junit: golangci-lint.junit.xml
9795

98-
# See: [.github/workflows/test.yaml]
9996
# This uses an old version of Go because the generation tools require it.
10097
must-commit-generated:
10198
stage: build
@@ -110,7 +107,6 @@ must-commit-generated:
110107
- git config --global --add safe.directory "$(pwd)"
111108
- make check-generate
112109

113-
# See: [.github/workflows/test.yaml]
114110
# This uses the latest version of Go we have internally.
115111
go-test:
116112
stage: test
@@ -172,7 +168,7 @@ govulncheck:
172168
# This fails the job when it detects a vulnerability in called code.
173169
- go run "${TOOL}" --format text --show verbose ./...
174170

175-
# See: [.github/workflows/trivy.yaml]
171+
# https://trivy.dev/latest/ecosystem/cicd
176172
trivy:
177173
stage: test
178174
needs: []
@@ -190,22 +186,25 @@ trivy:
190186
# Download Trivy and log its version.
191187
- |-
192188
VERSION=$(go list -m -f '{{.Version}}' github.com/aquasecurity/trivy@latest)
193-
TOOL="github.com/aquasecurity/trivy/cmd/trivy@${VERSION}"
194-
go run -exec true "${TOOL}"
195-
196-
# Download the JUnit template for this version.
197-
- curl -sSL -o /tmp/trivy-junit.tpl "https://raw.githubusercontent.com/aquasecurity/trivy/refs/tags/${VERSION}/contrib/junit.tpl"
189+
git clone --config 'advice.detachedHead=no' --depth 1 --branch "${VERSION}" --sparse \
190+
'https://github.com/aquasecurity/trivy.git' \
191+
'.gitlab-remotes/aquasecurity-trivy'
192+
(
193+
cd '.gitlab-remotes/aquasecurity-trivy'
194+
git sparse-checkout set 'contrib'
195+
bash 'contrib/install.sh' -b "${HOME}/bin" "${VERSION}"
196+
)
198197
199198
# Generate a report and fail when there are issues that can be fixed.
200199
# Trivy needs a populated Go module cache to detect Go module licenses.
201200
- go mod download
202201
- >-
203-
go run "${TOOL}" filesystem . --exit-code 1
202+
trivy filesystem . --exit-code 1
204203
--scanners license,secret,vuln
205204
--ignore-unfixed
206205
--no-progress
207206
--format template
208-
--template '@/tmp/trivy-junit.tpl'
207+
--template '@.gitlab-remotes/aquasecurity-trivy/contrib/junit.tpl'
209208
--output 'trivy.junit.xml'
210209
211210
# Send the report to GitLab.

0 commit comments

Comments
 (0)