aquasecurity / trivy-db

Apache License 2.0
215 stars 131 forks source link

refactor(metadata): pass db dir #412

Closed knqyf263 closed 2 months ago

knqyf263 commented 2 months ago

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:

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:

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.

Note

We need to update Trivy as it also affects Trivy.

knqyf263 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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!