@@ -15,6 +15,8 @@ DEBIAN_FRONTEND=noninteractive
1515# Read tool versions + metadata into environment variables
1616. /devcontainer/features/s-core-local/versions.sh
1717
18+ ARCHITECTURE=$( dpkg --print-architecture)
19+
1820apt-get update
1921
2022# INSTALL CONTAINER BUILD DEPENDENCIES
@@ -28,37 +30,62 @@ apt-get install -y graphviz="${graphviz_version}*"
2830# Protobuf compiler, via APT (needed by FEO)
2931apt-get install -y protobuf-compiler=" ${protobuf_compiler_version} *"
3032
31- # Bazel, via APT
32- # - ghcr.io/devcontainers-community/features/bazel uses bazelisk, which has a few problems:
33- # - It does not install bash autocompletion.
34- # - The bazel version is not pinned, which is required to be reproducible and to have coordinated, tested tool updates.
35- # - In general, pre-built containers *shall not* download "more tools" from the internet.
36- # This is an operational risk (security, availability); it makes the build non-reproducible,
37- # and it prevents the container from working in air-gapped environments.
38- curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel-archive-keyring.gpg
39- mv bazel-archive-keyring.gpg /usr/share/keyrings
40- echo " deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
41- apt-get update
42- apt-get install -y bazel=${bazel_version}
33+ # Bazelisk, directly from GitHub
34+ # Using the existing devcontainer feature is not optimal:
35+ # - it does not check the SHA256 checksum of the downloaded file
36+ # - it cannot pre-install a specific version of Bazel, or prepare bash completion
37+ BAZELISK_VARIANT=" amd64"
38+ SHA256SUM=" ${bazelisk_amd64_sha256} "
39+ if [ " ${ARCHITECTURE} " = " arm64" ]; then
40+ BAZELISK_VARIANT=" arm64"
41+ SHA256SUM=" ${bazelisk_arm64_sha256} "
42+ fi
43+ curl -L " https://github.com/bazelbuild/bazelisk/releases/download/v${bazelisk_version} /bazelisk-${BAZELISK_VARIANT} .deb" -o /tmp/bazelisk.deb
44+ echo " ${SHA256SUM} /tmp/bazelisk.deb" | sha256sum -c - || exit -1
45+ apt-get install -y --no-install-recommends --fix-broken /tmp/bazelisk.deb
46+ rm /tmp/bazelisk.deb
47+
48+ # Pre-install a fixed Bazel version, setup the bash command completion
49+ export USE_BAZEL_VERSION=${bazel_version}
50+ bazel help completion bash > /tmp/bazel-complete.bash
51+ ls -lah /tmp/bazel-complete.bash
52+ mkdir -p /etc/bash_completion.d
53+ mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash
54+ sh -c " echo 'export USE_BAZEL_VERSION=${bazel_version} ' >> /etc/profile.d/bazel.sh"
4355
4456# Buildifier, directly from GitHub (apparently no APT repository available)
4557# The version is pinned to a specific release, and the SHA256 checksum is provided by the devcontainer-features.json file.
46- curl -L " https://github.com/bazelbuild/buildtools/releases/download/v${buildifier_version} /buildifier-linux-amd64" -o /usr/local/bin/buildifier
47- echo " ${buildifier_amd64_sha256} /usr/local/bin/buildifier" | sha256sum -c - || exit -1
58+ BUILDIFIER_VARIANT=" amd64"
59+ SHA256SUM=" ${buildifier_amd64_sha256} "
60+ if [ " ${ARCHITECTURE} " = " arm64" ]; then
61+ BUILDIFIER_VARIANT=" arm64"
62+ SHA256SUM=" ${buildifier_arm64_sha256} "
63+ fi
64+ curl -L " https://github.com/bazelbuild/buildtools/releases/download/v${buildifier_version} /buildifier-linux-${BUILDIFIER_VARIANT} " -o /usr/local/bin/buildifier
65+ echo " ${SHA256SUM} /usr/local/bin/buildifier" | sha256sum -c - || exit -1
4866chmod +x /usr/local/bin/buildifier
4967
5068# Starlark Language Server, directly from GitHub (apparently no APT repository available)
51- curl -L " https://github.com/withered-magic/starpls/releases/download/v${starpls_version} /starpls-linux-amd64" -o /usr/local/bin/starpls
52- echo " ${starpls_amd64_sha256} /usr/local/bin/starpls" | sha256sum -c - || exit -1
69+ STARPLS_VARIANT=" amd64"
70+ SHA256SUM=" ${starpls_amd64_sha256} "
71+ if [ " ${ARCHITECTURE} " = " arm64" ]; then
72+ STARPLS_VARIANT=" aarch64"
73+ SHA256SUM=" ${starpls_arm64_sha256} "
74+ fi
75+ curl -L " https://github.com/withered-magic/starpls/releases/download/v${starpls_version} /starpls-linux-${STARPLS_VARIANT} " -o /usr/local/bin/starpls
76+ echo " ${SHA256SUM} /usr/local/bin/starpls" | sha256sum -c - || exit -1
5377chmod +x /usr/local/bin/starpls
5478
5579# Code completion for C++ code of Bazel projects
5680# (see https://github.com/kiron1/bazel-compile-commands)
57- # The version is pinned to a specific release, and the SHA256 checksum is provided by the devcontainer-features.json file.
5881source /etc/lsb-release
59- curl -L " https://github.com/kiron1/bazel-compile-commands/releases/download/v${bazel_compile_commands_version} /bazel-compile-commands_${bazel_compile_commands_version} -${DISTRIB_CODENAME} _amd64 .deb" -o /tmp/bazel-compile-commands.deb
82+ curl -L " https://github.com/kiron1/bazel-compile-commands/releases/download/v${bazel_compile_commands_version} /bazel-compile-commands_${bazel_compile_commands_version} -${DISTRIB_CODENAME} _ ${ARCHITECTURE} .deb" -o /tmp/bazel-compile-commands.deb
6083# Extract correct sha256 for current DISTRIB_CODENAME and check
61- echo " ${bazel_compile_commands_amd64_sha256} /tmp/bazel-compile-commands.deb" | sha256sum -c - || exit -1
84+ SHA256SUM=" ${bazel_compile_commands_amd64_sha256} "
85+ if [ " ${ARCHITECTURE} " = " arm64" ]; then
86+ SHA256SUM=" ${bazel_compile_commands_arm64_sha256} "
87+ fi
88+ echo " ${SHA256SUM} /tmp/bazel-compile-commands.deb" | sha256sum -c - || exit -1
6289apt-get install -y --no-install-recommends --fix-broken /tmp/bazel-compile-commands.deb
6390rm /tmp/bazel-compile-commands.deb
6491
0 commit comments