From ae887b1eb91bbce5de8f4c8787946acc9af2e384 Mon Sep 17 00:00:00 2001 From: Ruffin Date: Mon, 3 Apr 2023 08:57:56 -0500 Subject: [PATCH] Mount overlay workspace into Dev Container via volume (#3524) * Add volume for overlay to avoid rebuilding it from scratch whenever the dev container is rebuilt this saves startup time locally when fiddling with the configs * Append devcontainerId to volume name to avoid conflicts with other devcontainers note that devcontainerId is stable across rebuilds - https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson * Call updateContentCommand from onCreateCommand to deduplicate scripts and keep setup DRY given the addition of a mounted overlay volume which could include a prebuilt colcon workspace well before the dev container is created/rebuilt * Comment out colcon clean from setup to avoid unintentional removal of built packages from the persistent overlay workspace volume. Users can uncomment the line locally or simply remove the overlay workspace volume if they want to rebuild packages from scratch. * Format json --- .devcontainer/devcontainer.json | 23 ++++++++++++++--------- .devcontainer/on-create-command.sh | 8 +------- .devcontainer/update-content-command.sh | 6 +++--- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 985d9bfbcf6..7f2a4524a9d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,11 +1,11 @@ { "name": "Nav2", - "build": { - "dockerfile": "../Dockerfile", + "build": { + "dockerfile": "../Dockerfile", "context": "..", "target": "dever", "cacheFrom": "ghcr.io/ros-planning/navigation2:main" - }, + }, "runArgs": [ "--privileged", "--network=host" @@ -20,12 +20,17 @@ "CCACHE_DIR": "/tmp/.ccache" }, "mounts": [ - { - "source": "ccache", - "target": "/tmp/.ccache", - "type": "volume" - } - ], + { + "source": "ccache-${devcontainerId}", + "target": "/tmp/.ccache", + "type": "volume" + }, + { + "source": "overlay-${devcontainerId}", + "target": "/opt/overlay_ws", + "type": "volume" + } + ], "features": { // "ghcr.io/devcontainers/features/desktop-lite:1": {}, "ghcr.io/devcontainers/features/github-cli:1": {} diff --git a/.devcontainer/on-create-command.sh b/.devcontainer/on-create-command.sh index 2d8f4e9eeef..f86d22bc8d0 100755 --- a/.devcontainer/on-create-command.sh +++ b/.devcontainer/on-create-command.sh @@ -7,12 +7,6 @@ set -eo pipefail # set -x # env -cd $OVERLAY_WS - git config --global --add safe.directory "*" -colcon cache lock -. $UNDERLAY_WS/install/setup.sh -colcon build \ - --symlink-install \ - --mixin $OVERLAY_MIXINS +.devcontainer/update-content-command.sh diff --git a/.devcontainer/update-content-command.sh b/.devcontainer/update-content-command.sh index d3d619b59a3..2bdbf5cc1a3 100755 --- a/.devcontainer/update-content-command.sh +++ b/.devcontainer/update-content-command.sh @@ -49,9 +49,9 @@ then fi echo BUILD_PACKAGES: $BUILD_PACKAGES -colcon clean packages --yes \ - --packages-select ${BUILD_PACKAGES} \ - --base-select install +# colcon clean packages --yes \ +# --packages-select ${BUILD_PACKAGES} \ +# --base-select install . $UNDERLAY_WS/install/setup.sh colcon build \