From 5cc2725d12909fefe36a2abc3cb3f37b30d22512 Mon Sep 17 00:00:00 2001 From: niederha Date: Wed, 18 Jan 2023 17:51:22 +0100 Subject: [PATCH 01/23] Added AICA-based docker for IIWA ros --- docker/Dockerfile | 140 +++++++++++++++++++++++++++++++++++++++ docker/README.md | 0 docker/build_docker.bash | 57 ++++++++++++++++ docker/install_docker.sh | 5 ++ docker/start_docker.bash | 66 ++++++++++++++++++ 5 files changed, 268 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100644 docker/build_docker.bash create mode 100644 docker/install_docker.sh create mode 100644 docker/start_docker.bash diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..773d468 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,140 @@ +# Handle ros distro +ARG ROS_DISTRO=noetic +FROM ghcr.io/aica-technology/ros-ws:${ROS_DISTRO} + +# User provided arguments +ARG HOST_GID=1000 +ARG GIT_NAME="" +ARG GIT_EMAIL="" +ARG USE_SIMD=OFF + +# Tell docker we want to use bash instead of sh in general +SHELL ["/bin/bash", "-c"] + + +### Make sure everything is up to date +RUN sudo apt update +RUN sudo apt upgrade -y + +### Add the user to the current GID of the host to avoid permisson issues in volumes +# AICA uses the same name for user and user group +ENV USER_GROUP=${USER} +USER root +RUN if [ "HOST_GID" != "1000"] ; \ + then groupadd --gid ${HOST_GID} host_group && \ + usermod ${USER} -g ${HOST_GID} && \ + usermod ${USER} -a -G ${USER_GROUP}; fi +USER ${USER} + +# Setup git identity +RUN git config --global user.name "${GIT_NAME}" +RUN git config --global user.email "${GIT_EMAIL}" + +# Setup python version for noetic +RUN sudo apt update +RUN if [ "${ROS_DISTRO}" == "noetic" ] ; \ + then sudo apt install python-is-python3 ; fi + +# Handle SIMD option +RUN if [ "${USE_SIMD}" = "ON" ] ; \ + then export CMAKE_CXX_FLAGS="-march=native -faligned-new" ; fi + +### Install all dependencies of IIWA ROS +# Clone KUKA FRI (need to be root to clone private repo) +WORKDIR /sources +USER root +RUN --mount=type=ssh git clone git@github.com:epfl-lasa/kuka_fri.git +WORKDIR /sources/kuka_fri +RUN if [ "${USE_SMID}" != "ON" ] ; \ + then wget https://gist.githubusercontent.com/matthias-mayr/0f947982474c1865aab825bd084e7a92/raw/244f1193bd30051ae625c8f29ed241855a59ee38/0001-Config-Disables-SIMD-march-native-by-default.patch \ + ; fi +RUN --mount=type=ssh if [ "${USE_SMID}" != "ON" ] ; \ + then git am 0001-Config-Disables-SIMD-march-native-by-default.patch ; fi + +# Transfer repo back to original user after root clone +WORKDIR /sources +RUN chown -R ${USER}:${HOST_GID} kuka_fri + +# Install kuka Fri as USER +USER ${USER} +WORKDIR /sources/kuka_fri +RUN ./waf configure +RUN ./waf +RUN sudo ./waf install + +# Install SpaceVecAlg +WORKDIR /sources +RUN git clone --recursive https://github.com/jrl-umi3218/SpaceVecAlg.git +WORKDIR /sources/SpaceVecAlg/build +RUN cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. +RUN make -j +RUN sudo make install + +# Install RBDyn +WORKDIR /sources +RUN git clone --recursive https://github.com/jrl-umi3218/RBDyn.git +WORKDIR /sources/RBDyn/build +RUN cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. +RUN make -j +RUN sudo make install + +# Install mc_rbdyn_urdf +WORKDIR /sources +RUN git clone --recursive -b v1.1.0 https://github.com/jrl-umi3218/mc_rbdyn_urdf.git +WORKDIR /sources/mc_rbdyn_urdf/build +RUN cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. +RUN make -j +RUN sudo make install + +# Install corrade +WORKDIR /sources +RUN git clone https://github.com/mosra/corrade.git +WORKDIR /sources/corrade +RUN git checkout 0d149ee9f26a6e35c30b1b44f281b272397842f5 +WORKDIR /sources/corrade/build +RUN cmake .. +RUN make -j +RUN sudo make install + +# Install robot_controller +WORKDIR /sources +RUN git clone https://github.com/epfl-lasa/robot_controllers.git +WORKDIR /sources/robot_controllers/build +RUN cmake .. +RUN make -j +RUN sudo make install + +# Install ros_control +RUN sudo apt-get install -y ros-${ROS_DISTRO}-ros-control ros-${ROS_DISTRO}-ros-controllers + +### Install gazebo +# Install gazebo (9 or 11 depending on distro) +WORKDIR /home/${USER} +RUN sudo apt-get update +RUN if [ "$ROS_DISTRO" = "noetic" ] ; then sudo apt-get install -y gazebo11 ; fi +RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y gazebo9 ; fi + +# A few extra steps to fix gazebo bugs under melodic +# RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y mesa-utils libgl1-mesa-glx ; fi + +# Install gaezbo ros packages +RUN sudo apt install -y ros-${ROS_DISTRO}-gazebo-ros-pkgs ros-${ROS_DISTRO}-gazebo-ros-control + +### Install IIWA ROS +WORKDIR /home/${USER}/ros_ws/src +RUN git clone https://github.com/epfl-lasa/iiwa_ros.git + +### Add environement variables to bashrc +WORKDIR /home/${USER} + +# Give bashrc back to user +RUN sudo chown -R ${USER}:${HOST_GID} .bashrc + +# Add cmake option to bash rc if needed +RUN if [ "${USE_SIMD}" = "ON" ] ; \ + then echo "export ENABLE_SIMD=ON" >> /home/${USER}/.bashrc ; fi + +### Build ros workspace +WORKDIR /home/${USER}/ros_ws +RUN source /home/${USER}/.bashrc && rosdep install --from-paths src --ignore-src -r -y +RUN source /home/${USER}/.bashrc && catkin_make; diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..e69de29 diff --git a/docker/build_docker.bash b/docker/build_docker.bash new file mode 100644 index 0000000..787dbd6 --- /dev/null +++ b/docker/build_docker.bash @@ -0,0 +1,57 @@ +#!/bin/bash + +# Name and base and options +IMAGE_NAME=epfl-lasa/iiwa_ros # Chose any name for your image (but make sure to report it in start_docker) +ROS_DISTRO=melodic # Possible: noetic, melodic +USE_SIMD=ON # Possible: ON, OFF +BASE_IMAGE=ghcr.io/aica-technology/ros-ws:${ROS_DISTRO} # Do not modify + +# Help +HELP_MESSAGE="Usage: ./build.sh [-r, --rebuild] [-v, --verbose] [-i, --image-name] +Build the '${IMAGE_NAME}' image. +Options: + -r, --rebuild Rebuild with --no-cache option. + -v, --verbose Display additional info upon build. + -i, --image-name Defines the name given to the image beeing built. + -h, --help Show this help message." + +# Parse build flags +BUILD_FLAGS=() +while [ "$#" -gt 0 ]; do + case "$1" in + -r | --rebuild) + BUILD_FLAGS+=(--no-cache) + shift 1 + ;; + -v | --verbose) + BUILD_FLAGS+=(--progress=plain) + shift 1 + ;; + -i | --image-name) + IMAGE_NAME=$2 + shift 2 + ;; + -h | --help) + echo "${HELP_MESSAGE}" + exit 0 + ;; + *) + echo "Unknown option: $1" >&2 + exit 1 + ;; + esac +done + +# Try to pull image +docker pull "${BASE_IMAGE}" || echo -e "\033[31mCould not pull docker image ${BASE_IMAGE}" + +# Setup build flags +BUILD_FLAGS+=(--build-arg ROS_DISTRO="${ROS_DISTRO}") +BUILD_FLAGS+=(--build-arg USE_SIMD=${USE_SIMD}) +BUILD_FLAGS+=(-t "${IMAGE_NAME}") +BUILD_FLAGS+=(--build-arg HOST_GID=$(id -g)) # Pass the correct GID to avoid issues with mounted volumes +BUILD_FLAGS+=(--ssh default="${SSH_AUTH_SOCK}") +BUILD_FLAGS+=(--build-arg GIT_NAME=$(git config user.name)) # Pass git user info to be able to pull +BUILD_FLAGS+=(--build-arg GIT_EMAIL=$(git config user.email)) + +DOCKER_BUILDKIT=1 docker build "${BUILD_FLAGS[@]}" . \ No newline at end of file diff --git a/docker/install_docker.sh b/docker/install_docker.sh new file mode 100644 index 0000000..f5a7d6d --- /dev/null +++ b/docker/install_docker.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +mkdir tmp +git clone git@github.com:aica-technology/docker-images.git tmp + diff --git a/docker/start_docker.bash b/docker/start_docker.bash new file mode 100644 index 0000000..a5d86b9 --- /dev/null +++ b/docker/start_docker.bash @@ -0,0 +1,66 @@ +#!/bin/bash +IMAGE_NAME="epfl-lasa/iiwa_ros" +CONTAINER_NAME="${IMAGE_NAME//[\/.]/-}" +USERNAME="ros" +MODE=() + + +# Help +HELP_MESSAGE="Usage: ./start_dockers.sh [interactive | server | connect] [-i, --image] [-u, --user] +Build the '${IMAGE_NAME}' image. +Options: + interactive Spin the image in the console + server Spin the image as an ssh server + connect Connects to an active container + -i, --image The name of the image to use to start the container + -u, --user Specify the name of the login user. (optional) + -h, --help Show this help message and the one from aica-docker + Additional arguments are passed to the aica-docker command. + " + +# Argument parsing +RUN_FLAGS=() +FWS_FLAGS=() +SHOW_HELP=false + +while [ "$#" -gt 0 ]; do + case "$1" in + -i | --image) + IMAGE_NAME=$2 + shift 2 + ;; + -u | --user) + USERNAME=$2 + shift 2 + ;; + -m | --mode) + MODE=$2 + shift 2 + ;; + -h | --help) + SHOW_HELP=true + shift 1 + ;; + *) + if [ -z "${MODE}" ]; then + MODE=$1 + else + FWD_ARGS+=("$1") + fi + shift 1 + ;; + esac +done + +if $SHOW_HELP; then + echo $HELP_MESSAGE + aica-docker $MODE -h + exit 1 +fi + +aica-docker \ + "${MODE}" \ + "${IMAGE_NAME}" \ + -u "${USERNAME}" \ + -n "${CONTAINER_NAME}" \ + "${FWD_ARGS[@]}" \ \ No newline at end of file From fb277b6a107d66a05b5ebcf846d7f3ebd4d71679 Mon Sep 17 00:00:00 2001 From: niederha Date: Thu, 19 Jan 2023 14:35:15 +0100 Subject: [PATCH 02/23] Better syntax and better performances --- docker/Dockerfile | 80 ++++++++++++++++++++-------------------- docker/start_docker.bash | 14 +++++++ 2 files changed, 53 insertions(+), 41 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 773d468..40ce49c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,13 +8,24 @@ ARG GIT_NAME="" ARG GIT_EMAIL="" ARG USE_SIMD=OFF +# Graphics capabilitees +ENV QT_X11_NO_MITSHM 1 +ENV NVIDIA_VISIBLE_DEVICES all +ENV NVIDIA_DRIVER_CAPABILITIES all + # Tell docker we want to use bash instead of sh in general SHELL ["/bin/bash", "-c"] - -### Make sure everything is up to date -RUN sudo apt update -RUN sudo apt upgrade -y +### Add a few tools +RUN sudo apt-get update && sudo apt-get install -y \ + bash-completion \ + silversearcher-ag \ + apt-transport-https \ + less \ + alsa-utils \ + ros-${ROS_DISTRO}-ros-control \ + ros-${ROS_DISTRO}-ros-controllers \ + && sudo apt-get upgrade -y && sudo apt-get clean ### Add the user to the current GID of the host to avoid permisson issues in volumes # AICA uses the same name for user and user group @@ -41,10 +52,10 @@ RUN if [ "${USE_SIMD}" = "ON" ] ; \ ### Install all dependencies of IIWA ROS # Clone KUKA FRI (need to be root to clone private repo) -WORKDIR /sources +WORKDIR /tmp USER root RUN --mount=type=ssh git clone git@github.com:epfl-lasa/kuka_fri.git -WORKDIR /sources/kuka_fri +WORKDIR /tmp/kuka_fri RUN if [ "${USE_SMID}" != "ON" ] ; \ then wget https://gist.githubusercontent.com/matthias-mayr/0f947982474c1865aab825bd084e7a92/raw/244f1193bd30051ae625c8f29ed241855a59ee38/0001-Config-Disables-SIMD-march-native-by-default.patch \ ; fi @@ -52,67 +63,51 @@ RUN --mount=type=ssh if [ "${USE_SMID}" != "ON" ] ; \ then git am 0001-Config-Disables-SIMD-march-native-by-default.patch ; fi # Transfer repo back to original user after root clone -WORKDIR /sources +WORKDIR /tmp RUN chown -R ${USER}:${HOST_GID} kuka_fri # Install kuka Fri as USER USER ${USER} -WORKDIR /sources/kuka_fri -RUN ./waf configure -RUN ./waf -RUN sudo ./waf install +RUN cd kuka_fri && ./waf configure && ./waf && sudo ./waf install # Install SpaceVecAlg -WORKDIR /sources RUN git clone --recursive https://github.com/jrl-umi3218/SpaceVecAlg.git -WORKDIR /sources/SpaceVecAlg/build -RUN cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. -RUN make -j -RUN sudo make install +RUN cd SpaceVecAlg && mkdir build && cd build \ + && cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. \ + && make -j && sudo make install # Install RBDyn -WORKDIR /sources RUN git clone --recursive https://github.com/jrl-umi3218/RBDyn.git -WORKDIR /sources/RBDyn/build -RUN cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. -RUN make -j -RUN sudo make install +RUN cd RBDyn && mkdir build && cd build \ + && cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. \ + && make -j && sudo make install # Install mc_rbdyn_urdf -WORKDIR /sources RUN git clone --recursive -b v1.1.0 https://github.com/jrl-umi3218/mc_rbdyn_urdf.git -WORKDIR /sources/mc_rbdyn_urdf/build -RUN cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. -RUN make -j -RUN sudo make install +RUN cd mc_rbdyn_urdf && mkdir build && cd build \ + && cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON_BINDING=OFF .. \ + && make -j && sudo make install # Install corrade -WORKDIR /sources RUN git clone https://github.com/mosra/corrade.git -WORKDIR /sources/corrade -RUN git checkout 0d149ee9f26a6e35c30b1b44f281b272397842f5 -WORKDIR /sources/corrade/build -RUN cmake .. -RUN make -j -RUN sudo make install +RUN cd corrade && git checkout 0d149ee9f26a6e35c30b1b44f281b272397842f5 \ + && mkdir build && cd build && cmake .. && make -j && sudo make install # Install robot_controller -WORKDIR /sources RUN git clone https://github.com/epfl-lasa/robot_controllers.git -WORKDIR /sources/robot_controllers/build -RUN cmake .. -RUN make -j -RUN sudo make install +RUN cd robot_controllers && mkdir build && cd build \ + && cmake .. && make -j && sudo make install -# Install ros_control -RUN sudo apt-get install -y ros-${ROS_DISTRO}-ros-control ros-${ROS_DISTRO}-ros-controllers +# Remove temporari files +RUN sudo ldconfig +RUN rm -rf /tmp/* ### Install gazebo # Install gazebo (9 or 11 depending on distro) WORKDIR /home/${USER} RUN sudo apt-get update RUN if [ "$ROS_DISTRO" = "noetic" ] ; then sudo apt-get install -y gazebo11 ; fi -RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y gazebo9 ; fi +RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y gazebo9 ; fi # A few extra steps to fix gazebo bugs under melodic # RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y mesa-utils libgl1-mesa-glx ; fi @@ -138,3 +133,6 @@ RUN if [ "${USE_SIMD}" = "ON" ] ; \ WORKDIR /home/${USER}/ros_ws RUN source /home/${USER}/.bashrc && rosdep install --from-paths src --ignore-src -r -y RUN source /home/${USER}/.bashrc && catkin_make; + +### Final apt clean +RUN sudo apt update && sudo apt upgrade && sudo apt clean diff --git a/docker/start_docker.bash b/docker/start_docker.bash index a5d86b9..05b1992 100644 --- a/docker/start_docker.bash +++ b/docker/start_docker.bash @@ -3,6 +3,7 @@ IMAGE_NAME="epfl-lasa/iiwa_ros" CONTAINER_NAME="${IMAGE_NAME//[\/.]/-}" USERNAME="ros" MODE=() +USE_NVIDIA_TOOLKIT=true # Help @@ -58,9 +59,22 @@ if $SHOW_HELP; then exit 1 fi +# Handle network +docker network inspect multinet >/dev/null 2>&1 || \ + docker network create --subnet=172.20.0.0/16 --gateway=172.20.0.1 multinet +FWD_ARGS+=("--network=multinet") + + +# Handle GPU usage +[[ ${USE_NVIDIA_TOOLKIT} = true ]] && GPU_FLAG="--gpus all" || GPU_FLAG="" + +# Other +FWD_ARGS+=("--privileged") + aica-docker \ "${MODE}" \ "${IMAGE_NAME}" \ -u "${USERNAME}" \ -n "${CONTAINER_NAME}" \ + ${GPU_FLAG} \ "${FWD_ARGS[@]}" \ \ No newline at end of file From 5d140434860d008a8c3e9681038c947f01561b87 Mon Sep 17 00:00:00 2001 From: niederha Date: Thu, 19 Jan 2023 15:40:33 +0100 Subject: [PATCH 03/23] Cleaned docker, faster ROS, added the install docker script (maybe not needed) --- docker/Dockerfile | 6 +++--- docker/build_docker.bash | 2 +- docker/install_docker.sh | 13 +++++++++++-- docker/start_docker.bash | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 40ce49c..1ca0e96 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,9 +9,9 @@ ARG GIT_EMAIL="" ARG USE_SIMD=OFF # Graphics capabilitees -ENV QT_X11_NO_MITSHM 1 -ENV NVIDIA_VISIBLE_DEVICES all -ENV NVIDIA_DRIVER_CAPABILITIES all +# ENV QT_X11_NO_MITSHM 1 +# ENV NVIDIA_VISIBLE_DEVICES all +# ENV NVIDIA_DRIVER_CAPABILITIES all # Tell docker we want to use bash instead of sh in general SHELL ["/bin/bash", "-c"] diff --git a/docker/build_docker.bash b/docker/build_docker.bash index 787dbd6..d19ddf2 100644 --- a/docker/build_docker.bash +++ b/docker/build_docker.bash @@ -2,7 +2,7 @@ # Name and base and options IMAGE_NAME=epfl-lasa/iiwa_ros # Chose any name for your image (but make sure to report it in start_docker) -ROS_DISTRO=melodic # Possible: noetic, melodic +ROS_DISTRO=noetic # Possible: noetic, melodic USE_SIMD=ON # Possible: ON, OFF BASE_IMAGE=ghcr.io/aica-technology/ros-ws:${ROS_DISTRO} # Do not modify diff --git a/docker/install_docker.sh b/docker/install_docker.sh index f5a7d6d..be7c540 100644 --- a/docker/install_docker.sh +++ b/docker/install_docker.sh @@ -1,5 +1,14 @@ #!/bin/bash -mkdir tmp -git clone git@github.com:aica-technology/docker-images.git tmp +# Install aica docker +if ! command -v aica-docker &> /dev/null +then + echo "Installing AICA docker" + git clone git@github.com:aica-technology/docker-images.git /tmp + sudo bash /tmp/docker-images/scripts/install-aica-docker-sh + rm -rf /tmp/docker-images +else + echo "AICA docker already found" +fi + diff --git a/docker/start_docker.bash b/docker/start_docker.bash index 05b1992..ad2d22c 100644 --- a/docker/start_docker.bash +++ b/docker/start_docker.bash @@ -3,8 +3,9 @@ IMAGE_NAME="epfl-lasa/iiwa_ros" CONTAINER_NAME="${IMAGE_NAME//[\/.]/-}" USERNAME="ros" MODE=() -USE_NVIDIA_TOOLKIT=true +# If you're using a graphic card +USE_NVIDIA_TOOLKIT=true # Help HELP_MESSAGE="Usage: ./start_dockers.sh [interactive | server | connect] [-i, --image] [-u, --user] From 26efb040b97268ed608b6ac368902260ffe04f19 Mon Sep 17 00:00:00 2001 From: niederha Date: Mon, 23 Jan 2023 12:52:58 +0100 Subject: [PATCH 04/23] Corrected network setup to enable to read topics outside the container --- docker/Dockerfile | 5 ----- docker/build_docker.bash | 6 +++++- docker/start_docker.bash | 8 +++----- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 1ca0e96..40c9601 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,11 +8,6 @@ ARG GIT_NAME="" ARG GIT_EMAIL="" ARG USE_SIMD=OFF -# Graphics capabilitees -# ENV QT_X11_NO_MITSHM 1 -# ENV NVIDIA_VISIBLE_DEVICES all -# ENV NVIDIA_DRIVER_CAPABILITIES all - # Tell docker we want to use bash instead of sh in general SHELL ["/bin/bash", "-c"] diff --git a/docker/build_docker.bash b/docker/build_docker.bash index d19ddf2..dace32b 100644 --- a/docker/build_docker.bash +++ b/docker/build_docker.bash @@ -43,7 +43,11 @@ while [ "$#" -gt 0 ]; do done # Try to pull image -docker pull "${BASE_IMAGE}" || echo -e "\033[31mCould not pull docker image ${BASE_IMAGE}" +if [[ "$(docker images -q ${BASE_IMAGE} 2> /dev/null)" == "" ]]; \ + then echo "Base image already exists on the computer, proceeding to build docker"; + else echo -e "Base image does not exists ont the computer, pulling it..."; \ + docker pull "${BASE_IMAGE}" || echo -e "\033[31mCould not pull docker image ${BASE_IMAGE}"; +fi # Setup build flags BUILD_FLAGS+=(--build-arg ROS_DISTRO="${ROS_DISTRO}") diff --git a/docker/start_docker.bash b/docker/start_docker.bash index ad2d22c..f59d4ec 100644 --- a/docker/start_docker.bash +++ b/docker/start_docker.bash @@ -60,11 +60,9 @@ if $SHOW_HELP; then exit 1 fi -# Handle network -docker network inspect multinet >/dev/null 2>&1 || \ - docker network create --subnet=172.20.0.0/16 --gateway=172.20.0.1 multinet -FWD_ARGS+=("--network=multinet") - +# network for ros +FWD_ARGS+=(--net=host) +FWD_ARGS+=(--env ROS_HOSTNAME="$(hostname)") # Handle GPU usage [[ ${USE_NVIDIA_TOOLKIT} = true ]] && GPU_FLAG="--gpus all" || GPU_FLAG="" From af7f9224853007dc22911458f630398a6b909cb4 Mon Sep 17 00:00:00 2001 From: niederha Date: Mon, 23 Jan 2023 13:04:30 +0100 Subject: [PATCH 05/23] Fixed base image existence check --- docker/build_docker.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/build_docker.bash b/docker/build_docker.bash index dace32b..8e3eb96 100644 --- a/docker/build_docker.bash +++ b/docker/build_docker.bash @@ -43,7 +43,7 @@ while [ "$#" -gt 0 ]; do done # Try to pull image -if [[ "$(docker images -q ${BASE_IMAGE} 2> /dev/null)" == "" ]]; \ +if [[ "$(docker images -q ${BASE_IMAGE} 2> /dev/null)" != "" ]]; \ then echo "Base image already exists on the computer, proceeding to build docker"; else echo -e "Base image does not exists ont the computer, pulling it..."; \ docker pull "${BASE_IMAGE}" || echo -e "\033[31mCould not pull docker image ${BASE_IMAGE}"; From e9fdd4b0407ec0e7859ec52912aa0db93f625523 Mon Sep 17 00:00:00 2001 From: niederha Date: Mon, 30 Jan 2023 12:49:31 +0100 Subject: [PATCH 06/23] Cleaned up dockerfile --- docker/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 40c9601..330a3fa 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -104,9 +104,6 @@ RUN sudo apt-get update RUN if [ "$ROS_DISTRO" = "noetic" ] ; then sudo apt-get install -y gazebo11 ; fi RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y gazebo9 ; fi -# A few extra steps to fix gazebo bugs under melodic -# RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y mesa-utils libgl1-mesa-glx ; fi - # Install gaezbo ros packages RUN sudo apt install -y ros-${ROS_DISTRO}-gazebo-ros-pkgs ros-${ROS_DISTRO}-gazebo-ros-control From 1c2339ce573806666970f9f298fea85f8aedb217 Mon Sep 17 00:00:00 2001 From: niederha Date: Mon, 30 Jan 2023 12:50:57 +0100 Subject: [PATCH 07/23] Added distro and use SMID as flags in the build script --- docker/build_docker.bash | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docker/build_docker.bash b/docker/build_docker.bash index 8e3eb96..a233892 100644 --- a/docker/build_docker.bash +++ b/docker/build_docker.bash @@ -2,7 +2,7 @@ # Name and base and options IMAGE_NAME=epfl-lasa/iiwa_ros # Chose any name for your image (but make sure to report it in start_docker) -ROS_DISTRO=noetic # Possible: noetic, melodic +ROS_DISTRO=noetic # Possible: noetic, melodic USE_SIMD=ON # Possible: ON, OFF BASE_IMAGE=ghcr.io/aica-technology/ros-ws:${ROS_DISTRO} # Do not modify @@ -13,6 +13,8 @@ Options: -r, --rebuild Rebuild with --no-cache option. -v, --verbose Display additional info upon build. -i, --image-name Defines the name given to the image beeing built. + -d, --distro Can be \"noetic\" or \"melodic\". + -smid Build with smid flags on. -h, --help Show this help message." # Parse build flags @@ -31,6 +33,18 @@ while [ "$#" -gt 0 ]; do IMAGE_NAME=$2 shift 2 ;; + -d | --distro) + ROS_DISTRO=$2 + if [[ "$ROS_DISTRO" != "noetic" && "$ROS_DISTRO" != "melodic" ]] ; then + echo -e "\033[31mERROR: Distro \"$ROS_DISTRO\" is not supported"; \ + exit 1; + fi + shift 2 + ;; + -smid) + USE_SIMD=ON + shift 1 + ;; -h | --help) echo "${HELP_MESSAGE}" exit 0 @@ -42,6 +56,7 @@ while [ "$#" -gt 0 ]; do esac done + # Try to pull image if [[ "$(docker images -q ${BASE_IMAGE} 2> /dev/null)" != "" ]]; \ then echo "Base image already exists on the computer, proceeding to build docker"; From c03cc379adb553ad2f1f6a42b092ea8ce2290b9e Mon Sep 17 00:00:00 2001 From: niederha Date: Mon, 30 Jan 2023 12:51:24 +0100 Subject: [PATCH 08/23] Corrected smid flag syntax --- docker/build_docker.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/build_docker.bash b/docker/build_docker.bash index a233892..18a55eb 100644 --- a/docker/build_docker.bash +++ b/docker/build_docker.bash @@ -14,7 +14,7 @@ Options: -v, --verbose Display additional info upon build. -i, --image-name Defines the name given to the image beeing built. -d, --distro Can be \"noetic\" or \"melodic\". - -smid Build with smid flags on. + --smid Build with smid flags on. -h, --help Show this help message." # Parse build flags @@ -41,7 +41,7 @@ while [ "$#" -gt 0 ]; do fi shift 2 ;; - -smid) + --smid) USE_SIMD=ON shift 1 ;; From 79116e8fbfb2c80e3d2ad2d2c207806e04d4f9e8 Mon Sep 17 00:00:00 2001 From: niederha Date: Mon, 30 Jan 2023 12:52:09 +0100 Subject: [PATCH 09/23] Added automatic detection of nvidi GPUs --- docker/start_docker.bash | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docker/start_docker.bash b/docker/start_docker.bash index f59d4ec..62b29c2 100644 --- a/docker/start_docker.bash +++ b/docker/start_docker.bash @@ -3,10 +3,16 @@ IMAGE_NAME="epfl-lasa/iiwa_ros" CONTAINER_NAME="${IMAGE_NAME//[\/.]/-}" USERNAME="ros" MODE=() - -# If you're using a graphic card USE_NVIDIA_TOOLKIT=true +# Chek if a NVIDIA GPU is available +if [[ $(sudo lshw -C display | grep vendor) =~ NVIDIA ]]; then + USE_NVIDIA_TOOLKIT=true + echo "Detected NVIDIA graphic card, giving access to the container." +else + USE_NVIDIA_TOOLKIT=false +fi + # Help HELP_MESSAGE="Usage: ./start_dockers.sh [interactive | server | connect] [-i, --image] [-u, --user] Build the '${IMAGE_NAME}' image. From d3f107d8bc564bb0ac42c9286b82c0ff911e85d8 Mon Sep 17 00:00:00 2001 From: niederha Date: Mon, 30 Jan 2023 14:04:36 +0100 Subject: [PATCH 10/23] Updated start docker to make server and connect options work --- docker/start_docker.bash | 44 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/docker/start_docker.bash b/docker/start_docker.bash index 62b29c2..365dd0d 100644 --- a/docker/start_docker.bash +++ b/docker/start_docker.bash @@ -3,15 +3,7 @@ IMAGE_NAME="epfl-lasa/iiwa_ros" CONTAINER_NAME="${IMAGE_NAME//[\/.]/-}" USERNAME="ros" MODE=() -USE_NVIDIA_TOOLKIT=true - -# Chek if a NVIDIA GPU is available -if [[ $(sudo lshw -C display | grep vendor) =~ NVIDIA ]]; then - USE_NVIDIA_TOOLKIT=true - echo "Detected NVIDIA graphic card, giving access to the container." -else - USE_NVIDIA_TOOLKIT=false -fi +USE_NVIDIA_TOOLKIT=() # Help HELP_MESSAGE="Usage: ./start_dockers.sh [interactive | server | connect] [-i, --image] [-u, --user] @@ -60,22 +52,42 @@ while [ "$#" -gt 0 ]; do esac done +# Help verbose if $SHOW_HELP; then echo $HELP_MESSAGE aica-docker $MODE -h exit 1 fi -# network for ros -FWD_ARGS+=(--net=host) -FWD_ARGS+=(--env ROS_HOSTNAME="$(hostname)") +# Handle interactive/server specific arguments +if [ "${MODE}" != "connect" ]; then + + # Check if a NVIDIA GPU is available + if [[ $(sudo lshw -C display | grep vendor) =~ NVIDIA ]]; then + USE_NVIDIA_TOOLKIT=true + echo "Detected NVIDIA graphic card, giving access to the container." + else + USE_NVIDIA_TOOLKIT=false + fi + + # network for ros + FWD_ARGS+=(--net=host) + FWD_ARGS+=(--env ROS_HOSTNAME="$(hostname)") -# Handle GPU usage -[[ ${USE_NVIDIA_TOOLKIT} = true ]] && GPU_FLAG="--gpus all" || GPU_FLAG="" + # Handle GPU usage + [[ ${USE_NVIDIA_TOOLKIT} = true ]] && GPU_FLAG="--gpus all" || GPU_FLAG="" -# Other -FWD_ARGS+=("--privileged") + # Other + FWD_ARGS+=("--privileged") +fi + +# Trick aica-docker into making a server on a host network container +if [ "${MODE}" == "server" ]; then + FWD_ARGS+=("--detach") + MODE=interactive +fi +# Start docker using aica aica-docker \ "${MODE}" \ "${IMAGE_NAME}" \ From 628a28125ef89dc5c39d2ea302a808cb7fe6f5f8 Mon Sep 17 00:00:00 2001 From: niederha Date: Tue, 31 Jan 2023 13:19:05 +0100 Subject: [PATCH 11/23] Corrected default use_smid flag to OFF --- docker/build_docker.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/build_docker.bash b/docker/build_docker.bash index 18a55eb..f2aa536 100644 --- a/docker/build_docker.bash +++ b/docker/build_docker.bash @@ -3,7 +3,7 @@ # Name and base and options IMAGE_NAME=epfl-lasa/iiwa_ros # Chose any name for your image (but make sure to report it in start_docker) ROS_DISTRO=noetic # Possible: noetic, melodic -USE_SIMD=ON # Possible: ON, OFF +USE_SIMD=OFF # Possible: ON, OFF BASE_IMAGE=ghcr.io/aica-technology/ros-ws:${ROS_DISTRO} # Do not modify # Help From 7cf01840172fc6981c6bfe41b288345317a15654 Mon Sep 17 00:00:00 2001 From: niederha Date: Tue, 31 Jan 2023 13:19:31 +0100 Subject: [PATCH 12/23] Added notes on what to do in the script --- docker/install_docker.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docker/install_docker.sh b/docker/install_docker.sh index be7c540..900c070 100644 --- a/docker/install_docker.sh +++ b/docker/install_docker.sh @@ -1,12 +1,16 @@ #!/bin/bash +# If not installed, install docker with post install + +# If nvidia, install nividia-docker2 + # Install aica docker -if ! command -v aica-docker &> /dev/null -then - echo "Installing AICA docker" +if [ ! command -v aica-docker &> /dev/null ]; then + echo "Installing aica-docker..." git clone git@github.com:aica-technology/docker-images.git /tmp - sudo bash /tmp/docker-images/scripts/install-aica-docker-sh + sudo bash /tmp/docker-images/scripts/install-aica-docker.sh rm -rf /tmp/docker-images + echo "aica-docker properly installed" else echo "AICA docker already found" fi From d11afc3656c8e1a2ddb7d67cb158de26a31da21b Mon Sep 17 00:00:00 2001 From: niederha Date: Tue, 31 Jan 2023 13:20:08 +0100 Subject: [PATCH 13/23] Sloved the issue of launching a docker when one with the same name is already running --- docker/start_docker.bash | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker/start_docker.bash b/docker/start_docker.bash index 365dd0d..1069639 100644 --- a/docker/start_docker.bash +++ b/docker/start_docker.bash @@ -62,6 +62,12 @@ fi # Handle interactive/server specific arguments if [ "${MODE}" != "connect" ]; then + # Check if a conitainer with this name is already running + if [ "$( docker container inspect -f '{{.State.Status}}' ${CONTAINER_NAME} 2>/dev/null)" == "running" ]; then + echo "A container named ${CONTAINER_NAME} is already running. Stopping it." + docker stop ${CONTAINER_NAME} + fi + # Check if a NVIDIA GPU is available if [[ $(sudo lshw -C display | grep vendor) =~ NVIDIA ]]; then USE_NVIDIA_TOOLKIT=true From a3af04b78cb8ae2714d3f2b463bd534549c9b55c Mon Sep 17 00:00:00 2001 From: niederha Date: Wed, 1 Feb 2023 11:35:40 +0100 Subject: [PATCH 14/23] Added install docker script --- docker/install_docker.sh | 119 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 7 deletions(-) diff --git a/docker/install_docker.sh b/docker/install_docker.sh index 900c070..2989056 100644 --- a/docker/install_docker.sh +++ b/docker/install_docker.sh @@ -1,18 +1,123 @@ #!/bin/bash -# If not installed, install docker with post install +# If not installed, suggest install docker +if [ ! command -v docker &> /dev/null ]; then + + while true; do + read -p "Docker command not available, do you whish to install it (y/n)?" yn + case $yn in + [Yy]* ) + + # Docker installation according to https://docs.docker.com/engine/install/ubuntu/ + echo "Docker not found, installing..." + sudo apt-get update + sudo apt-get install ca-certificates curl gnupg lsb-release + sudo mkdir -p /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update + sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin + echo "Docker installed" + break;; + + [Nn]* ) + echo "Skipping docker installation. Note that it will likely impair your ability to run dockers" + break;; + + * ) echo "Please answer y or n";; + esac + done +else + echo "Docker already found, skipping install." +fi + + +# Check docker post install +if ! [ $(getent group docker) ] || ! id -nG | grep -qw "docker" ; then # ! [ id -nG | grep -qw "docker" ]; then + + while true; do + read -p "Docker post install steps not done, do you whish to do it (y/n)?" yn + case $yn in + [Yy]* ) + # Docker post-installation according to https://docs.docker.com/engine/install/linux-postinstall/ + echo "Running docker post install..." + + # Create docker group if not already done + if ! [ $(getent group docker) ] ; then + sudo groupadd docker + fi + + # Add user to docker group + sudo usermod -aG docker $USER + newgrp docker + break;; + [Nn]* ) + echo "Skipping docker post install steps. Without it this user might have to call docker with sudo everytime." + break;; + * ) echo "Please answer y or n";; + esac + done + +else + echo "Docker post install already done. Skipping step." +fi # If nvidia, install nividia-docker2 +if [[ $(sudo lshw -C display | grep vendor) =~ NVIDIA ]]; then + if [ $(dpkg-query -W -f='${Status}' nvidia-docker2 2>/dev/null | grep -c "ok installed") -eq 0 ]; then + + while true; do + read -p "You have a nvidia graphic card. Do you wish to install nvidia-docker2 to use it in your container (y/n)?" yn + case $yn in + [Yy]* ) + # nvidia-docker2 install according to: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html + echo "Installing nvidia-docker2" + distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \ + && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ + && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \ + sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ + sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list + sudo apt-get update + sudo apt-get install -y nvidia-docker2 + sudo systemctl restart docker + echo "Installation done." + break;; + [Nn]* ) + echo "Skipping install of nividia-docker2. Note that this might create some issues with the GUI of your application in the container." + break;; + * ) echo "Please answer y or n";; + esac + done + else + echo "nividia-docker2 already installed, skipping this step." + fi +else + echo "No nvidia graphic cards detected, skipping install of nvidia-docker2." +fi + # Install aica docker if [ ! command -v aica-docker &> /dev/null ]; then - echo "Installing aica-docker..." - git clone git@github.com:aica-technology/docker-images.git /tmp - sudo bash /tmp/docker-images/scripts/install-aica-docker.sh - rm -rf /tmp/docker-images - echo "aica-docker properly installed" + while true; do + read -p "aica-docker command not found, do you whish to install it? (y/n)?" yn + case $yn in + [Yy]* ) + echo "Installing aica-docker..." + git clone git@github.com:aica-technology/docker-images.git /tmp + sudo bash /tmp/docker-images/scripts/install-aica-docker.sh + rm -rf /tmp/docker-images + echo "aica-docker installed." + break;; + [Nn]* ) + echo "Skipping installation of aica-docker. This might impair the start docker scripts execution." + break;; + * ) echo "Please answer y or n";; + esac + done else - echo "AICA docker already found" + echo "aica-docker already found, skipping install." fi From fcecfeddcc3ef8540f12ba851c137d23e664cb4e Mon Sep 17 00:00:00 2001 From: niederha Date: Wed, 1 Feb 2023 15:00:08 +0100 Subject: [PATCH 15/23] Renamed files with more common extensions --- docker/{build_docker.bash => build_docker.sh} | 0 docker/{start_docker.bash => start_docker.sh} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename docker/{build_docker.bash => build_docker.sh} (100%) rename docker/{start_docker.bash => start_docker.sh} (100%) diff --git a/docker/build_docker.bash b/docker/build_docker.sh similarity index 100% rename from docker/build_docker.bash rename to docker/build_docker.sh diff --git a/docker/start_docker.bash b/docker/start_docker.sh similarity index 100% rename from docker/start_docker.bash rename to docker/start_docker.sh From 40888677d2e0ebb570a462666ac68c8991ba45fc Mon Sep 17 00:00:00 2001 From: niederha Date: Wed, 1 Feb 2023 15:01:12 +0100 Subject: [PATCH 16/23] Clearer message in install_docker script --- docker/install_docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/install_docker.sh b/docker/install_docker.sh index 2989056..1871bdc 100644 --- a/docker/install_docker.sh +++ b/docker/install_docker.sh @@ -38,7 +38,7 @@ fi if ! [ $(getent group docker) ] || ! id -nG | grep -qw "docker" ; then # ! [ id -nG | grep -qw "docker" ]; then while true; do - read -p "Docker post install steps not done, do you whish to do it (y/n)?" yn + read -p "Docker post install steps for Linux not done, do you whish to do it (y/n)?" yn case $yn in [Yy]* ) # Docker post-installation according to https://docs.docker.com/engine/install/linux-postinstall/ From 92ccfa9e9c0b5d561393a11a04878b3d7b071b64 Mon Sep 17 00:00:00 2001 From: niederha Date: Wed, 1 Feb 2023 15:01:30 +0100 Subject: [PATCH 17/23] added dockeringore file --- docker/.dockerignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docker/.dockerignore diff --git a/docker/.dockerignore b/docker/.dockerignore new file mode 100644 index 0000000..e900864 --- /dev/null +++ b/docker/.dockerignore @@ -0,0 +1,6 @@ +.git* +install_docker.sh +build_docker.sh +start_docker.sh +Dockerfile +README.md From 69e9c012e89276661422d2e5a9af73d7aefe79d7 Mon Sep 17 00:00:00 2001 From: niederha Date: Thu, 2 Feb 2023 10:51:09 +0100 Subject: [PATCH 18/23] Added documentation --- docker/README.md | 116 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/docker/README.md b/docker/README.md index e69de29..6ec08a7 100644 --- a/docker/README.md +++ b/docker/README.md @@ -0,0 +1,116 @@ +# Docker for iiwa_ros + +This folder holds a docker for iiwa_ros. This is an out of the box docker infrastructure that allows you to build an image with ros melodic or noetic containing iiwa_ros and all its dependencies, and sharing the network of the host computer. +## Prerequisite + +### OS + +**Linux:** This docker was developed to be used under Ubuntu. It has been tested on Ubuntu 20.04 but should work with any reasonably recent version. It should also be usable on other Linux-based os but will probably require some adaptations. + +**OS-X:** For OSX users, the docker should work. However it is to be expected that the graphical interfaces such as Gazebo will not be working. This might be fixable for specific cases but support is not provided by this package. This is due to the fact that solutions to this may vary a lot depending on the hardware and versions. Also `install_docker.sh` will most likely not work on OS-X. However the user should be able to recreate by hand the necessary steps. + +**Windows:** This will not work under windows. However I would suggest using [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/about) which should allow the user to run this docker on a windows computer. + +### Network + +The docker container will share the network of the host. So if you plan to use it to communicate with the IIWA robot, you should first make sure that your host network and ports are correctly configured. Check the main README.md for more information about that. + +### Nvidia GPU + +Some graphic application (e.g: gazebo9) might need explicit access to your NVIDIA GPU to run without error if you have one. So if you have a NVIDIA GPU, make sure that you have installed a driver and that it is up to date. If you encounter issues with it, try upgrading to the latest LTS driver supported by you GPU. +Not that a NVIDIA GPU is not required to run this. The docker should work well even if you don't have one. + +## Installation + +To install the necessary dependencies to run this docker you can either do it manually or execute `install_docker.sh` which will check take you through the installation steps. + +### Short cut (recommended) + +Run: +```bash +bash install_docker.sh +``` + +This will check which commands are already on your system and propose you to install the missing ones. Unless you have a specific reason to decline, it is strongly suggested to say yes to all installations. + +### Manual installation + +If for some reasons you are not able to use the install script, you can install the dependencies by hand. + +1. This package requires you to have docker installed. More information about this can be found [here](https://docs.docker.com/engine/install/). If you are on Linux don't forget to run the [post install steps](https://docs.docker.com/engine/install/linux-postinstall/) + +2. In addition the `start_docker.sh` script uses a command form [aica-technology/docker-images](https://github.com/aica-technology/docker-images) to cut down on code. To install it download the repo and execute `scripts/install-aica-docker.sh`. This is also a neat command to use is you are developing other dockers. +3. If you have a NVIDIA GPU you will also need to install `nvidia-docker2`. Installation instruction can be found [here](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) + +## Building image + +To build the docker image simply run: +```bash +bash build_docker.sh +``` + +This script has a few options that can be used to specify various build variations. The options are: +```bash +Usage: ./build.sh [-r, --rebuild] [-v, --verbose] [-i, --image-name] [-d, --distro] [--smid] +Build the epfl-lasa/iiwa_ros image. +Options: + -r, --rebuild Rebuild with --no-cache option. + -v, --verbose Display additional info upon build. + -i, --image-name Defines the name given to the image beeing built. Default: epfl-lasa/iiwa_ros + -d, --distro Can be \"noetic\" or \"melodic\", default: noetic + --smid Build with smid flags on. Flags are off by default. + -h, --help Show this help message." +``` + +## Spinning container + +To run the container, use: +```bash +bash start_docker.sh interactive +``` + +This will open the container command prompt. The user is `ros`, and starts in a ros workspace which is already built and sourced. So you might for example directly input a command such as: +```bash +roslaunch iiwa_gazebo iiwa_gazebo.launch +``` + +### Modes + +`start_docker.sh` offers 3 modes. + +- `interactive`: Opens a prompt connected to the container. Stops the container as soon as the prompt is closed +- `server`: Starts the container in the background. The container will only be stopped when stopped explicitly or when `start_docker` is called again with interactive or server. (We always stop the previous docker before starting it again) +- `connect`: Allows to connect to the container which was started with the server command. This opens a prompt to the container. You can have as many prompt connected to a server as you want. + +### Options + +In addition a few options can be used when using `start_docker`: + +```bash +Usage: ./start_dockers.sh [interactive | server | connect] [-i, --image] [-u, --user] +Build the '${IMAGE_NAME}' image. +Options: + interactive Spin the image in the console + server Spin the image as an ssh server + connect Connects to an active container + -i, --image The name of the image to use to start the container + -u, --user Specify the name of the login user. (optional) + -h, --help Show this help message and the one from aica-docker + Additional arguments are passed to the aica-docker command. +``` + +## Technical notes + +- The docker builds on top of docker images from the [aica-docker/docker-images](https://github.com/aica-technology/docker-images). And the `start_docker.sh` script uses their set of command. This might not be the best approach but this works for now so it is good enough. +- When building the docker the iiwa-ros repository is cloned into the image. A better approach would probably be to copy it from the host computer. This would likely save a little time at build (who ever does that should also make sure that the .dockerignore is also updated) +- `start_docker.sh` checks for NVIDIA GPU and automatically chooses to enable it for the container if it is there. The reason is that it seems gazebo has some issues if there is only an NVIDIA GPU and the container does not have access. But it might still be nice to have an option to override this automatic detection. Also, the output of the command is printed on the terminal, we could do without. Maybe check if there is an NVIDIA driver instead of a physical GPU? +- In my case gazebo still outputs an error on the terminal but everything ends up working fine. I think this is partly because gazebo9 and gazebo11 are fairly old. So if everything else works just ignore error messages. +- Note that through the `build_docker.sh` you will forward your git user name and git email to the docker image. This will allow you to push and pull in the docker. +- When you build the docker using SIMD flags, the .bashrc in the image is updated to include `export ENABLE_SIMD=ON`. This enables SIMD for iiwa_ros without having to write it explicitly at every catkin_make. Just know it's there. +- `start_docker.bash` start the docker with `--net=host` which means the container has the same ip as the host. This enables to share ros communication seemlessly in, out and between containers. +- Containers names are hard coded in `start_docker.sh`. If you want multiple ones on the same machine you need to change manually the container name in the script... Well it's not practical, I didn't think of that... But in the same time, why would you want to do that? Feel free to fix it with an new option to specify container name it you run into this use case + +## Authors/Maintainers + +- Loïc Niederhauser: loic.niederhauser@epfl.ch, @niderha on github. + From f8bdd03cb3234b0562e412a94fe9eb4f5ac84e64 Mon Sep 17 00:00:00 2001 From: niederha Date: Thu, 2 Feb 2023 10:51:38 +0100 Subject: [PATCH 19/23] Better help message --- docker/build_docker.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/build_docker.sh b/docker/build_docker.sh index f2aa536..749971d 100644 --- a/docker/build_docker.sh +++ b/docker/build_docker.sh @@ -7,14 +7,14 @@ USE_SIMD=OFF # Possible: ON, OFF BASE_IMAGE=ghcr.io/aica-technology/ros-ws:${ROS_DISTRO} # Do not modify # Help -HELP_MESSAGE="Usage: ./build.sh [-r, --rebuild] [-v, --verbose] [-i, --image-name] +HELP_MESSAGE="Usage: ./build.sh [-r, --rebuild] [-v, --verbose] [-i, --image-name] [-d, --distro] [--smid] Build the '${IMAGE_NAME}' image. Options: -r, --rebuild Rebuild with --no-cache option. -v, --verbose Display additional info upon build. - -i, --image-name Defines the name given to the image beeing built. - -d, --distro Can be \"noetic\" or \"melodic\". - --smid Build with smid flags on. + -i, --image-name Defines the name given to the image beeing built. Default: ${IMAGE_NAME} + -d, --distro Can be \"noetic\" or \"melodic\", default: ${ROS_DISTRO} + --smid Build with smid flags on. Flags are off by default. -h, --help Show this help message." # Parse build flags From ac219a8820bbd05489276caaf1099f06f91f8e84 Mon Sep 17 00:00:00 2001 From: niederha Date: Wed, 15 Feb 2023 13:56:24 +0100 Subject: [PATCH 20/23] Moved gazebo install before git clones to make better use of caching --- docker/Dockerfile | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 330a3fa..88078e9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,17 +11,6 @@ ARG USE_SIMD=OFF # Tell docker we want to use bash instead of sh in general SHELL ["/bin/bash", "-c"] -### Add a few tools -RUN sudo apt-get update && sudo apt-get install -y \ - bash-completion \ - silversearcher-ag \ - apt-transport-https \ - less \ - alsa-utils \ - ros-${ROS_DISTRO}-ros-control \ - ros-${ROS_DISTRO}-ros-controllers \ - && sudo apt-get upgrade -y && sudo apt-get clean - ### Add the user to the current GID of the host to avoid permisson issues in volumes # AICA uses the same name for user and user group ENV USER_GROUP=${USER} @@ -41,6 +30,27 @@ RUN sudo apt update RUN if [ "${ROS_DISTRO}" == "noetic" ] ; \ then sudo apt install python-is-python3 ; fi + +### Add a few tools +RUN sudo apt-get update && sudo apt-get install -y \ + bash-completion \ + silversearcher-ag \ + apt-transport-https \ + less \ + alsa-utils \ + ros-${ROS_DISTRO}-ros-control \ + ros-${ROS_DISTRO}-ros-controllers \ + && sudo apt-get upgrade -y && sudo apt-get clean + +# Install gazebo (9 or 11 depending on distro) +WORKDIR /home/${USER} +RUN sudo apt-get update +RUN if [ "$ROS_DISTRO" = "noetic" ] ; then sudo apt-get install -y gazebo11 ; fi +RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y gazebo9 ; fi + +# Install gaezbo ros packages +RUN sudo apt install -y ros-${ROS_DISTRO}-gazebo-ros-pkgs ros-${ROS_DISTRO}-gazebo-ros-control + # Handle SIMD option RUN if [ "${USE_SIMD}" = "ON" ] ; \ then export CMAKE_CXX_FLAGS="-march=native -faligned-new" ; fi @@ -97,16 +107,6 @@ RUN cd robot_controllers && mkdir build && cd build \ RUN sudo ldconfig RUN rm -rf /tmp/* -### Install gazebo -# Install gazebo (9 or 11 depending on distro) -WORKDIR /home/${USER} -RUN sudo apt-get update -RUN if [ "$ROS_DISTRO" = "noetic" ] ; then sudo apt-get install -y gazebo11 ; fi -RUN if [ "$ROS_DISTRO" = "melodic" ] ; then sudo apt-get install -y gazebo9 ; fi - -# Install gaezbo ros packages -RUN sudo apt install -y ros-${ROS_DISTRO}-gazebo-ros-pkgs ros-${ROS_DISTRO}-gazebo-ros-control - ### Install IIWA ROS WORKDIR /home/${USER}/ros_ws/src RUN git clone https://github.com/epfl-lasa/iiwa_ros.git From 1e3a0bcad5a1eccdfd09248c2cafbe7a5db4ec21 Mon Sep 17 00:00:00 2001 From: niederha Date: Wed, 15 Feb 2023 14:03:03 +0100 Subject: [PATCH 21/23] Following suggestion: added sha256 of bases to readme and warning about screen share on window --- docker/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/README.md b/docker/README.md index 6ec08a7..c2ce16d 100644 --- a/docker/README.md +++ b/docker/README.md @@ -9,7 +9,7 @@ This folder holds a docker for iiwa_ros. This is an out of the box docker infras **OS-X:** For OSX users, the docker should work. However it is to be expected that the graphical interfaces such as Gazebo will not be working. This might be fixable for specific cases but support is not provided by this package. This is due to the fact that solutions to this may vary a lot depending on the hardware and versions. Also `install_docker.sh` will most likely not work on OS-X. However the user should be able to recreate by hand the necessary steps. -**Windows:** This will not work under windows. However I would suggest using [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/about) which should allow the user to run this docker on a windows computer. +**Windows:** This will not work under windows. However I would suggest using [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/about) which should allow the user to run this docker on a windows computer. However display sharing issues are still to be expected. ### Network @@ -102,6 +102,9 @@ Options: ## Technical notes - The docker builds on top of docker images from the [aica-docker/docker-images](https://github.com/aica-technology/docker-images). And the `start_docker.sh` script uses their set of command. This might not be the best approach but this works for now so it is good enough. +- The tested base images versions are: + - [ros-ws:melodic](https://github.com/aica-technology/docker-images/pkgs/container/ros-ws): sha256:d1ab8c7a5e28dd3fa71ebe051ac0937207adf03215235386a1a0edea855d68d2 + - [ros-ws:noetic](https://github.com/aica-technology/docker-images/pkgs/container/ros-ws): sha256:6c439fedd5b475995187a7206b8cd6f0f2651b809dd689aba5641f3975c61b7f - When building the docker the iiwa-ros repository is cloned into the image. A better approach would probably be to copy it from the host computer. This would likely save a little time at build (who ever does that should also make sure that the .dockerignore is also updated) - `start_docker.sh` checks for NVIDIA GPU and automatically chooses to enable it for the container if it is there. The reason is that it seems gazebo has some issues if there is only an NVIDIA GPU and the container does not have access. But it might still be nice to have an option to override this automatic detection. Also, the output of the command is printed on the terminal, we could do without. Maybe check if there is an NVIDIA driver instead of a physical GPU? - In my case gazebo still outputs an error on the terminal but everything ends up working fine. I think this is partly because gazebo9 and gazebo11 are fairly old. So if everything else works just ignore error messages. @@ -113,4 +116,3 @@ Options: ## Authors/Maintainers - Loïc Niederhauser: loic.niederhauser@epfl.ch, @niderha on github. - From d3305c1c3cac7acc3b91a4671f9b3e541a4b7950 Mon Sep 17 00:00:00 2001 From: niederha Date: Wed, 15 Feb 2023 20:07:53 +0100 Subject: [PATCH 22/23] Added reference to the specific commit that this script works with from AICA-docker + specified it in the install script --- docker/README.md | 2 +- docker/install_docker.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/README.md b/docker/README.md index c2ce16d..7a5dcc9 100644 --- a/docker/README.md +++ b/docker/README.md @@ -101,7 +101,7 @@ Options: ## Technical notes -- The docker builds on top of docker images from the [aica-docker/docker-images](https://github.com/aica-technology/docker-images). And the `start_docker.sh` script uses their set of command. This might not be the best approach but this works for now so it is good enough. +- The docker builds on top of docker images from the [aica-docker/docker-images](https://github.com/aica-technology/docker-images). The install script checks out the And the `start_docker.sh` script uses their set of command. This might not be the best approach but this works for now so it is good enough. At the time of merging the latest commit working with these script is [5f8d908](https://github.com/aica-technology/docker-images/commit/5f8d9084b2d7b4fb69631b9e69aa72f64d7f7843) on main. Although it is likely to work with later commits. Note that the install script will install the `aica-docker` command from this commit. - The tested base images versions are: - [ros-ws:melodic](https://github.com/aica-technology/docker-images/pkgs/container/ros-ws): sha256:d1ab8c7a5e28dd3fa71ebe051ac0937207adf03215235386a1a0edea855d68d2 - [ros-ws:noetic](https://github.com/aica-technology/docker-images/pkgs/container/ros-ws): sha256:6c439fedd5b475995187a7206b8cd6f0f2651b809dd689aba5641f3975c61b7f diff --git a/docker/install_docker.sh b/docker/install_docker.sh index 1871bdc..71f3c24 100644 --- a/docker/install_docker.sh +++ b/docker/install_docker.sh @@ -101,11 +101,12 @@ fi # Install aica docker if [ ! command -v aica-docker &> /dev/null ]; then while true; do - read -p "aica-docker command not found, do you whish to install it? (y/n)?" yn + read -p "aica-docker command not found, do you whish to install it? It will install the latest version that worked with this script at the time of developpement. (y/n)?" yn case $yn in [Yy]* ) echo "Installing aica-docker..." git clone git@github.com:aica-technology/docker-images.git /tmp + git --git-dir=/tmp/docker-images/.git checkout 5f8d908 sudo bash /tmp/docker-images/scripts/install-aica-docker.sh rm -rf /tmp/docker-images echo "aica-docker installed." From d2bad738044498d5567be2ab1c71afafe3eb8a2b Mon Sep 17 00:00:00 2001 From: niederha Date: Fri, 21 Apr 2023 16:05:50 +0200 Subject: [PATCH 23/23] Added some missing tools for iiwa communications --- docker/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 88078e9..bb7dde9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -40,6 +40,8 @@ RUN sudo apt-get update && sudo apt-get install -y \ alsa-utils \ ros-${ROS_DISTRO}-ros-control \ ros-${ROS_DISTRO}-ros-controllers \ + net-tools \ + netbase \ && sudo apt-get upgrade -y && sudo apt-get clean # Install gazebo (9 or 11 depending on distro)