ci: trivy через образ aquasec/trivy (сокет) + кэш БД на хосте; бинарь через github releases качается слишком медленно
ci / lint (push) Successful in 53s
contract-openapi / openapi-contract (push) Failing after 35s
contract-openapi / ts-client-is-current (push) Failing after 36s
ci / unit (push) Successful in 47s
ci / security (push) Successful in 1m23s
ci / build (push) Has been skipped
ci / image-scan (push) Has been skipped
ci / push (push) Has been skipped
ci / lint (push) Successful in 53s
contract-openapi / openapi-contract (push) Failing after 35s
contract-openapi / ts-client-is-current (push) Failing after 36s
ci / unit (push) Successful in 47s
ci / security (push) Successful in 1m23s
ci / build (push) Has been skipped
ci / image-scan (push) Has been skipped
ci / push (push) Has been skipped
Refs #17
This commit is contained in:
+21
-19
@@ -248,35 +248,37 @@ jobs:
|
||||
TRIVY_VERSION: "0.76.1"
|
||||
TRIVY_SEVERITY: "HIGH,CRITICAL"
|
||||
steps:
|
||||
- name: install trivy
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fsSL -o /tmp/trivy.tar.gz \
|
||||
"https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz"
|
||||
tar -xzf /tmp/trivy.tar.gz -C /usr/local/bin trivy
|
||||
chmod +x /usr/local/bin/trivy
|
||||
trivy --version
|
||||
|
||||
# trivy запускается официальным образом через docker-сокет: не требует
|
||||
# скачивания бинаря (github releases отдаёт медленно) + БД кэшируется в
|
||||
# /opt/trivy-cache на build-хосте.
|
||||
- name: "trivy image (HIGH/CRITICAL -> fail)"
|
||||
run: |
|
||||
set -o pipefail
|
||||
IMAGE="${REGISTRY}/${IMAGE_NAME}:staging-${GITHUB_SHA::8}"
|
||||
echo "scan: ${IMAGE}"
|
||||
trivy image \
|
||||
--image-src docker \
|
||||
--scanners vuln \
|
||||
--severity "$TRIVY_SEVERITY" \
|
||||
--ignore-unfixed \
|
||||
--exit-code 1 \
|
||||
--format table \
|
||||
"$IMAGE" 2>&1 | tee trivy-report.txt
|
||||
docker run --rm \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /opt/trivy-cache:/root/.cache/trivy \
|
||||
"aquasec/trivy:${TRIVY_VERSION}" image \
|
||||
--image-src docker --scanners vuln \
|
||||
--severity "$TRIVY_SEVERITY" --ignore-unfixed \
|
||||
--exit-code 1 --format table "$IMAGE" 2>&1 | tee trivy-report.txt
|
||||
|
||||
- name: trivy json report
|
||||
if: always()
|
||||
run: |
|
||||
set -o pipefail
|
||||
IMAGE="${REGISTRY}/${IMAGE_NAME}:staging-${GITHUB_SHA::8}"
|
||||
trivy image --image-src docker --scanners vuln --severity "$TRIVY_SEVERITY" \
|
||||
--ignore-unfixed --format json -o trivy-report.json "$IMAGE" || true
|
||||
mkdir -p reports
|
||||
docker run --rm \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /opt/trivy-cache:/root/.cache/trivy \
|
||||
-v "$PWD/reports:/reports" \
|
||||
"aquasec/trivy:${TRIVY_VERSION}" image \
|
||||
--image-src docker --scanners vuln \
|
||||
--severity "$TRIVY_SEVERITY" --ignore-unfixed \
|
||||
--format json -o /reports/trivy-report.json "$IMAGE" || true
|
||||
cp reports/trivy-report.json ./trivy-report.json 2>/dev/null || true
|
||||
|
||||
- name: upload trivy report
|
||||
if: always()
|
||||
|
||||
Reference in New Issue
Block a user