Skip to content

Commit 72f458e

Browse files
opajonklurtz
andauthored
Add aarch64 support to DevContainer (#29)
Co-authored-by: Oliver Pajonk <opajonk@users.noreply.github.com> Co-authored-by: Lutz Reinhardt <lutz.reinhardt@elektrobit.com>
1 parent fe3588c commit 72f458e

13 files changed

Lines changed: 138 additions & 39 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/usr/bin/env bash
22
npm install -g @devcontainers/cli
33
pre-commit install
4+
5+
scripts/create_builder.sh

.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
# Check
4242
pre-commit run --show-diff-on-failure --color=always --all-files || exit -1
4343
44+
# Create builder for multi-arch builds
45+
./scripts/create_builder.sh
46+
4447
# Build
4548
./scripts/build.sh
4649
@@ -58,4 +61,4 @@ jobs:
5861
runCmd: |
5962
# manually login to ghcr.io for publishing
6063
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
61-
./scripts/publish.sh "latest"
64+
./scripts/publish.sh "main"

.github/workflows/release.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
# Check
3737
pre-commit run --show-diff-on-failure --color=always --all-files || exit -1
3838
39+
# Create builder for multi-arch builds
40+
./scripts/create_builder.sh
41+
3942
# Build
4043
./scripts/build.sh
4144
@@ -53,4 +56,4 @@ jobs:
5356
# manually login to ghcr.io for publishing
5457
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
5558
# Note: "${{ github.ref_name }}" will be the tag name, e.g., "1.0.0"
56-
./scripts/publish.sh "${{ github.ref_name }}"
59+
./scripts/publish.sh "${{ github.ref_name }}" "latest"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ It should contain the following:
2929
````
3030

3131
The `<version>` must be a [valid, published release](https://github.com/eclipse-score/devcontainer/tags).
32-
You can also use `latest` as `<version>` to automatically follow the `main` branch - but be aware that this can result in undesired updates.
32+
You can also use `main` as `<version>` to automatically follow the `main` branch, and `latest` to follow release tags - but be aware that this can result in undesired updates.
3333

3434
To start using the container, click the **Reopen in Container** button when prompted by Visual Studio Code:
3535

scripts/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
22
set -euxo pipefail
33

4-
devcontainer build --workspace-folder src/s-core-devcontainer --image-name ghcr.io/eclipse-score/devcontainer:latest --cache-from ghcr.io/eclipse-score/devcontainer
4+
devcontainer build --platform linux/aarch64 --workspace-folder src/s-core-devcontainer --image-name ghcr.io/eclipse-score/devcontainer --cache-from ghcr.io/eclipse-score/devcontainer
5+
devcontainer build --platform linux/amd64 --workspace-folder src/s-core-devcontainer --image-name ghcr.io/eclipse-score/devcontainer --cache-from ghcr.io/eclipse-score/devcontainer

scripts/create_builder.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
docker buildx create --name multiarch --driver docker-container --use

scripts/publish.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/usr/bin/env bash
22
set -euxo pipefail
33

4-
TAG="${1:-latest}"
5-
6-
if [[ "$TAG" != "latest" ]]; then
7-
docker tag "ghcr.io/eclipse-score/devcontainer:latest" "ghcr.io/eclipse-score/devcontainer:${TAG}"
4+
IMAGES=("--image-name \"ghcr.io/eclipse-score/devcontainer:main\"")
5+
if [ "$#" -gt 0 ]; then
6+
IMAGES=()
7+
for arg in "$@"; do
8+
IMAGES+=("--image-name \"ghcr.io/eclipse-score/devcontainer:${arg}\"")
9+
done
810
fi
911

10-
docker push "ghcr.io/eclipse-score/devcontainer:${TAG}"
12+
DEVCONTAINER_CALL="devcontainer build --push --workspace-folder src/s-core-devcontainer --cache-from ghcr.io/eclipse-score/devcontainer"
13+
14+
for IMAGE in "${IMAGES[@]}"; do
15+
DEVCONTAINER_CALL+=" $IMAGE"
16+
done
17+
18+
eval "$DEVCONTAINER_CALL --platform linux/aarch64"
19+
eval "$DEVCONTAINER_CALL --platform linux/amd64"

src/s-core-devcontainer/.devcontainer/devcontainer.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@
4242
},
4343
"./s-core-local": {}
4444
},
45+
"overrideFeatureInstallOrder": [
46+
// this order makes it more convenient to develop the s-core-local feature, since it will be installed last
47+
// which means changes to it will be applied without needing to rebuild all other features
48+
"ghcr.io/devcontainers/features/git",
49+
"ghcr.io/devcontainers/features/git-lfs",
50+
"ghcr.io/devcontainers/features/common-utils",
51+
"ghcr.io/devcontainers-community/features/llvm",
52+
"ghcr.io/devcontainers/features/rust",
53+
"ghcr.io/devcontainers/features/python",
54+
"./s-core-local"
55+
],
4556
"remoteUser": "vscode",
46-
"initializeCommand": "mkdir -p ${localEnv:HOME}/.cache/bazel",
4757
"customizations": {
4858
"vscode": {
4959
"extensions": [

src/s-core-devcontainer/.devcontainer/s-core-local/install.sh

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1820
apt-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)
2931
apt-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
4866
chmod +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
5377
chmod +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.
5881
source /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
6289
apt-get install -y --no-install-recommends --fix-broken /tmp/bazel-compile-commands.deb
6390
rm /tmp/bazel-compile-commands.deb
6491

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4-
if [ -f .bazelversion ] && [ "$(cat .bazelversion)" != "$(dpkg --list | grep 'ii bazel ' | awk '{print $3}')" ]; then
5-
sudo apt-get update && sudo apt-get install -y --allow-downgrades bazel=$(cat .bazelversion)
4+
if [ -f .bazelversion ] && [ "$(cat .bazelversion)" != "$(bazel version | grep 'Build label:' | awk '{print $3}')" ]; then
5+
# Pre-install the matching Bazel version, setup the bash command completion
6+
USE_BAZEL_VERSION=$(cat .bazelversion)
7+
bazel help completion bash > /tmp/bazel-complete.bash
8+
sudo mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash
9+
sudo sed -i '/^USE_BAZEL_VERSION=/c\USE_BAZEL_VERSION=${USE_BAZEL_VERSION}' /etc/profile.d/bazel.sh || true
610
fi

0 commit comments

Comments
 (0)