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

feat: obtain Java and Python artifacts from .m2 or Python virtual environment from input #864

Conversation

tromai
Copy link
Member

@tromai tromai commented Sep 17, 2024

Closes #811

Description

This pull request adds the following features:

  • The ability to provide Macaron with a maven local repository
  • The ability to resolve the directories that contains artifacts corresponding to a PackageURL from the Maven local repository and/or the Python virtual environment.

Providing a Maven local repository.

A new CLI parameter is added --local-maven-repo that takes a path to a maven local repo. This flag is optional.
If --local-maven-repo is not used, Macaron will load the path to the local maven repo (at $HOME/.m2) if that directory is available.
Macaron will treat this maven local repo as READ-ONLY.

What directory to mount if Macaron is being run as a Docker container?

If --local-maven-repo is provided to run_macaron.sh, the directory provided with this flag is mount to ${MACARON_WORKSPACE}/analyze_local_maven_repo_readonly.

If --local-maven-repo is NOT provided to run_macaron.sh, run_macaron.sh default behavior is consistent with Macaron running as a package, regarding loading the default location $HOME/.m2 of the host:

  • If $HOME/.m2/ of the host is not available, an empty directory is created within the output dir and mounted as read only to ${MACARON_WORKSPACE}/analyze_local_maven_repo_readonly. Then Macaron running within the Docker container will be provided with this empty directory as --local-maven-repo. We do so to avoid Macaron loading $HOME/.m2 as maven local repo inside the container, as $HOME/.m2 inside the container is being used by the cyclone-dx SBOM generator.
  • If $HOME/.m2/ of the host is available, it will be mounted to ${MACARON_WORKSPACE}/analyze_local_maven_repo_readonly.

Providing Python virtual environment as input

This has been implemented in #748.

Resolving artifacts from local repositories for a PackageURL

This is a high-level diagram of finding local artifacts for a PURL

graph LR
purl[Input - PackageURL] -->patt_gen{1 - Generating glob patterns} -->patts(artifact dir glob patterns)

lrps[Input - Local repository path]

patts -->fa{2 - Find artifact dis from local repo path}
lrps -->fa

fa -->result(Output - list of artifact directories existed within the local repo path.)
Loading

Generating glob patterns

From a PackageURL, we can directly obtain the glob patterns representing the location of artifact dirs in a local repo. These glob patterns will be different between a maven PURL and a PYPI PURL.

Glob patterns matching on the repo path corresponding to the input PURL's type.

In Macaron (the main's Analyzer instance), we will store mappings between a PURL type (e.g maven) to its corresponding local repo path (if provided by the user). Right now, we only have maximum 2 entries:

  • maven maps to the maven local repo path
  • pypi maps to the python virtual env path

If the user doesn't provide a local repo path, there will be no entry for it in these mappings.

Using the input PURL's type, we will find the corresponding local repo path from this mapping.
Then we use the glob patterns obtained earlier to look for artifacts within this path. We don't raise error if we cannot find any artifact dir that matches any of the glob patterns.

Storing the discovered artifacts paths

They will be stored in the analyze context instance's dynamic_data object as a list of string.

Tasks

  • Add --local-maven-repo as CLI option.
  • Handle mounting .m2 depending on user provided --local-maven-repo into the container.
  • Add integration tests for invalid usages of --local-maven-repo
  • Add unit tests for run_macaron.sh adding --local-maven-repo behavior
  • Fix and issue with dumps-defaults command not being handled in run_macaron.sh
  • Obtain directories and files corresponding to a Python software component from virtual environment.
    • Add unit tests.
  • Obtain directories and files corresponding to a Java software component from the cached .m2.
    • Add unit tests.
  • Add tutorial - will be worked on later - Create a tutorial for using the local maven repo #936

@tromai tromai self-assigned this Sep 17, 2024
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 17, 2024
@tromai tromai force-pushed the 811-use-cached-artifacts-instead-of-downloading-them-when-possible branch from 4c95c95 to 7ac9e54 Compare September 24, 2024 04:55
@tromai tromai force-pushed the 811-use-cached-artifacts-instead-of-downloading-them-when-possible branch from 7ac9e54 to 0020c0d Compare December 3, 2024 23:50
@behnazh-w behnazh-w requested review from benmss and nicallen December 4, 2024 03:54
@tromai tromai marked this pull request as ready for review December 4, 2024 03:56
@tromai tromai requested a review from behnazh-w as a code owner December 4, 2024 03:56
@tromai tromai changed the title feat: obtain Java and Python artifacts from .m2 or Python virtual environment from input (WIP) feat: obtain Java and Python artifacts from .m2 or Python virtual environment from input Dec 4, 2024
src/macaron/__main__.py Outdated Show resolved Hide resolved
@tromai tromai force-pushed the 811-use-cached-artifacts-instead-of-downloading-them-when-possible branch from f5a4c66 to da0f514 Compare December 10, 2024 00:39
@tromai tromai force-pushed the 811-use-cached-artifacts-instead-of-downloading-them-when-possible branch from 65c9014 to 9a1da36 Compare December 18, 2024 01:43
@tromai tromai merged commit 12d8593 into staging Dec 18, 2024
9 checks passed
@tromai tromai deleted the 811-use-cached-artifacts-instead-of-downloading-them-when-possible branch December 18, 2024 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants