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

CLI flag for directory base #1867

Merged
merged 5 commits into from
Jul 10, 2023
Merged

CLI flag for directory base #1867

merged 5 commits into from
Jul 10, 2023

Conversation

deitch
Copy link
Contributor

@deitch deitch commented Jun 6, 2023

The ability to add a "root" or "base" directory already exists. However, it only was exposed via API and not CLI.

This adds a flag called --base-path <base> which would use that as the root. Defaults to "".

In order to wire it up into Source, and specifically the whole ParseInput*() without adding even more variants, I rewired them to just take variadic options funcs, and created the funcs for the ones we know exist. I recognize that this looks good to me, but may be a little off the wall for others. I am more than happy to take redirection on it.

I thought about doing the same in source.go with NewFromDirectoryWithName() and NewFromDirectoryRootWithName() and NewFromDirectoryWithNameVersion() and etc. etc. But that already had the *Root* variants, so I left it alone. I can add it, if wanted.

Either way, this does work.

Signed-off-by: Avi Deitcher <avi@deitcher.net>
@deitch
Copy link
Contributor Author

deitch commented Jun 6, 2023

Clean CI always is nice 😁

@deitch
Copy link
Contributor Author

deitch commented Jun 7, 2023

How can I help move this along @kzantow ?

…redundant functions

Signed-off-by: Keith Zantow <kzantow@gmail.com>
@wagoodman
Copy link
Contributor

API-wise this is about to introduce a new pattern on an object that is about to be deleted in #1846 (which I'm hoping to land for final review this week). I think it makes sense to hold off on this PR, get #1846 in, then I can rebase this on the changes there.

@kzantow kzantow merged commit 4ab9f39 into anchore:main Jul 10, 2023
@deitch deitch deleted the option-dir-base branch July 10, 2023 17:53
@deitch
Copy link
Contributor Author

deitch commented Jul 10, 2023

Huzzah!

@deitch
Copy link
Contributor Author

deitch commented Jul 10, 2023

So it is just syft packages --base-path /path/to/base?

Is this going into a release version?

@kzantow
Copy link
Contributor

kzantow commented Jul 10, 2023

@deitch yes either --base-path or env var SYFT_BASE_PATH=..., it'll be in the next release, of course. We can look at getting a release done this week, does that work for you?

@deitch
Copy link
Contributor Author

deitch commented Jul 10, 2023

Sure. Can I bother you to comment here when it is in? I will start to adopt it upstream in various places then.

spiffcs added a commit that referenced this pull request Jul 11, 2023
* main:
  feat: CLI flag for directory base (#1867)
  Fix CPE gen for k8s python client (#1921)
  chore: update iterations to protect against race (#1927)
  chore(deps): update bootstrap tools to latest versions (#1922)
  fix: Don't use the actual redis or grpc CPEs for gems (#1926)
  fix(install): return with right error code (#1915)
  Remove erroneous Java CPEs from generation (#1918)
  chore(deps): bump golang.org/x/net from 0.11.0 to 0.12.0 (#1916)
  Switch UI to bubbletea (#1888)
  fix: use filepath.EvalSymlinks if os.Readlink fails to evaluate the link (#1884)
  add file source digest support (#1914)
  chore(deps): update bootstrap tools to latest versions (#1908)
  chore(deps): bump golang.org/x/mod from 0.11.0 to 0.12.0 (#1912)
  chore(deps): bump golang.org/x/term from 0.9.0 to 0.10.0 (#1913)
  doc(readme): add installation section with scoop (#1909)
  Refactor source API (#1846)
  chore(deps): update bootstrap tools to latest versions (#1905)
@spiffcs spiffcs added the enhancement New feature or request label Jul 12, 2023
@kzantow
Copy link
Contributor

kzantow commented Jul 12, 2023

@deitch this has made it into a release: https://github.com/anchore/syft/releases/tag/v0.85.0

@CLechleitner42
Copy link

CLechleitner42 commented Jul 26, 2023

Shouldn't the base-path default to "/" instead of ""?

I solved a CI problem (that occured as of the latest syft release) by adding --base-path /.

FYI we are scanning a temp directory with symlinks to *.jar files, because we only want a report on those JARs used by our application. And without --base-path / we ended up with an empty list (no packages found), instead of 52.

@kzantow
Copy link
Contributor

kzantow commented Jul 26, 2023

@CLechleitner42 could you open an issue for this? Symlinks are hard. We probably need a broader discussion to change the behavior -- but absolutely can if it's determined to be the right thing to do!

@CLechleitner42
Copy link

CLechleitner42 commented Jul 26, 2023

OK, I'll create an issue shortly, first I have to make sure our CI is fixed, it blocks a major project's acceptance ;-)

Yes symlinks are not trivial to handle once you start to think about link symlinks to symlinks, loops, and so on.

PS: Thanks for the quick reaction!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants