Skip to content

Commit

Permalink
Merge pull request #51 from leanix/feature/CID-1864/enhance-dev-mode
Browse files Browse the repository at this point in the history
CID-1864 Enhance Dev Mode
  • Loading branch information
geoandri authored Aug 22, 2023
2 parents f06f879 + 1cca48b commit e89bb0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The second `-v` param is the path to temporary folder that the `vsm-sbom-booster

`ANALYSIS_TIMEOUT`(optional): The timeout, in minutes, that is used to force kill container workers working on analyzing the repository. There are cases that we need to force kill containers with slow progress to free up resources. Default: 30

`DEV_MODE`(optional): This is a flag to enable/disable the dev mode. When enabled, all logs from ORT containers will be preserved in the temp folder location. The processing of each repository consists of three separate phases (download, analyze and generate_sbom) that are facilitated by the ORT software. The produced logs are saved in the temp folder using the `<repository_name>_<phase>.txt` naming pattern.This is useful for debugging purposes. Default: false
`DEV_MODE`(optional): This is a flag to enable/disable the dev mode. When enabled, all logs from ORT containers will be preserved in the temp folder location and the project folders will be retained. Additionally, the logging level for the ORT containers will be set to DEBUG. The processing of each repository consists of three separate phases (download, analyze and generate_sbom) that are facilitated by the ORT software. The produced logs are saved in the temp folder using the `<repository_name>_<phase>.txt` naming pattern.This is useful for debugging purposes. Default: false

#### LeanIX configs

Expand Down
13 changes: 12 additions & 1 deletion src/main/kotlin/net/leanix/vsm/sbomBooster/service/OrtService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class OrtService(
}

fun downloadProject(projectUrl: String, username: String, gitToken: String): String {
val downloadFolder = "downloaded_${List(10) { charPool.random() }.joinToString("")}"
val downloadFolder = "${projectUrl.substringAfterLast("/")}_${List(10) { charPool.random() }.joinToString("")}"

val downloadProcessBuilder = ProcessBuilder(
"docker",
Expand All @@ -38,6 +38,7 @@ class OrtService(
"-e", "ORT_HTTP_PASSWORD=$gitToken",
"-v", "${Paths.get(propertiesConfiguration.mountedVolume).toAbsolutePath()}:/project",
"leanixacrpublic.azurecr.io/ort",
loggingParameter(),
"download",
"--project-url", projectUrl,
"-o", "/project/$downloadFolder"
Expand All @@ -60,6 +61,7 @@ class OrtService(
"${Paths.get(propertiesConfiguration.mountedVolume).toAbsolutePath()}" +
"/$downloadFolder:/downloadedProject",
"leanixacrpublic.azurecr.io/ort",
loggingParameter(),
"-P", "ort.analyzer.allowDynamicVersions=true",
"analyze",
"-i", "/downloadedProject",
Expand All @@ -81,6 +83,7 @@ class OrtService(
"${Paths.get(propertiesConfiguration.mountedVolume).toAbsolutePath()}" +
"/$downloadFolder:/downloadedProject",
"leanixacrpublic.azurecr.io/ort",
loggingParameter(),
"report",
"-f", "CycloneDX",
"-i", "/downloadedProject/analyzer-result.yml",
Expand Down Expand Up @@ -115,4 +118,12 @@ class OrtService(
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT)
}
}

private fun loggingParameter(): String {
return if (propertiesConfiguration.devMode) {
"--debug"
} else {
"--warn"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ class ProcessService(
} catch (e: Exception) {
logger.error(e.message)
} finally {
ortService.deleteDownloadedFolder(downloadedFolder)
logger.info("Finished deleting temp folder $downloadedFolder.")
if (!propertiesConfiguration.devMode) {
logger.info("Beginning to delete folder $downloadedFolder.")
ortService.deleteDownloadedFolder(downloadedFolder)
logger.info("Finished deleting temp folder $downloadedFolder.")
}
}
}

Expand Down

0 comments on commit e89bb0a

Please sign in to comment.