Add Dockerfile auto-discovery when scanning is enabled #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Customers currently need to manually specify Dockerfile paths in their config:
This is tedious and error-prone, especially across multiple repos where Dockerfiles may be in different locations.
Solution
Auto-discover Dockerfiles when scanning is enabled but no explicit paths are configured.
Before: Customer must know and list every Dockerfile path
After: Just enable scanning, Socket Basics finds them automatically
Implementation
Added
_discover_dockerfiles()method to the Trivy connector that:os.walk()Discovery Patterns
DockerfileDockerfile.prod,Dockerfile.dev,Dockerfile.testapp.dockerfile,backend.dockerfileExcluded Directories
Directories are excluded case-insensitively to avoid false positives:
node_modules,vendor.git,.svn,.hgtest,tests,testing,__tests__,spec,specsfixture,fixtures,testdata,test_dataexample,examples,sample,samplesmock,mocksdist,build,out,targetvenv,.venv,env,.env.cache,.tox,.nox,.pytest_cacheapp_testsBehavior
dockerfilesexplicitly setdockerfilesempty + scanning enableddockerfilesempty + scanning disabledTest Coverage
15 unit tests covering all discovery and exclusion scenarios:
Test Details
discovers_dockerfile_at_rootDockerfilein workspace rootdiscovers_dockerfile_in_subdirectorydocker/Dockerfilenested pathsdiscovers_dockerfile_with_suffixDockerfile.prod,Dockerfile.devdiscovers_dockerfile_extensionapp.dockerfile,backend.dockerfileexcludes_node_modulesnode_modules/**/Dockerfileexcludes_vendor_directoryvendor/**/Dockerfileexcludes_test_directoriestest/,tests/,testing/,__tests__/excludes_fixture_directoriesfixture/,fixtures/,testdata/excludes_example_directoriesexample/,examples/,sample/,samples/excludes_build_directoriesdist/,build/,out/,target/excludes_app_tests_directorydiscovers_multiple_dockerfilesempty_workspace_returns_empty_listno_dockerfiles_returns_empty_list[]when no Dockerfiles existcase_insensitive_exclusionsNode_Modules,VENDOR,Testsall excludedFiles Changed
socket_basics/core/connector/trivy/trivy.py- Added_discover_dockerfiles()method and integrationtests/test_dockerfile_discovery.py- Pytest test suite (for future use with Python 3.10+)tests/run_discovery_tests.py- Standalone test runner (works with any Python 3.x)Example Log Output
🤖 Generated with Claude Code