Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Interpause committed Jan 17, 2023
1 parent a20e056 commit 9a3588d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/hooks/postCreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

. /opt/ros/$ROS_DISTRO/setup.sh

# Auto-activate ROS whenever bash shell is opened.
echo "source /opt/ros/$ROS_DISTRO/setup.bash\nsource $WORKSPACE_ROOT/install/local_setup.bash" >> ~/.bashrc

# (OPTION) Symlink `/data` mount point to workspace folder for convenience.
# ln -sf /data "$WORKSPACE_ROOT/"

# Something deleted the package indexes so we re-download them for convenience.
apt-get update
rosdep update
3 changes: 0 additions & 3 deletions .devcontainer/hooks/postStart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ git config --global safe.directory "*"
# Ensure submodules are cloned; Doesn't affect already cloned ones.
git submodule update --init --recursive

# (OPTION) Symlink `/data` mount point to workspace folder for convenience.
# ln -sf /data "$WORKSPACE_ROOT/"

# Ensure dependencies are installed.
rosdep install --ignore-src --from-path "$WORKSPACE_ROOT" -y
pip install -r "$WORKSPACE_ROOT/requirements.txt"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

# Dockerfile for production
# Referring to Dockerfile.dev might be useful for understanding the contents.
# Referring to Dockerfile.dev & hooks/postCreate.sh might be useful for understanding the contents.

FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu22.04

Expand Down
17 changes: 11 additions & 6 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN bash /tmp/scripts/desktop-lite-debian.sh root password
RUN mkdir -p /etc/OpenCL/vendors && \
echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd

# Curl key and authorize ROS repository.
# Curl key to authorize ROS repository.
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" > /etc/apt/sources.list.d/ros2.list

Expand All @@ -58,23 +58,28 @@ RUN rosdep init && rosdep update
# RQT's plugin support allows for custom visualizations, tools or control panels.
RUN apt-get install -y ~nros-${ROS_DISTRO}-rqt*

# Curl key to authorize Docker repository.
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - 2>/dev/null \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

# Install Docker CLI tools (not including daemon).
RUN apt-get update \
&& apt-get install -y docker-ce-cli \
&& pip install docker-compose

# Needed for Dev Container lifecycle hooks to run.
COPY ./.devcontainer /tmp/.devcontainer

COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ \
# VNC entrypoint
"/usr/local/share/desktop-init.sh", \
# ROS entrypoint
"/entrypoint.sh" \
"/usr/local/share/desktop-init.sh" \
]

# Make /bin/sh launch bash instead.
ENV ENV=\$HOME/.shrc
RUN echo "exec bash" >> ~/.shrc
# Auto-activate ROS whenever bash shell is opened.
RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash\nsource /code/install/local_setup.bash" >> ~/.bashrc

# Ensure RQT icons show up.
RUN mkdir ~/.icons && ln -s /usr/share/icons/Tango ~/.icons/hicolor
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Template for ROS2 workspace using [VS Code Dev Containers](https://code.visualst
- [Dev Container Lifecycle Hooks](#dev-container-lifecycle-hooks)
- [Dev Container using Docker Compose](#dev-container-using-docker-compose)
- [Tips](#tips)
- [`git` Submodules](#git-submodules)
- [`example_module`](#example_module)
- [`git` Submodules](#git-submodules)
- [Update Package Indexes](#update-package-indexes)
- [Minimize Changes to the Dockerfile](#minimize-changes-to-the-dockerfile)
- [Change ROS Distro](#change-ros-distro)
Expand All @@ -35,7 +35,12 @@ Template for ROS2 workspace using [VS Code Dev Containers](https://code.visualst

### Mount Point `/data`

Mount points are used to mount a folder from the host into the container. By following `(OPTION)`s, `./data` on the host is mounted to `/data` in the container. `/data` can be used to share anything from the host with the container (e.g., config files, models, databases).
> Note: If using `Dev Containers: Clone Repository in Container Volume...`, the host folder path must be absolute.
Mount points are used to mount a folder from the host into the container. An example for mounting a folder to `/data` is included in [`docker-compose.dev.yml`](./docker-compose.dev.yml) as an `(OPTION)`. `/data` can be used to share anything from the host with the container (e.g., config files, models, databases). Also remember to:

- Add mount points to [`.gitignore`](./.gitignore) and [`.dockerignore`](./.dockerignore).
- Symlink mount points into your workspace folder for convenience in [`postCreate.sh`](./.devcontainer/hooks/postCreate.sh).

While one mount point is sufficient, more can be added by following `/data`'s example. See <https://docs.docker.com/storage/bind-mounts/> for more info.

Expand Down Expand Up @@ -64,6 +69,8 @@ See <https://docs.docker.com/engine/reference/commandline/docker/> for more info

#### Building

> Note: If using `Dev Containers: Clone Repository in Container Volume...` on Windows, follow <https://code.visualstudio.com/docs/containers/choosing-dev-environment#_windows-subsystem-for-linux> to ensure built images are stored on the host computer's image repository.
```sh
docker build . -t organization/repo:vx.x.x -t organization/repo:latest
```
Expand All @@ -72,6 +79,8 @@ Images can have multiple names tagged to them. Tagging images with the version n

#### Exporting

> Note: Run this command on the host computer rather than in the Dev Container.
```sh
docker save organization/repo:vx.x.x organization/repo:latest -o repo-vx.x.x.tar
```
Expand Down Expand Up @@ -102,12 +111,20 @@ Both [`devcontainer.json`](./.devcontainer/devcontainer.json) and [`extensions.j

Instead of using Dev Container with a Dockerfile, this template uses it with Docker Compose instead. This is done for a few reasons:

- Include example of multiple Docker containers being capable of operating as one ROS system.
- Include example of how to configure Docker for ROS to communicate across containers.
- Docker Compose is closer to real world deployment scenarios.
- It is also more flexible and easier to configure than [`devcontainer.json`](./.devcontainer/devcontainer.json).

## Tips

### `example_module`

`example_module`'s [README.md](https://github.com/Interpause/ros-example-node/blob/main/README.md) provides instructions on how to create a `git` submodule and add ROS packages to it. It also contains a simple pub-sub `launch` file that can be used to test bandwidth & latency. To remove `example_module`:

```sh
git rm example_module
```

### `git` Submodules

> Note: The template will clone missing submodules for you by default.
Expand Down Expand Up @@ -140,14 +157,6 @@ git submodule foreach --recursive git checkout main

This is done for you automatically if using a named volume to store the repository.

### `example_module`

`example_module`'s [README.md](https://github.com/Interpause/ros-example-node/blob/main/README.md) provides instructions on how to create a `git` submodule and add ROS packages to it. It also contains a simple pub-sub `launch` file that can be used to test bandwidth & latency. To remove `example_module`:

```sh
git rm example_module
```

### Update Package Indexes

The `rosdep` and Ubuntu package managers rely on a local cache of their package index. If the package index is outdated, it may not contain any active package distribution server, leading to package downloads failing. Hence, it is recommended to periodically re-download the package index:
Expand Down
7 changes: 5 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
# Allow access to Docker daemon for VS Code Docker extension to work inside container.
- /var/run/docker.sock:/var/run/docker-host.sock
# (OPTION) Mount point for `data` folder.
# - ./data:/data:cached
# - C:\Users\user\Documents\project-name-data:/data:cached
# (OPTION) Legacy support for mounting repository from host filesystem.
# - .:/code:cached

Expand Down Expand Up @@ -56,8 +56,11 @@ services:
- 6080:6080
# Expose rosbridge.
- 9090:9090
image: alpine # smallest image

# Used to allow ROS to communicate across containers.
ipc: shareable
pid: shareable

image: alpine # smallest image
stop_signal: SIGKILL
command: sleep infinity

0 comments on commit 9a3588d

Please sign in to comment.