diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 72db3cd..9fdf340 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,9 @@ "image": "mcr.microsoft.com/devcontainers/javascript-node:0-18", "features": { "ghcr.io/devcontainers/features/git:1": {}, - "ghcr.io/devcontainers/features/git-lfs:1": {}, + "ghcr.io/devcontainers/features/git-lfs:1": { + "autoPull": "false" // do not automatically pull LFS files when creating the container + }, "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "ghcr.io/devcontainers-extra/features/pre-commit:2": { "version": "4.2.0" diff --git a/README.md b/README.md index f5889ee..a984f10 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,12 @@ It should contain the following: ````json { "name": "eclipse-s-core", - "image": "ghcr.io/eclipse-score/devcontainer:", - "initializeCommand": "mkdir -p ${localEnv:HOME}/.cache/bazel" + "image": "ghcr.io/eclipse-score/devcontainer:" } ```` The `` must be a [valid, published release](https://github.com/eclipse-score/devcontainer/tags). You can also use `latest` as `` to automatically follow the `main` branch - but be aware that this can result in undesired updates. -The `initializeCommand` is required to ensure the default Bazel cache directory exists on your host system. To start using the container, click the **Reopen in Container** button when prompted by Visual Studio Code: 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 2206a3e..66e185e 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 @@ -36,9 +36,9 @@ "postCreateCommand": "if [ -f .bazelversion ] && [ \"$(cat .bazelversion)\" != \"$(dpkg --list | grep 'ii bazel ' | awk '{print $3}')\" ]; then sudo apt-get update && sudo apt-get install -y --allow-downgrades bazel=$(cat .bazelversion); fi", "mounts": [ { - "source": "${localEnv:HOME}/.cache/bazel", // default Bazel cache directory + "source": "eclipse-s-core-bazel-cache", "target": "/var/cache/bazel", - "type": "bind" + "type": "volume" } ] } 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 index 578464c..d8de6ee 100755 --- 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 @@ -1,15 +1,24 @@ #!/usr/bin/env bash set -euo pipefail -# In some scenarios (like CodeSpaces), apparently not all (or even any?) -# bind mounts to the host are done and /var/cache/bazel does not exist. -# See devcontainer-feature.json, where this mount is defined. -# Hence, if /var/cache/bazel exists, it was mounted from the host, -# and we configure Bazel to use /var/cache/bazel as cache. -# This way, Bazel re-uses a bind-mounted cache from the host machine, while -# still using the default cache (${HOME}/.cache/bazel) if no such cache exists. +# Enable persistent Bazel cache +# +# Usually, a volume is mounted to /var/cache/bazel (see +# devcontainer-feature.json). This shall be used as Bazel cache, which is then +# preserved across container re-starts. Since the volume has a fixed +# name ("eclipse-s-core-bazel-cache"), it is even used across all Eclipse +# S-CORE DevContainer instances. if [ -d /var/cache/bazel ]; then - echo "Configuring Bazel to use /var/cache/bazel as cache..." + echo "Bazel Cache: /var/cache/bazel exists. Checking ownership and configuring Bazel to use it as cache..." + current_owner_group=$(stat -c "%U:%G" /var/cache/bazel) + current_user_group="$(id -un):$(id -gn)" + if [ "${current_owner_group}" = "${current_user_group}" ]; then + echo "Bazel Cache: /var/cache/bazel is already owned by ${current_user_group}. " + else + echo "Bazel Cache: /var/cache/bazel is not owned by ${current_owner_group}. Setting ownership (this may take a few seconds) ..." + sudo chown -R "${current_user_group}" /var/cache/bazel + fi + echo "Bazel Cache: Configuring Bazel to use /var/cache/bazel as cache..." echo "startup --output_user_root=/var/cache/bazel" >> ~/.bazelrc fi