From e80abee80ef478b8bd69a17e1f7a0334bd92a41b Mon Sep 17 00:00:00 2001 From: Wolfgang Klenk Date: Mon, 16 Dec 2024 16:50:12 +0100 Subject: [PATCH] fix(scancode): Ensure to find license texts in the Docker image Dump the ScanCode license texts to directory /opt/scancode-license-data when creating the ORT docker container. Use this directory as fallback option if the ScanCode license texts cannot be located by the existing heuristic algorithm. Fixes #8147. Signed-off-by: Wolfgang Klenk --- Dockerfile | 10 ++++++++++ utils/spdx/src/main/kotlin/Utils.kt | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4fa0b05d3131c..2c6bca2fe826c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -157,6 +157,11 @@ RUN ARCH=$(arch | sed s/aarch64/arm64/) \ rm requirements.txt; \ fi +# Extract ScanCode license texts to a directory. +RUN scancode-license-data --path /opt/scancode-license-data \ + && find /opt/scancode-license-data -type f -not -name "*.LICENSE" -exec rm -f {} + \ + && rm -rf /opt/scancode-license-data/static + RUN pip install --no-cache-dir -U \ pip=="$PIPTOOL_VERSION" \ wheel \ @@ -171,6 +176,9 @@ RUN pip install --no-cache-dir -U \ FROM scratch AS python COPY --from=pythonbuild /opt/python /opt/python +FROM scratch as scancode-license-data +COPY --from=pythonbuild /opt/scancode-license-data /opt/scancode-license-data + #------------------------------------------------------------------------ # NODEJS - Build NodeJS as a separate component with nvm FROM base AS nodejsbuild @@ -493,6 +501,8 @@ ENV GEM_HOME=/var/tmp/gem ENV PATH=$PATH:$RBENV_ROOT/bin:$RBENV_ROOT/shims:$RBENV_ROOT/plugins/ruby-install/bin COPY --from=ruby --chown=$USER:$USER $RBENV_ROOT $RBENV_ROOT +COPY --from=scancode-license-data --chown=$USER:$USER /opt/scancode-license-data /opt/scancode-license-data + #------------------------------------------------------------------------ # Container with all supported package managers. FROM minimal-tools as all-tools diff --git a/utils/spdx/src/main/kotlin/Utils.kt b/utils/spdx/src/main/kotlin/Utils.kt index 876f8ecf257f9..0d799de9f53c0 100644 --- a/utils/spdx/src/main/kotlin/Utils.kt +++ b/utils/spdx/src/main/kotlin/Utils.kt @@ -49,7 +49,8 @@ val scanCodeLicenseTextDir by lazy { val pythonBinDir = listOf("bin", "Scripts") val scanCodeBaseDir = scanCodeExeDir?.takeUnless { it.name in pythonBinDir } ?: scanCodeExeDir?.parentFile - scanCodeBaseDir?.walkTopDown()?.find { it.isDirectory && it.endsWith("licensedcode/data/licenses") } + scanCodeBaseDir?.walkTopDown()?.find { it.isDirectory && it.endsWith("licensedcode/data/licenses") } ?: + File("/opt/scancode-license-data").takeIf { it.isDirectory } } /**