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

simplify Setup ROS 2 with devcontainer. #4161

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,28 @@ Add a workspace in order to build and open them in a container, e.g.:
.. code-block:: console

cd ~/
mkdir ws_[project]
cd ws_[project]
mkdir ws
cd ws
mkdir src

Now create a .devcontainer folder in the root of your workspace and add a devcontainer.json and Dockerfile to this .devcontainer folder.
Additionally, you need to create a cache folder in which you can cache the build and install folders for different ROS 2 distros.
Now create a ``.devcontainer`` folder in the root of your workspace and add a ``devcontainer.json`` and ``Dockerfile`` to this ``.devcontainer`` folder.
The workspace structure should look like this:

::

ws_[project]
├── cache
| ├── [ROS2_DISTRO]
| | ├── build
| | ├── install
| | └── log
| └── ...
|
ws
├── .devcontainer
│ ├── devcontainer.json
│ └── Dockerfile
├── src
├── .devcontainer
│ ├── devcontainer.json
│ └── Dockerfile
├── package1
└── package2


With ``File->Open Folder...`` or ``Ctrl+K Ctrl+O``, open the ``src`` folder of your workspace in VS Code.
With ``File->Open Folder...`` or ``Ctrl+K Ctrl+O``, open the ``ws`` folder of your workspace in VS Code.

Edit devcontainer.json for your environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Edit ``devcontainer.json`` for your environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For the Dev Container to function properly, we have to build it with the correct user.
Therefore add the following to ``.devcontainer/devcontainer.json``:
Expand Down Expand Up @@ -150,10 +142,7 @@ Therefore add the following to ``.devcontainer/devcontainer.json``:
],
"mounts": [
"source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached",
"source=/dev/dri,target=/dev/dri,type=bind,consistency=cached",
"source=${localWorkspaceFolder}/../cache/ROS_DISTRO/build,target=/home/ws/build,type=bind",
"source=${localWorkspaceFolder}/../cache/ROS_DISTRO/install,target=/home/ws/install,type=bind",
"source=${localWorkspaceFolder}/../cache/ROS_DISTRO/log,target=/home/ws/log,type=bind"
"source=/dev/dri,target=/dev/dri,type=bind,consistency=cached"
],
"postCreateCommand": "sudo rosdep update && sudo rosdep install --from-paths src --ignore-src -y && sudo chown -R $(whoami) /home/ws/"
}
Expand All @@ -166,9 +155,8 @@ If you do not know your username, you can find it by running ``echo $USERNAME``
Also replace ``ROS_DISTRO``, with the ROS 2 distribution that you want to use and added to the cache previously, for example, "humble" or "foxy".



Edit Dockerfile
^^^^^^^^^^^^^^^
Edit ``Dockerfile``
^^^^^^^^^^^^^^^^^^^

Open the Dockerfile and add the following contents:

Expand Down Expand Up @@ -201,14 +189,14 @@ Open the Dockerfile and add the following contents:
USER $USERNAME
CMD ["/bin/bash"]

Search here also for ``ROS_DISTRO`` with the ROS 2 distribution you wish to use and added to the cache previously.
Search here also for ``ROS_DISTRO`` with the ROS 2 distribution you wish to use.
Copy link
Contributor

Choose a reason for hiding this comment

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

It is unclear to me why you would "search" here for the ROS_DISTRO. You search and then do...what?

(this was an existing problem with this sentence)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i added Replace... sentence for this, how does it look? 611df1f

besides it, caching directories are removed, and removed that sentence as well.



Open and Build Development Container
------------------------------------

Use ``View->Command Palette...`` or ``Ctrl+Shift+P`` to open the command palette.
Search for the command ``Dev Containers: (Re-)build and Reopen in Container`` and execute it.
Search for the command ``Dev Containers: Reopen in Container`` and execute it.
This will build your development docker container for your. It will take a while - sit back or go for a coffee.


Expand Down
Loading