From 949b5de3a2f5426f08e12d30f38ee8de15281aec Mon Sep 17 00:00:00 2001 From: Nicolas Nobelis Date: Mon, 22 Jul 2024 10:47:57 +0200 Subject: [PATCH] chore(docker): Replace Bazel by Bazelisk Bazelisk is the rerommended way of installing Bazel ([1]). It has the benefit of honoring the .bazelversion file, that can be shipped with a project, to analyze the project with the correponding Bazel version ([2]). Bazelisk is installed in the ORT Docker image as the 'Bazel' executable, as recommanded ([3]). For projects without a '.bazelversion' file, USE_BAZEL_FALLBACK_VERSION (see [2]) is used to the default Bazel version 7.0.1, that ORT was using previously. [1]: https://bazel.build/install/bazelisk#installing_bazel [2]: https://github.com/bazelbuild/bazelisk?tab=readme-ov-file#how-does-bazelisk-know-which-bazel-version-to-run [3]: https://github.com/bazelbuild/bazelisk?tab=readme-ov-file#installation Signed-off-by: Nicolas Nobelis --- Dockerfile | 6 +++--- docker/versions.dockerfile | 2 +- plugins/package-managers/bazel/src/main/kotlin/Bazel.kt | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index a2546ed162d88..d4b1042dcf2cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -404,15 +404,15 @@ COPY --from=dotnetbuild /opt/dotnet /opt/dotnet # BAZEL FROM base as bazelbuild -ARG BAZEL_VERSION +ARG BAZELISK_VERSION ENV BAZEL_HOME=/opt/bazel RUN mkdir -p $BAZEL_HOME/bin \ && if [ "$(arch)" = "aarch64" ]; then \ - curl -L https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-linux-arm64 -o $BAZEL_HOME/bin/bazel; \ + curl -L https://github.com/bazelbuild/bazelisk/releases/download/v$BAZELISK_VERSION/bazelisk-linux-arm64 -o $BAZEL_HOME/bin/bazel; \ else \ - curl -L https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-linux-x86_64 -o $BAZEL_HOME/bin/bazel; \ + curl -L https://github.com/bazelbuild/bazelisk/releases/download/v$BAZELISK_VERSION/bazelisk-linux-amd64 -o $BAZEL_HOME/bin/bazel; \ fi \ && chmod a+x $BAZEL_HOME/bin/bazel diff --git a/docker/versions.dockerfile b/docker/versions.dockerfile index b6a8b4a843755..87002a887ca56 100644 --- a/docker/versions.dockerfile +++ b/docker/versions.dockerfile @@ -1,6 +1,6 @@ ARG ANDROID_CMD_VERSION=11076708 ARG ASKALONO_VERSION=0.4.6 -ARG BAZEL_VERSION=7.0.1 +ARG BAZELISK_VERSION=1.20.0 ARG BOWER_VERSION=1.8.14 ARG BOYTERLC_VERSION=1.3.1 ARG COCOAPODS_VERSION=1.15.2 diff --git a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt index 93e6e7b4e3c6e..228375940e69f 100644 --- a/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt +++ b/plugins/package-managers/bazel/src/main/kotlin/Bazel.kt @@ -59,6 +59,7 @@ import org.ossreviewtoolkit.utils.common.withoutPrefix import org.semver4j.RangesList import org.semver4j.RangesListFactory +private const val BAZEL_FALLBACK_VERSION = "7.0.1" private const val LOCKFILE_NAME = "MODULE.bazel.lock" class Bazel( @@ -84,7 +85,10 @@ class Bazel( args = args, workingDir = workingDir, // Disable the optional wrapper script under `tools/bazel`, to ensure the --version option works. - environment = environment + mapOf("BAZELISK_SKIP_WRAPPER" to "true") + environment = environment + mapOf( + "BAZELISK_SKIP_WRAPPER" to "true", + "USE_BAZEL_FALLBACK_VERSION" to BAZEL_FALLBACK_VERSION + ) ) override fun transformVersion(output: String) = output.removePrefix("bazel ")