From 0e9bd6cc6b6e13c66584d148bf697a81f538056c Mon Sep 17 00:00:00 2001 From: Sanjay Vasandani Date: Thu, 24 Oct 2024 10:32:54 -0700 Subject: [PATCH] ci: Keep Trivy cache up-to-date on default branch See https://github.com/aquasecurity/trivy-action?tab=readme-ov-file#updating-caches-in-the-default-branch --- .github/workflows/update-trivy-cache.yml | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/update-trivy-cache.yml diff --git a/.github/workflows/update-trivy-cache.yml b/.github/workflows/update-trivy-cache.yml new file mode 100644 index 00000000000..349467db9b9 --- /dev/null +++ b/.github/workflows/update-trivy-cache.yml @@ -0,0 +1,43 @@ +name: Update Trivy cache + +on: + schedule: + - cron: '0 5 * * *' # Night in America/Los_Angeles, before deploy-nightly. + workflow_dispatch: + pull_request: + branches: + - main + +jobs: + update-trivy-cache: + runs-on: ubuntu-latest + env: + TRIVY_CACHE_PATH: .cache/trivy + steps: + - uses: oras-project/setup-oras@v1 + + - name: Get current date + id: get-date + run: echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT" + + - name: Download vulnerability DB + run: oras pull ghcr.io/aquasecurity/trivy-db:2 + + - name: Download Java DB + run: oras pull ghcr.io/aquasecurity/trivy-java-db:1 + + - name: Extract vulnerability DB + run: | + mkdir -p "$TRIVY_CACHE_PATH/db" + tar -xf db.tar.gz -C "$TRIVY_CACHE_PATH/db" + + - name: Extract Java DB + run: | + mkdir -p "$TRIVY_CACHE_PATH/java-db" + tar -xf javadb.tar.gz -C "$TRIVY_CACHE_PATH/java-db" + + - name: Save cache + uses: actions/cache/save@v4 + with: + path: ${{ env.TRIVY_CACHE_PATH }} + key: cache-trivy-${{ steps.get-date.outputs.date }} \ No newline at end of file