From 21174ee9727d0af554b45bd5bf835195a3f69c65 Mon Sep 17 00:00:00 2001 From: Oliver Pajonk Date: Wed, 23 Jul 2025 11:56:52 +0000 Subject: [PATCH 1/3] disable autoPull for git lfs this sometimes causes errors when starting the container --- src/s-core-devcontainer/.devcontainer/devcontainer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/s-core-devcontainer/.devcontainer/devcontainer.json b/src/s-core-devcontainer/.devcontainer/devcontainer.json index 17fb611..21899af 100644 --- a/src/s-core-devcontainer/.devcontainer/devcontainer.json +++ b/src/s-core-devcontainer/.devcontainer/devcontainer.json @@ -11,6 +11,7 @@ }, "ghcr.io/devcontainers/features/git-lfs": { // Installs the latest version from the Distribution + "autoPull": "false" // do not automatically pull LFS files when creating the container }, "ghcr.io/devcontainers/features/common-utils": { // Installs latest version from the Distribution From fd625275784085098d155dab028e39fe99005e2b Mon Sep 17 00:00:00 2001 From: Oliver Pajonk Date: Wed, 23 Jul 2025 11:57:55 +0000 Subject: [PATCH 2/3] split out Bazel cache setup to run earlier in the lifecycle --- .../.devcontainer/s-core-local/devcontainer-feature.json | 1 + .../.devcontainer/s-core-local/post_create_command.sh | 3 --- .../.devcontainer/s-core-local/update_content_command.sh | 5 +++++ 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100755 src/s-core-devcontainer/.devcontainer/s-core-local/update_content_command.sh diff --git a/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json b/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json index 3930707..4c8deab 100644 --- a/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json +++ b/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json @@ -30,6 +30,7 @@ "description": "sha256sums of Bazel Compile Commands to verify the download; format: :;:;..." } }, + "updateContentCommand": "/devcontainer/features/s-core-local/update_content_command.sh", "postCreateCommand": "/devcontainer/features/s-core-local/post_create_command.sh", "mounts": [ { "source": "${localEnv:HOME}/.cache/bazel", // default Bazel cache directory diff --git a/src/s-core-devcontainer/.devcontainer/s-core-local/post_create_command.sh b/src/s-core-devcontainer/.devcontainer/s-core-local/post_create_command.sh index 0152adf..0da43c3 100755 --- a/src/s-core-devcontainer/.devcontainer/s-core-local/post_create_command.sh +++ b/src/s-core-devcontainer/.devcontainer/s-core-local/post_create_command.sh @@ -4,9 +4,6 @@ set -euo pipefail # Configure Bazel to use the cache directory that is mounted from the host echo "startup --output_user_root=/var/cache/bazel" >> ~/.bazelrc -# ensure that the Bazel cache directory has the correct permissions -sudo chown -R "$(id -un):$(id -gn)" /var/cache/bazel - # Configure clangd to remove the -fno-canonical-system-headers flag, which is # GCC-specific. If not done, there is an annoying error message on the first # line of every C++ file when being displayed in Visual Studio Code. diff --git a/src/s-core-devcontainer/.devcontainer/s-core-local/update_content_command.sh b/src/s-core-devcontainer/.devcontainer/s-core-local/update_content_command.sh new file mode 100755 index 0000000..360a7c6 --- /dev/null +++ b/src/s-core-devcontainer/.devcontainer/s-core-local/update_content_command.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ensure that the Bazel cache directory has the correct permissions +sudo chown -R "$(id -un):$(id -gn)" /var/cache/bazel From 8eaa6a52b2b433ad26b8d07dfd16cdf53f9dc31f Mon Sep 17 00:00:00 2001 From: Oliver Pajonk Date: Thu, 24 Jul 2025 07:40:05 +0000 Subject: [PATCH 3/3] optimize the lifecycle hooks - all can run quite early in onCreateCommand, since they just do static initialization that does not need to change afterwards - better handle the case where /var/cache/bazel is mounted from the host --- .../s-core-local/devcontainer-feature.json | 3 +- .../s-core-local/on_create_command.sh | 33 +++++++++++++++++++ .../s-core-local/post_create_command.sh | 15 --------- .../s-core-local/update_content_command.sh | 5 --- 4 files changed, 34 insertions(+), 22 deletions(-) create mode 100755 src/s-core-devcontainer/.devcontainer/s-core-local/on_create_command.sh delete mode 100755 src/s-core-devcontainer/.devcontainer/s-core-local/post_create_command.sh delete mode 100755 src/s-core-devcontainer/.devcontainer/s-core-local/update_content_command.sh diff --git a/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json b/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json index 4c8deab..258723d 100644 --- a/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json +++ b/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json @@ -30,8 +30,7 @@ "description": "sha256sums of Bazel Compile Commands to verify the download; format: :;:;..." } }, - "updateContentCommand": "/devcontainer/features/s-core-local/update_content_command.sh", - "postCreateCommand": "/devcontainer/features/s-core-local/post_create_command.sh", + "onCreateCommand": "/devcontainer/features/s-core-local/on_create_command.sh", "mounts": [ { "source": "${localEnv:HOME}/.cache/bazel", // default Bazel cache directory "target": "/var/cache/bazel", diff --git a/src/s-core-devcontainer/.devcontainer/s-core-local/on_create_command.sh b/src/s-core-devcontainer/.devcontainer/s-core-local/on_create_command.sh new file mode 100755 index 0000000..5f1092d --- /dev/null +++ b/src/s-core-devcontainer/.devcontainer/s-core-local/on_create_command.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ensure that the Bazel cache directory exists +if [ ! -d /var/cache/bazel ]; then + echo "Creating /var/cache/bazel directory..." + # yes, mkdir -p is idempotent, but we want to see the log message + mkdir -p /var/cache/bazel +fi + +# If /var/cache/bazel is not a mountpoint, we assume it is a container-local cache. +# This is the case in codespaces, for example. +# Here, we must ensure that the directory has the correct permissions +# so that Bazel can write to it. +if ! mountpoint -q /var/cache/bazel; then + echo "/var/cache/bazel is not mounted. Using container-local cache and setting permissions." + chown -R "$(id -un):$(id -gn)" /var/cache/bazel +fi + +# Configure Bazel to use the cache directory +# This way, Bazel can re-use an existing cache on the host machine, if mounted. +# Note that in some scenarios (like codespaces), it is not and hence resides in the container. +echo "startup --output_user_root=/var/cache/bazel" >> ~/.bazelrc + +# Configure clangd to remove the -fno-canonical-system-headers flag, which is +# GCC-specific. If not done, there is an annoying error message on the first +# line of every C++ file when being displayed in Visual Studio Code. +mkdir -p ~/.config/clangd +cat > ~/.config/clangd/config.yaml <> ~/.bazelrc - -# Configure clangd to remove the -fno-canonical-system-headers flag, which is -# GCC-specific. If not done, there is an annoying error message on the first -# line of every C++ file when being displayed in Visual Studio Code. -mkdir -p ~/.config/clangd -cat > ~/.config/clangd/config.yaml <