From d71a7190f1210f5ac97ce16892552ecf495e2437 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Tue, 22 Aug 2023 20:47:09 +0200 Subject: [PATCH] Devcontainer (#29259) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * mvp devcontainer. builds, runs and UI works * fix indentation * enable color and fix openpilot_env path * separate dockerfile for devcontainer * use prebuilt image * Fix openpilot_env setup * Add dev container section in readme * Fix typo * Fix typo again * Move dev dockerfile to .devcontainer dir * Update README * Add note about x11 forwarding on macos * Update dev container json * Fix typo * Override DISPLAY on macOS * Mention XAUTHORITY for macOS setup in README * fix typo * Add devcontainer CI test * Rename to devcontainer * Fix git issues * ripgrep * Link instead of vscode manual * Replace raw path with containerWorkspaceFolder * Fix typo * Remove dev tools workflow * Link away X11 forwarding setup isntructions for mac * Remove fork consrtaint, add test run of scons * Add submodules as safe.directories in postStartCommand * Remove openpilot_env references * Add scons cache volume --------- Co-authored-by: Robbe Derks Co-authored-by: Kacper Rączy --- .devcontainer/Dockerfile | 6 ++++++ .devcontainer/devcontainer.json | 22 ++++++++++++++++++++++ .github/workflows/tools_tests.yaml | 18 +++++++++++++++++- tools/README.md | 10 ++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100755 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..e72704bfd0 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/commaai/openpilot-base:latest + +# remove gitconfig if exists, since its gonna be replaced by host one +RUN rm -f /root/.gitconfig +RUN apt update && apt install -y vim net-tools usbutils htop ripgrep +RUN pip install ipython jupyter jupyterlab diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100755 index 0000000000..c2d26fb9a7 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +{ + "name": "openpilot devcontainer", + "build": { + "dockerfile": "Dockerfile" + }, + "postCreateCommand": "bash -c 'if [[ $DISPLAY == *xquartz* ]]; then echo \"export DISPLAY=host.docker.internal:0\" >> /root/.bashrc; fi'", + "postStartCommand": "git config --file .gitmodules --get-regexp path | awk '{ print $2 }' | xargs -I{} git config --global --add safe.directory \"$PWD/{}\"", + "privileged": true, + "containerEnv": { + "DISPLAY": "${localEnv:DISPLAY}", + "PYTHONPATH": "${containerWorkspaceFolder}", + "force_color_prompt": "1" + }, + "runArgs": [ + "--volume=/tmp/.X11-unix:/tmp/.X11-unix", + "--volume=${localEnv:XAUTHORITY}:/root/.Xauthority", + "--volume=${localEnv:HOME}/.comma:/root/.comma", + "--volume=/tmp/comma_download_cache:/tmp/comma_download_cache", + "--volume=/tmp/devcontainer_scons_cache:/tmp/scons_cache", + "--shm-size=1G" + ] +} \ No newline at end of file diff --git a/.github/workflows/tools_tests.yaml b/.github/workflows/tools_tests.yaml index 5891d5207e..04f73d21af 100644 --- a/.github/workflows/tools_tests.yaml +++ b/.github/workflows/tools_tests.yaml @@ -91,4 +91,20 @@ jobs: if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/openpilot' run: | $DOCKER_LOGIN - docker push $DOCKER_REGISTRY/openpilot-docs:latest \ No newline at end of file + docker push $DOCKER_REGISTRY/openpilot-docs:latest + + devcontainer: + name: devcontainer + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Setup Dev Container CLI + run: npm install -g @devcontainers/cli + - name: Build dev container image + run: devcontainer build --workspace-folder . + - name: Run dev container + run: devcontainer up --workspace-folder . + - name: Test environment + run: devcontainer exec --workspace-folder . scons --dry-run diff --git a/tools/README.md b/tools/README.md index fd03a5d77e..28f4f7ebd2 100644 --- a/tools/README.md +++ b/tools/README.md @@ -38,6 +38,16 @@ Build openpilot with this command: scons -u -j$(nproc) ``` +### Dev Container + +openpilot supports [Dev Containers](https://containers.dev/). Dev containers provide customizable and consistent development environment wrapped inside a container. This means you can develop in a designated environment matching our primary development target, regardless of your local setup. + +Dev containers are supported in [multiple editors and IDEs](https://containers.dev/supporting), including [Visual Studio Code](https://code.visualstudio.com/docs/devcontainers/containers). + +#### X11 forwarding on macOS + +GUI apps like `ui` or `cabana` can also run inside the container by leveraging X11 forwarding. To make use of it on macOS, additional configuration steps must be taken. Follow [these](https://gist.github.com/sorny/969fe55d85c9b0035b0109a31cbcb088) steps to setup X11 forwarding on macOS. + ### Windows Neither openpilot nor any of the tools are developed or tested on Windows, but the [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/about) should provide a similar experience to native Ubuntu. [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/compare-versions) specifically has been reported by several users to be a seamless experience.