Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Keep Trivy cache up-to-date on default branch #1878

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/scan-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ jobs:
echo "path=${IMAGE//\//_}.sarif" >> $GITHUB_OUTPUT
- name: Run Trivy image scanner
uses: aquasecurity/[email protected]
env:
TRIVY_SKIP_DB_UPDATE: true
TRIVY_SKIP_JAVA_DB_UPDATE: true
with:
image-ref: ${{ inputs.container-registry }}/${{ inputs.image-repo-prefix }}/${{ matrix.image }}:${{ inputs.image-tag }}
format: sarif
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/update-trivy-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2024 The Cross-Media Measurement Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Update Trivy cache

on:
schedule:
- cron: '0 5 * * *' # Night in America/Los_Angeles, before deploy-nightly.
workflow_dispatch:

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 }}
# Cache key expected by aquasecurity/trivy-action.
key: cache-trivy-${{ steps.get-date.outputs.date }}