-
Notifications
You must be signed in to change notification settings - Fork 86
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
chore(ci): Save Trivy cache to avoid Trivy TOOMANYREQUESTS errors #182
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Note: This workflow only updates the cache. You should create a separate workflow for your actual Trivy scans. | ||
# In your scan workflow, set TRIVY_SKIP_DB_UPDATE=true and TRIVY_SKIP_JAVA_DB_UPDATE=true. | ||
name: Update Trivy Cache | ||
|
||
on: | ||
schedule: | ||
- cron: '0 1 * * *' # Run daily at midnight UTC | ||
workflow_dispatch: # Allow manual triggering | ||
|
||
jobs: | ||
update-trivy-db: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get current date | ||
id: date | ||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | ||
|
||
- name: Download and extract the vulnerability DB | ||
run: | | ||
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db | ||
oras copy ghcr.io/aquasecurity/trivy-db:2 ghcr.io/tiryoh/aquasecurity/trivy-db:2 || echo "err" | ||
oras pull ghcr.io/aquasecurity/trivy-db:2 || oras pull ghcr.io/tiryoh/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 | ||
run: | | ||
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/java-db | ||
oras copy ghcr.io/aquasecurity/trivy-java-db:1 ghcr.io/tiryoh/aquasecurity/trivy-java-db:1 || echo "err" | ||
oras pull ghcr.io/aquasecurity/trivy-java-db:1 || oras pull ghcr.io/tiryoh/aquasecurity/trivy-java-db:1 | ||
tar -xzf javadb.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/java-db | ||
rm javadb.tar.gz | ||
Comment on lines
+26
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Apply similar improvements to the Java DB download step. This step could benefit from the same enhancements suggested for the previous step:
Consider updating the step as follows: - name: Download and extract the Java DB
run: |
mkdir -p "$GITHUB_WORKSPACE/.cache/trivy/java-db"
if ! oras copy ghcr.io/aquasecurity/trivy-java-db:1 ghcr.io/tiryoh/aquasecurity/trivy-java-db:1; then
echo "Failed to copy trivy-java-db, falling back to direct pull"
fi
if ! (oras pull ghcr.io/aquasecurity/trivy-java-db:1 || oras pull ghcr.io/tiryoh/aquasecurity/trivy-java-db:1); then
echo "Failed to pull trivy-java-db from both sources" >&2
exit 1
fi
tar -xzf javadb.tar.gz -C "$GITHUB_WORKSPACE/.cache/trivy/java-db"
rm javadb.tar.gz This update aligns the Java DB step with the improvements suggested for the vulnerability DB step. 🧰 Tools🪛 actionlint
|
||
|
||
- name: Cache DBs | ||
uses: actions/cache/save@v4 | ||
with: | ||
path: ${{ github.workspace }}/.cache/trivy | ||
key: cache-trivy-${{ steps.date.outputs.date }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance error handling and use double quotes for variables.
The fallback mechanism for database download is a good practice. However, there are a few areas that could be improved:
echo "err"
, consider using proper error messages and exit codes.Consider updating the step as follows:
This update improves error handling and adds proper quoting for variables.
🧰 Tools
🪛 actionlint