Skip to content

fix(docker): add local image scanning for Trivy when not pushing to registry - #14

Merged
williaby merged 1 commit into
mainfrom
fix/trivy-local-image-scan
Dec 27, 2025
Merged

williaby merged 1 commit into
mainfrom
fix/trivy-local-image-scan

Conversation

@williaby

@williaby williaby commented Dec 27, 2025 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds support for Trivy vulnerability scanning when Docker images are not pushed to a registry
  • Exports local images to a tarball for scanning in non-push scenarios (PR builds, local testing)
  • Maintains existing registry-based scanning for pushed images

Problem

Previously, Trivy scanning would fail when push was disabled because it tried to reference a non-existent remote image using image-ref. This caused scan failures in:

  • Pull request builds (where images typically aren't pushed)
  • Local testing scenarios
  • Dry-run configurations

Solution

  • Added a new step to export the local Docker image to /tmp/image.tar when push is disabled
  • Created a separate Trivy action step that uses input parameter to scan the local tarball
  • Original registry-based scanning step now only runs when push is enabled

Test plan

  • Test with push: false - should export and scan local image
  • Test with push: true - should scan registry image as before
  • Verify SARIF output is generated in both scenarios

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enhanced container image vulnerability scanning workflow to comprehensively scan both locally built and registry-pushed images with separate conditional scanning paths, improved image export handling, and comprehensive results reporting for both scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

…egistry

Previously, Trivy scanning would fail when images weren't pushed to a
registry because it tried to reference a non-existent remote image.

This change:
- Exports local images to a tarball when push is disabled
- Uses Trivy's `input` parameter to scan the local tarball
- Keeps registry-based scanning for pushed images

Fixes scanning failures in PR builds and local testing scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 27, 2025 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The pull request refactors Trivy scanning in the Docker workflow by replacing a single scan step with a conditional three-step sequence. It now exports local images to a tarball for scanning when images aren't pushed to a registry, while maintaining separate logic for registry-based scans.

Changes

Cohort / File(s) Summary
Trivy Scanning Restructure
.github/workflows/python-docker.yml
Splits single Trivy scan into conditional multi-step flow: adds local image export to tarball, introduces separate local image scan step (when not pushed), and conditionally gates registry image scan (when pushed). Preserves downstream result upload and PR comment logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Scanning hops through Docker lanes,
Local tarballs, registry chains,
Trivy splits the scan in three,
Conditional logic, clean and free!
Vulnerabilities won't hide,
With branching paths to help us guide. ✨

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/trivy-local-image-scan

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc4881a and 1cc336c.

📒 Files selected for processing (1)
  • .github/workflows/python-docker.yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@williaby
williaby merged commit 61b1f32 into main Dec 27, 2025
4 of 5 checks passed
@williaby
williaby deleted the fix/trivy-local-image-scan branch December 27, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant