Skip to content

Commit

Permalink
chore(docker): Replace Bazel by Bazelisk
Browse files Browse the repository at this point in the history
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 <nicolas.nobelis@bosch.com>
  • Loading branch information
nnobelis authored and fviernau committed Jul 26, 2024
1 parent 2839a76 commit 949b5de
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docker/versions.dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion plugins/package-managers/bazel/src/main/kotlin/Bazel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 ")
Expand Down

0 comments on commit 949b5de

Please sign in to comment.