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

refactor(metadata): pass db dir #412

Merged
merged 2 commits into from
Jul 1, 2024

Conversation

knqyf263
Copy link
Collaborator

@knqyf263 knqyf263 commented Jun 28, 2024

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.

@knqyf263 knqyf263 self-assigned this Jun 28, 2024
Signed-off-by: knqyf263 <[email protected]>
@knqyf263 knqyf263 marked this pull request as ready for review June 28, 2024 17:09
@knqyf263 knqyf263 requested a review from DmitriyLewen June 28, 2024 17:09
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

1 question:
in source code you use OUT_DIR, but in PR description DB_DIR.
Is this the same thing?

@knqyf263
Copy link
Collaborator Author

knqyf263 commented Jul 1, 2024

in source code you use OUT_DIR, but in PR description DB_DIR.
Is this the same thing?

Yes. DB dir is used as an argument because it is a DB directory, but I thought output dir would be easier to understand as a CLI flag of trivy-db build, so that is what I did. I don't mind changing it to the same name.

BTW, I'm afraid of breaking something. I built a database locally and confirmed it worked as expected, but could you double-check it?

@DmitriyLewen
Copy link
Contributor

Yes. DB dir is used as an argument because it is a DB directory, but I thought output dir would be easier to understand as a CLI flag of trivy-db build, so that is what I did. I don't mind changing it to the same name.

OUT_DIR is good for me. But I suggest using OUT_DIR in the PR description so that we don't get confused if we look at that PR later.

I built a database locally and confirmed it worked as expected, but could you double-check it?

I have already build/compress/compact db locally. It works correctly for me too.

@knqyf263
Copy link
Collaborator Author

knqyf263 commented Jul 1, 2024

OUT_DIR is good for me. But I suggest using OUT_DIR in the PR description so that we don't get confused if we look at that PR later.

Updated.

I have already build/compress/compact db locally. It works correctly for me too.

Awesome. Thanks!

@knqyf263 knqyf263 merged commit 8e90746 into aquasecurity:main Jul 1, 2024
2 checks passed
@knqyf263 knqyf263 deleted the refactor/db_path branch July 1, 2024 10:35
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.

2 participants