Skip to content

Commit

Permalink
huge refactoring to enable developing locally using docker
Browse files Browse the repository at this point in the history
  • Loading branch information
paucarre committed May 23, 2021
1 parent 5af53f5 commit d803d61
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
31 changes: 30 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ To run the docker image use:

# Getting environment up and running

## Copy workspace from docker machine

If you want to get quicky up and runing, keeping sources on your computer
and using docker as a as a perdictable build system you can run:
```bash
Expand All @@ -37,7 +39,34 @@ You can confirm you have the right origin URL by running:
git remote show origin
```

## Use computer workspace on docker

If you have your workspace locally and want to use the docker machine to build
and/or run nodes, you can use the scrip `docker-develop.sh`.
This script will discard the sources from the remote repository and instead
use the sources you have locally on your computer that will be mounted
on the docker machine.

For example, you can use the following command:
```bash
docker-develop.sh /home/<YOUR_USERNAME>/catkin_ws
```

If you want to run it as a daemon you can use:
```bash
docker-develop.sh /home/<YOUR_USERNAME>/catkin_ws dt
```

Once you are in the docker machine you can, for instance, build
from sources doing
```bash
catkin build -j$(($(nproc) / 2)) -l1 tsdf_plusplus_ros rgbd_segmentation mask_rcnn_ros cloud_segmentation
```

By doing so, the docker machine will build the sources on your computer and
keep the binaries on your computer as well.


TODO:
- Allow mounted local workspaced in docker
- Automatically build the current (remote) branch
- Entrypoint with all nodes running
15 changes: 14 additions & 1 deletion docker/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM ros:melodic-ros-core
ENV DEBIAN_FRONTEND=noninteractive

ARG USER_ID
ARG GROUP_ID

# Install dependencies
RUN apt update -y
RUN apt upgrade -y
Expand All @@ -15,4 +18,14 @@ RUN apt install -y build-essential tree vim \
rm -rf /var/lib/apt/lists/* && \
apt clean && \
apt autoclean
RUN pip install -U osrf-pycommon wstool setuptools
RUN pip install -U osrf-pycommon wstool setuptools


# Create 'ros' user with sudo powers
ARG USERNAME=ros
RUN groupadd --gid $GROUP_ID $USERNAME
RUN useradd -s /bin/bash --uid $USER_ID --gid $GROUP_ID -m $USERNAME
RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
RUN chmod 0440 /etc/sudoers.d/$USERNAME
RUN echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc
RUN echo "if [ -f /opt/ros/${ROS_DISTRO}/setup.bash ]; then source /opt/ros/${ROS_DISTRO}/setup.bash; fi" >> /home/$USERNAME/.bashrc
2 changes: 1 addition & 1 deletion docker/build-ros-image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
docker build -t tsdf-plusplus-ros-base:v0.1 base
docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) -t tsdf-plusplus-ros-base:v0.1 base
docker build -t tsdf-plusplus-ros-workspace:v0.1 workspace
docker build -t tsdf-plusplus-ros-catkin-build:v0.1 catkin-build
5 changes: 5 additions & 0 deletions docker/catkin-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ USER $USERNAME
WORKDIR /home/$USERNAME
ARG ROS_VERSION=melodic
ARG CATKIN_WS=/home/ros/catkin_ws
RUN bash -c 'source /opt/ros/melodic/setup.bash && \
cd $CATKIN_WS/src && \
git clone https://github.com/ethz-asl/tsdf-plusplus.git && \
wstool merge -t . tsdf-plusplus/tsdf_plusplus_https.rosinstall && \
wstool update'
RUN bash -c 'source /opt/ros/melodic/setup.bash && \
cd $CATKIN_WS && \
catkin build -j$(($(nproc) / 2)) -l1 tsdf_plusplus_ros rgbd_segmentation mask_rcnn_ros cloud_segmentation'
19 changes: 19 additions & 0 deletions docker/docker-develop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
workspace_folder=$1
if [ -z "$1" ]
then
echo "Absolute path of the workspace folder not found"
exit 1
fi
mode=$2
if [ -z "$2" ]
then
mode="it"
fi
docker container run --rm -$mode \
--user $(id -u) \
--mount type=bind,source="${workspace_folder}",target=/home/ros/catkin_ws \
--name tsdf-plusplus-dev \
--workdir /home/ros/catkin_ws \
tsdf-plusplus-ros-base:v0.1 \
bash
17 changes: 1 addition & 16 deletions docker/workspace/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
FROM tsdf-plusplus-ros-base:v0.1

# Create 'ros' user with sudo powers
ARG USERNAME=ros
ARG USER_UID=1001
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& echo "source /usr/share/bash-completion/completions/git" >> /home/$USERNAME/.bashrc \
&& echo "if [ -f /opt/ros/${ROS_DISTRO}/setup.bash ]; then source /opt/ros/${ROS_DISTRO}/setup.bash; fi" >> /home/$USERNAME/.bashrc

# Create workspace
USER $USERNAME
WORKDIR /home/$USERNAME
Expand All @@ -22,8 +11,4 @@ RUN bash -c 'source /opt/ros/melodic/setup.bash && \
catkin init && \
catkin config --extend /opt/ros/melodic --merge-devel && \
catkin config --cmake-args -DCMAKE_CXX_STANDARD=14 -DCMAKE_BUILD_TYPE=Release && \
wstool init src && \
cd $CATKIN_WS/src && \
git clone https://github.com/ethz-asl/tsdf-plusplus.git && \
wstool merge -t . tsdf-plusplus/tsdf_plusplus_https.rosinstall && \
wstool update'
wstool init src'

0 comments on commit d803d61

Please sign in to comment.