Skip to content

Commit

Permalink
cache trivy take 1
Browse files Browse the repository at this point in the history
  • Loading branch information
coilysiren committed Nov 13, 2024
1 parent cdc2ad4 commit 7682e01
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/vulnerability-scans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,44 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: Restore cached trivy vulnerability and Java DBs
id: cache-trivy
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/.cache/trivy
key: cache-trivy-${{ steps.date.outputs.date }}

- name: Setup oras
if: steps.cache-trivy.outputs.cache-hit != 'true'
uses: oras-project/setup-oras@v1

- name: Download and extract the vulnerability DB
if: steps.cache-trivy.outputs.cache-hit != 'true'
run: |
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db
oras pull ghcr.io/aquasecurity/trivy-db:2
tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db
rm db.tar.gz
- name: Download and extract the Java DB
if: steps.cache-trivy.outputs.cache-hit != 'true'
run: |
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/java-db
oras pull ghcr.io/aquasecurity/trivy-java-db:1
tar -xzf javadb.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/java-db
rm javadb.tar.gz
- name: Cache DBs
if: steps.cache-trivy.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/.cache/trivy
key: cache-trivy-${{ steps.date.outputs.date }}

- name: Restore cached Docker image
uses: actions/cache/restore@v4
with:
Expand All @@ -116,6 +154,9 @@ jobs:
ignore-unfixed: true
vuln-type: os
scanners: vuln,secret
env:
TRIVY_SKIP_DB_UPDATE: true
TRIVY_SKIP_JAVA_DB_UPDATE: true

- name: Save output to workflow summary
if: always() # Runs even if there is a failure
Expand Down

0 comments on commit 7682e01

Please sign in to comment.