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.
Current Situation
Currently, the db and metadata packages are passed a cache directory, within which they create subdirectories like
$CACHE_DIR/db
. This results in database and metadata files being stored at paths such as:$CACHE_DIR/db/trivy.db
$CACHE_DIR/db/metadata.json
Problem
While the metadata implementation and other aspects are common and potentially reusable for Java DB and other databases, the hard-coded
db/
subdirectory makes it difficult to reuse these packages effectively.Proposed Solution
To improve reusability, I propose to remove the hard-coded
db/
subdirectory and instead allow the DB directory to be passed from outside. This change will result in file paths like:$DB_DIR/trivy.db
$DB_DIR/metadata.json
Where
$DB_DIR
can be set to any desired path, including but not limited to the current$CACHE_DIR/db
.As a CLI flag, the value passed as
--output-dir
is passed directly to $DB_DIR.$OUTPUT_DIR/trivy.db
$OUTPUT_DIR/metadata.json
Note
We need to update Trivy as it also affects Trivy.