Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ It should contain the following:
````json
{
"name": "eclipse-s-core",
"image": "ghcr.io/eclipse-score/devcontainer:<version>",
"initializeCommand": "mkdir -p ${localEnv:HOME}/.cache/bazel"
"image": "ghcr.io/eclipse-score/devcontainer:<version>"
}
````

The `<version>` must be a [valid, published release](https://github.com/eclipse-score/devcontainer/tags).
You can also use `latest` as `<version>` 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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down