|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Copy feature sources and tests to expected location |
| 5 | +FEATURES_DIR="/devcontainer/features" |
| 6 | +SCRIPT_PATH=$(readlink -f "$0") |
| 7 | +SCRIPT_DIR=$(dirname -- "${SCRIPT_PATH}") |
| 8 | +mkdir -p "${FEATURES_DIR}" |
| 9 | +COPY_TARGET="${FEATURES_DIR}/$(basename "${SCRIPT_DIR%%_*}")" |
| 10 | +cp -R "${SCRIPT_DIR}" "${COPY_TARGET}" |
| 11 | +rm -f "${COPY_TARGET}/devcontainer-features.env" "${COPY_TARGET}/devcontainer-features-install.sh" |
| 12 | + |
| 13 | +DEBIAN_FRONTEND=noninteractive |
| 14 | + |
| 15 | +# Read tool versions + metadata into environment variables |
| 16 | +. /devcontainer/features/s-core-local/versions.sh /devcontainer/features/bazel/versions.yaml |
| 17 | + |
| 18 | +ARCHITECTURE=$(dpkg --print-architecture) |
| 19 | + |
| 20 | +apt-get update |
| 21 | + |
| 22 | +# INSTALL CONTAINER BUILD DEPENDENCIES |
| 23 | +# Container build dependencies are not pinned, since they are removed anyway after container creation. |
| 24 | +apt-get install apt-transport-https -y |
| 25 | + |
| 26 | +# Bazelisk, directly from GitHub |
| 27 | +# Using the existing devcontainer feature is not optimal: |
| 28 | +# - it does not check the SHA256 checksum of the downloaded file |
| 29 | +# - it cannot pre-install a specific version of Bazel, or prepare bash completion |
| 30 | +BAZELISK_VARIANT="amd64" |
| 31 | +SHA256SUM="${bazelisk_amd64_sha256}" |
| 32 | +if [ "${ARCHITECTURE}" = "arm64" ]; then |
| 33 | + BAZELISK_VARIANT="arm64" |
| 34 | + SHA256SUM="${bazelisk_arm64_sha256}" |
| 35 | +fi |
| 36 | +curl -L "https://github.com/bazelbuild/bazelisk/releases/download/v${bazelisk_version}/bazelisk-${BAZELISK_VARIANT}.deb" -o /tmp/bazelisk.deb |
| 37 | +echo "${SHA256SUM} /tmp/bazelisk.deb" | sha256sum -c - || exit -1 |
| 38 | +apt-get install -y --no-install-recommends --fix-broken /tmp/bazelisk.deb |
| 39 | +rm /tmp/bazelisk.deb |
| 40 | + |
| 41 | +# Pre-install a fixed Bazel version, setup the bash command completion |
| 42 | +export USE_BAZEL_VERSION=${bazel_version} |
| 43 | +# bazelisk downloads Bazel into the home directory of the user running the command |
| 44 | +# lets assume there is only one user in the devcontainer |
| 45 | +su $(ls /home) -c "bazel help completion bash > /tmp/bazel-complete.bash" |
| 46 | +mkdir -p /etc/bash_completion.d |
| 47 | +mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash |
| 48 | +sh -c "echo 'INSTALLED_BAZEL_VERSION=${bazel_version}' >> /devcontainer/features/bazel/bazel_setup.sh" |
| 49 | + |
| 50 | +# Configure Bazel to use system trust store for SSL/TLS connections |
| 51 | +# This is required for corporate environments with custom CA certificates |
| 52 | +echo 'startup --host_jvm_args=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts --host_jvm_args=-Djavax.net.ssl.trustStorePassword=changeit' >> /etc/bazel.bazelrc |
| 53 | + |
| 54 | +# Buildifier, directly from GitHub (apparently no APT repository available) |
| 55 | +# The version is pinned to a specific release, and the SHA256 checksum is provided by the devcontainer-features.json file. |
| 56 | +BUILDIFIER_VARIANT="amd64" |
| 57 | +SHA256SUM="${buildifier_amd64_sha256}" |
| 58 | +if [ "${ARCHITECTURE}" = "arm64" ]; then |
| 59 | + BUILDIFIER_VARIANT="arm64" |
| 60 | + SHA256SUM="${buildifier_arm64_sha256}" |
| 61 | +fi |
| 62 | +curl -L "https://github.com/bazelbuild/buildtools/releases/download/v${buildifier_version}/buildifier-linux-${BUILDIFIER_VARIANT}" -o /usr/local/bin/buildifier |
| 63 | +echo "${SHA256SUM} /usr/local/bin/buildifier" | sha256sum -c - || exit -1 |
| 64 | +chmod +x /usr/local/bin/buildifier |
| 65 | + |
| 66 | +# Starlark Language Server, directly from GitHub (apparently no APT repository available) |
| 67 | +STARPLS_VARIANT="amd64" |
| 68 | +SHA256SUM="${starpls_amd64_sha256}" |
| 69 | +if [ "${ARCHITECTURE}" = "arm64" ]; then |
| 70 | + STARPLS_VARIANT="aarch64" |
| 71 | + SHA256SUM="${starpls_arm64_sha256}" |
| 72 | +fi |
| 73 | +curl -L "https://github.com/withered-magic/starpls/releases/download/v${starpls_version}/starpls-linux-${STARPLS_VARIANT}" -o /usr/local/bin/starpls |
| 74 | +echo "${SHA256SUM} /usr/local/bin/starpls" | sha256sum -c - || exit -1 |
| 75 | +chmod +x /usr/local/bin/starpls |
| 76 | + |
| 77 | +# Code completion for C++ code of Bazel projects |
| 78 | +# (see https://github.com/kiron1/bazel-compile-commands) |
| 79 | +source /etc/lsb-release |
| 80 | +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 |
| 81 | +# Extract correct sha256 for current DISTRIB_CODENAME and check |
| 82 | +SHA256SUM="${bazel_compile_commands_amd64_sha256}" |
| 83 | +if [ "${ARCHITECTURE}" = "arm64" ]; then |
| 84 | + SHA256SUM="${bazel_compile_commands_arm64_sha256}" |
| 85 | +fi |
| 86 | +echo "${SHA256SUM} /tmp/bazel-compile-commands.deb" | sha256sum -c - || exit -1 |
| 87 | +apt-get install -y --no-install-recommends --fix-broken /tmp/bazel-compile-commands.deb |
| 88 | +rm /tmp/bazel-compile-commands.deb |
| 89 | + |
| 90 | +# Cleanup |
| 91 | +# REMOVE CONTAINER BUILD DEPENDENCIES |
| 92 | +apt-get remove --purge -y apt-transport-https |
| 93 | +apt-get autoremove -y |
| 94 | +apt-get clean |
| 95 | +rm -rf /var/lib/apt/lists/* |
0 commit comments