diff --git a/docker/README.md b/docker/README.md index 14ab5b4..4ca49a1 100644 --- a/docker/README.md +++ b/docker/README.md @@ -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 @@ -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//catkin_ws +``` + +If you want to run it as a daemon you can use: +```bash +docker-develop.sh /home//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 \ No newline at end of file diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile index 1ab25aa..39856bc 100644 --- a/docker/base/Dockerfile +++ b/docker/base/Dockerfile @@ -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 @@ -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 \ No newline at end of file +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 diff --git a/docker/build-ros-image.sh b/docker/build-ros-image.sh index 616552f..bcfba8d 100755 --- a/docker/build-ros-image.sh +++ b/docker/build-ros-image.sh @@ -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 \ No newline at end of file diff --git a/docker/catkin-build/Dockerfile b/docker/catkin-build/Dockerfile index 02343b0..464d15e 100644 --- a/docker/catkin-build/Dockerfile +++ b/docker/catkin-build/Dockerfile @@ -1,9 +1,15 @@ FROM tsdf-plusplus-ros-workspace:v0.1 +ARG USERNAME=ros 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' \ No newline at end of file diff --git a/docker/docker-develop.sh b/docker/docker-develop.sh new file mode 100755 index 0000000..1a8503f --- /dev/null +++ b/docker/docker-develop.sh @@ -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 \ No newline at end of file diff --git a/docker/workspace/Dockerfile b/docker/workspace/Dockerfile index a5c5aab..5cb1786 100644 --- a/docker/workspace/Dockerfile +++ b/docker/workspace/Dockerfile @@ -1,17 +1,7 @@ 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 +ARG USERNAME=ros USER $USERNAME WORKDIR /home/$USERNAME ARG ROS_VERSION=melodic @@ -22,8 +12,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'