Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devcontainer #29259

Merged
merged 33 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4de62a0
mvp devcontainer. builds, runs and UI works
Aug 6, 2023
8c0ea4d
fix indentation
Aug 6, 2023
c6c8cf8
enable color and fix openpilot_env path
Aug 6, 2023
ba2177d
separate dockerfile for devcontainer
robbederks Aug 7, 2023
d1a3a75
use prebuilt image
robbederks Aug 8, 2023
40b559a
Fix openpilot_env setup
fredyshox Aug 8, 2023
e734099
Add dev container section in readme
fredyshox Aug 8, 2023
d5f48b9
Fix typo
fredyshox Aug 8, 2023
db19249
Fix typo again
fredyshox Aug 8, 2023
ad9a87b
Move dev dockerfile to .devcontainer dir
fredyshox Aug 8, 2023
2d0456f
Update README
fredyshox Aug 9, 2023
33e7ebc
Add note about x11 forwarding on macos
fredyshox Aug 10, 2023
bd611bf
Update dev container json
fredyshox Aug 10, 2023
f98ae2f
Fix typo
fredyshox Aug 10, 2023
a62a9ba
Override DISPLAY on macOS
fredyshox Aug 10, 2023
fa104b1
Mention XAUTHORITY for macOS setup in README
fredyshox Aug 10, 2023
fd1e402
fix typo
fredyshox Aug 10, 2023
a9924ad
Add devcontainer CI test
fredyshox Aug 10, 2023
8e1456a
Rename to devcontainer
fredyshox Aug 10, 2023
1d1c822
Fix git issues
fredyshox Aug 10, 2023
27a5f12
ripgrep
robbederks Aug 14, 2023
949275a
Link instead of vscode manual
fredyshox Aug 16, 2023
0a84a57
Replace raw path with containerWorkspaceFolder
fredyshox Aug 16, 2023
5e5f53a
Fix typo
fredyshox Aug 16, 2023
17768e5
Remove dev tools workflow
fredyshox Aug 16, 2023
d3aa650
Merge branch 'master' into devcontainer
fredyshox Aug 16, 2023
aa75b3f
Link away X11 forwarding setup isntructions for mac
fredyshox Aug 21, 2023
6c83c1b
Merge remote-tracking branch 'origin/master' into devcontainer
fredyshox Aug 21, 2023
11b82d5
Remove fork consrtaint, add test run of scons
fredyshox Aug 21, 2023
bd8d87b
Add submodules as safe.directories in postStartCommand
fredyshox Aug 21, 2023
4972a3b
Remove openpilot_env references
fredyshox Aug 22, 2023
0126999
Merge remote-tracking branch 'origin/master' into devcontainer
fredyshox Aug 22, 2023
15305c1
Add scons cache volume
fredyshox Aug 22, 2023
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
7 changes: 7 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ghcr.io/commaai/openpilot-base:latest

RUN printf "\nsource /workspaces/openpilot/tools/openpilot_env.sh\n" >> ~/.bashrc
# remove gitconfig if exists, since its gonna be replaced by host one
RUN rm -f /root/.gitconfig
Comment on lines +3 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't it be shadowed anyway when it's mounted in?

Copy link
Contributor

@fredyshox fredyshox Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not mounting it ourselves, vscode/devcontainer does that for us, and it fails silently if it exists already.

RUN apt update && apt install -y vim net-tools usbutils htop ripgrep
RUN pip install ipython jupyter jupyterlab
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should consider adding this as a poetry group

20 changes: 20 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "openpilot devcontainer",
"build": {
"dockerfile": "Dockerfile"
},
"postCreateCommand": "bash -c 'if [[ $DISPLAY == *xquartz* ]]; then echo \"export DISPLAY=host.docker.internal:0\" >> /root/.bashrc; fi'",
"privileged": true,
"containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}",
"PYTHONPATH": "${containerWorkspaceFolder}",
"force_color_prompt": "1"
},
"runArgs": [
robbederks marked this conversation as resolved.
Show resolved Hide resolved
"--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",
"--shm-size=1G"
]
}
24 changes: 24 additions & 0 deletions .github/workflows/dev_tools_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: development tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've already got tools_tests.yaml

on:
push:
branches:
- master
pull_request:

jobs:
devcontainer:
name: devcontainer
runs-on: ubuntu-latest
if: github.repository == 'commaai/openpilot'
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: Stop containers
run: docker kill $(docker ps -q)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem necessary

1 change: 1 addition & 0 deletions Dockerfile.openpilot_base
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ RUN cd /tmp && \
rm -rf thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp

RUN sudo git config --global --add safe.directory /tmp/openpilot
RUN sed -i "/openpilot_env\.sh/d" /root/.bashrc
26 changes: 26 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ 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 you local setup.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you -> your


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we can link away this whole section


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. First of all, install [XQuartz](https://formulae.brew.sh/cask/xquartz#default):
```sh
brew install --cask xquartz
```

Open XQuartz, go to `XQuartz` > `Settings...` > `Security` and check "Authenticate connections" and "Allow connections from network clients" boxes. Then allow for connections from localhost with:
```sh
xhost +localhost
```
Note that this is temporary and only affects current XQuartz session. To make it permanent, add the above line to shell rc file.

`.Xauthority` file is used for authentication with X11 server. It's typically stored in user's `$HOME` directory. Openpilot's dev container is using `XAUTHORITY` env var to locate such file in host file system. If it's not set already, run following lines to set it up (and again, to make it permanent, add it to rc file):

```sh
XAUTH_FILE_ROW=($(xauth info | head -n 1))
export XAUTHORITY="${XAUTH_FILE_ROW[@]:2}"
```

### 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.
Expand Down
Loading