From 5a6fda9aeebc48eea96169ab2fe5f92cdcf3c016 Mon Sep 17 00:00:00 2001 From: Ruffin Date: Mon, 13 Mar 2023 10:59:05 -0500 Subject: [PATCH] Use Codespaces prebuilds (#3470) * Add commands to devcontainer * Set builtin bash to be safe https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ * Setup workspace on create * Revert use of set -u for bash don't raise error due to variables otherwise colcon setup.sh chokes from using an unbounded path variable * Add safe.directory for git config otherwise colcon cache errors out because of issues with git due to complex user mapping magic that vscode does with devcontainers https://stackoverflow.com/questions/72978485/git-submodule-update-failed-with-fatal-detected-dubious-ownership-in-repositor also used by Moveit2: https://github.com/ros-planning/moveit2/pull/1994 https://github.blog/2022-04-12-git-security-vulnerability-announced/ * Set env using remoteEnv instead of inlining them in scripts * Revert to using the main tag now that the tester stage has been replicated with the new devcontainer script commands instead * formating * Scrap `-dev` image tag and use codspaces prebuilds instead * Build incrementally from update content command by copying the build workspace steps from circleci config * Adapt the build workspace steps for bash --- .devcontainer/devcontainer.json | 8 +++- .devcontainer/on-create-command.sh | 19 +++++++++ .devcontainer/update-content-command.sh | 57 +++++++++++++++++++++++++ .github/workflows/update_ci_image.yaml | 20 --------- 4 files changed, 83 insertions(+), 21 deletions(-) create mode 100755 .devcontainer/on-create-command.sh create mode 100755 .devcontainer/update-content-command.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f02258cd5d..81d7112151 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,12 +1,18 @@ { "name": "Nav2", - "image": "ghcr.io/ros-planning/navigation2:main-dev", + "image": "ghcr.io/ros-planning/navigation2:main", "runArgs": [ "--privileged", "--network=host" ], "workspaceMount": "source=${localWorkspaceFolder},target=/opt/overlay_ws/src/navigation2,type=bind", "workspaceFolder": "/opt/overlay_ws/src", + "onCreateCommand": "navigation2/.devcontainer/on-create-command.sh", + "updateContentCommand": "navigation2/.devcontainer/update-content-command.sh", + "remoteEnv": { + "OVERLAY_MIXINS": "release ccache lld", + "CCACHE_DIR": "${containerEnv:OVERLAY_WS}/.ccache" + }, "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 new file mode 100755 index 0000000000..b630db77f6 --- /dev/null +++ b/.devcontainer/on-create-command.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -exo pipefail + +env + +cd $OVERLAY_WS +. $UNDERLAY_WS/install/setup.sh + +git config --global --add safe.directory "*" +colcon cache lock + +colcon build \ + --symlink-install \ + --mixin $OVERLAY_MIXINS + +sed --in-place \ + 's|^source .*|source "$OVERLAY_WS/install/setup.bash"|' \ + /ros_entrypoint.sh diff --git a/.devcontainer/update-content-command.sh b/.devcontainer/update-content-command.sh new file mode 100755 index 0000000000..7954e0dbc5 --- /dev/null +++ b/.devcontainer/update-content-command.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +set -exo pipefail + +env + +cd $OVERLAY_WS + +colcon cache lock + +BUILD_UNFINISHED=$( + colcon list \ + --names-only \ + --packages-skip-build-finished \ + | xargs) +echo BUILD_UNFINISHED: $BUILD_UNFINISHED + +BUILD_FAILED=$( + colcon list \ + --names-only \ + --packages-select-build-failed \ + | xargs) +echo BUILD_FAILED: $BUILD_FAILED + +BUILD_INVALID=$( + colcon list \ + --names-only \ + --packages-select-cache-invalid \ + --packages-select-cache-key build \ + | xargs) +echo BUILD_INVALID: $BUILD_INVALID + +BUILD_PACKAGES="" +if [ -n "$BUILD_UNFINISHED" ] || \ + [ -n "$BUILD_FAILED" ] || \ + [ -n "$BUILD_INVALID" ] +then + BUILD_PACKAGES=$( + colcon list \ + --names-only \ + --packages-above \ + $BUILD_UNFINISHED \ + $BUILD_FAILED \ + $BUILD_INVALID \ + | xargs) +fi +echo BUILD_PACKAGES: $BUILD_PACKAGES + +colcon clean packages --yes \ + --packages-select ${BUILD_PACKAGES} \ + --base-select install + +. $UNDERLAY_WS/install/setup.sh +colcon build \ + --symlink-install \ + --mixin $OVERLAY_MIXINS \ + --packages-select ${BUILD_PACKAGES} diff --git a/.github/workflows/update_ci_image.yaml b/.github/workflows/update_ci_image.yaml index ad3b069b99..82259bb1a8 100644 --- a/.github/workflows/update_ci_image.yaml +++ b/.github/workflows/update_ci_image.yaml @@ -109,23 +109,3 @@ jobs: - name: Image digest if: steps.config.outputs.trigger == 'true' run: echo ${{ steps.docker_build.outputs.digest }} - - name: Build and push ${{ github.ref_name }}-dev - if: steps.config.outputs.trigger == 'true' - id: docker_build_dev - uses: docker/build-push-action@v4 - with: - pull: true - push: true - cache-from: | - type=registry,ref=ghcr.io/ros-planning/navigation2:${{ github.ref_name }} - type=registry,ref=ghcr.io/ros-planning/navigation2:${{ github.ref_name }}-dev - cache-to: type=inline - build-args: | - RUN_TESTS=True - target: tester - tags: | - ghcr.io/ros-planning/navigation2:${{ github.ref_name }}-dev - ghcr.io/ros-planning/navigation2:${{ github.ref_name }}-dev-${{ steps.config.outputs.timestamp }} - - name: Image digest - if: steps.config.outputs.trigger == 'true' - run: echo ${{ steps.docker_build.outputs.digest }}