From 2dce959122ffedc764ff20d3a59fd290443f6a58 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 11 Apr 2021 21:32:01 -0700 Subject: [PATCH 1/4] Added first working version of docker environment --- Dockerfile | 47 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 19 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..654db19 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +ARG UBUNTU_VERSION +FROM nvidia/opengl:1.1-glvnd-runtime-ubuntu${UBUNTU_VERSION} + +# Add ROS ppa +RUN apt-get update && apt-get install -y --no-install-recommends gnupg2 lsb-release && \ + echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list && \ + apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 + +# DEBIAN_FRONTEND is so tzdata doesn't require user input during the apt install +ENV DEBIAN_FRONTEND=noninteractive +ARG ROS_DISTRO +RUN apt-get update && \ + apt-get install -y ros-${ROS_DISTRO}-desktop-full --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* + +# Add ROS env vars to the bashrc +ENV BASH_ENV="/root/launch.sh" +SHELL ["/bin/bash", "-c"] +ENTRYPOINT ["/bin/bash", "-c"] +RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> $BASH_ENV + +# Install build dependencies +RUN apt-get update && \ + apt-get install -y \ + # ROS Build dependencies + python-rosinstall \ + python-rosinstall-generator \ + python-wstool \ + build-essential \ + # Project-specific build dependencies + python-pip \ + ros-${ROS_DISTRO}-serial \ + ros-${ROS_DISTRO}-joint-state-publisher-gui && \ + rm -rf /var/lib/apt/lists/* + +# Install python dependencies +ARG PYMYCOBOT_VERSION +RUN pip install "pymycobot $PYMYCOBOT_VERSION" --user + +# Build the project +WORKDIR /catkin_ws/src +ADD . myCobotROS +WORKDIR /catkin_ws +RUN catkin_make + +# Let ROS know about the projects launch options +RUN echo "source /catkin_ws/devel/setup.bash" >> $BASH_ENV diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4970052 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3' + +services: + ros: + image: elephantrobotics/myCobotROS + command: ["roslaunch myCobotROS control_slider.launch"] + privileged: true + environment: + PYTHONUNBUFFERED: 1 + QT_X11_NO_MITSHM: 1 + DISPLAY: :1 + volumes: + - "/tmp/.X11-unix:/tmp/.X11-unix:rw" + build: + context: . + args: + UBUNTU_VERSION: "16.04" + ROS_DISTRO: "kinetic" + PYMYCOBOT_VERSION: ">=2<3" From dc89128f1feb79ef4bc82200c23c265cafaa8c95 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 11 Apr 2021 22:22:38 -0700 Subject: [PATCH 2/4] Finish cleaning up the dockerfile --- Dockerfile | 20 +++++++++----------- docker-compose.yml | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 654db19..89d5aa0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,20 @@ + ARG UBUNTU_VERSION + FROM nvidia/opengl:1.1-glvnd-runtime-ubuntu${UBUNTU_VERSION} -# Add ROS ppa -RUN apt-get update && apt-get install -y --no-install-recommends gnupg2 lsb-release && \ - echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list && \ - apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 - -# DEBIAN_FRONTEND is so tzdata doesn't require user input during the apt install -ENV DEBIAN_FRONTEND=noninteractive -ARG ROS_DISTRO -RUN apt-get update && \ - apt-get install -y ros-${ROS_DISTRO}-desktop-full --no-install-recommends && \ - rm -rf /var/lib/apt/lists/* +# For this build, we pull the entire ros image, and then merge the filesystem +# with the nvidia/opengl image, so that displaying to the screen on GPU +# (or without GPU) works through docker. +# I was unable to use the ROS_DISTRO variable here due to this issue: +# https://github.com/docker/for-mac/issues/2155 +COPY --from=osrf/ros:kinetic-desktop-full / / # Add ROS env vars to the bashrc ENV BASH_ENV="/root/launch.sh" SHELL ["/bin/bash", "-c"] ENTRYPOINT ["/bin/bash", "-c"] +ARG ROS_DISTRO RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> $BASH_ENV # Install build dependencies diff --git a/docker-compose.yml b/docker-compose.yml index 4970052..322d9d4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: ros: - image: elephantrobotics/myCobotROS + image: elephantrobotics/my-cobot-ros command: ["roslaunch myCobotROS control_slider.launch"] privileged: true environment: From 61f76d6edb786835637db7a47b43d7649e65e0d3 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 11 Apr 2021 22:29:52 -0700 Subject: [PATCH 3/4] Added documentation for running within docker --- README.md | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 07f95ac..2fa3cbe 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,39 @@ Download ROS [http://wiki.ros.org/ROS/Installation](http://wiki.ros.org/ROS/Installation) -## 1. Installation -### 1.1 Pre-Requriements +## 1. Installation +### Option 1: Docker +There are two ways to run this project. The first is by running the project in a container, and this requires +[installing docker](https://docs.docker.com/engine/install/ubuntu/) and +[installing docker-compose](https://docs.docker.com/compose/install/). The benefit of running in the container is that you can run the project in any version of linux, as long as your kernel +is new enough. + +Once docker is installed, run the following command, and the project should show up: + +``` +docker-compose build && xhost +local:root && docker-compose up +``` + +This command does three things: +1) `docker-compose build` + + This builds the project in a container. That means nothing is installed on your host machine! + The first time this runs, this command will take a long while. After running it once, caching + will allow this command to run quickly. + +2) `xhost +local:root` + + This command gives X the ability to display GUI's from within the docker container + +3) `docker-compose up` + + This runs the image specified in the `docker-compose.yml`, which by default runs + the command `roslaunch myCobotROS control_slider.launch` within the container. + + +### Option 2: Local +#### 1.1 Pre-Requriements For using this package, the [Python api](https://github.com/elephantrobotics/pymycobot.git) library should be installed first. @@ -28,7 +58,7 @@ For using this package, the [Python api](https://github.com/elephantrobotics/pym pip install pymycobot --user ``` -### 1.2 Package Download and Install +#### 1.2 Package Download and Install Install ros package in your src folder of your Catkin workspace. @@ -39,7 +69,7 @@ $ cd ~/catkin_ws $ catkin_make ``` -### 1.3 Test Python API +#### 1.3 Test Python API ```bash cd ~/catkin_ws/src/myCobotROS From 60349997022a22d25794bffb89d1c9dfbc8515c1 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 23 Apr 2021 18:09:49 -0700 Subject: [PATCH 4/4] Add support for computers without NVIDIA hardware --- Dockerfile | 5 ++--- README.md | 6 +++--- docker-compose.yml | 38 +++++++++++++++++++++++++------------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 89d5aa0..008f54c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ +ARG BASE_IMAGE -ARG UBUNTU_VERSION - -FROM nvidia/opengl:1.1-glvnd-runtime-ubuntu${UBUNTU_VERSION} +FROM ${BASE_IMAGE} # For this build, we pull the entire ros image, and then merge the filesystem # with the nvidia/opengl image, so that displaying to the screen on GPU diff --git a/README.md b/README.md index 2fa3cbe..82a20d4 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,11 @@ is new enough. Once docker is installed, run the following command, and the project should show up: ``` -docker-compose build && xhost +local:root && docker-compose up +docker-compose build ros && xhost +local:root && docker-compose up ros ``` This command does three things: -1) `docker-compose build` +1) `docker-compose build ros` This builds the project in a container. That means nothing is installed on your host machine! The first time this runs, this command will take a long while. After running it once, caching @@ -43,7 +43,7 @@ This command does three things: This command gives X the ability to display GUI's from within the docker container -3) `docker-compose up` +3) `docker-compose up ros` This runs the image specified in the `docker-compose.yml`, which by default runs the command `roslaunch myCobotROS control_slider.launch` within the container. diff --git a/docker-compose.yml b/docker-compose.yml index 322d9d4..e11f3fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,31 @@ -version: '3' +version: '3.4' + +x-app: &common + command: [ "roslaunch myCobotROS control_slider.launch" ] + privileged: true + environment: + PYTHONUNBUFFERED: 1 + QT_X11_NO_MITSHM: 1 + DISPLAY: :1 + volumes: + - "/tmp/.X11-unix:/tmp/.X11-unix:rw" + build: + context: . + args: &common-args + ROS_DISTRO: "kinetic" + PYMYCOBOT_VERSION: ">=2<3" + BASE_IMAGE: nvidia/opengl:1.1-glvnd-runtime-ubuntu18.04 + services: + # This configuration builds the project for computers with NVIDIA hardware + nvidia-ros: *common + + # This is the default for computers that don't have nvidia hardware accelerators ros: - image: elephantrobotics/my-cobot-ros - command: ["roslaunch myCobotROS control_slider.launch"] - privileged: true - environment: - PYTHONUNBUFFERED: 1 - QT_X11_NO_MITSHM: 1 - DISPLAY: :1 - volumes: - - "/tmp/.X11-unix:/tmp/.X11-unix:rw" + <<: *common build: context: . args: - UBUNTU_VERSION: "16.04" - ROS_DISTRO: "kinetic" - PYMYCOBOT_VERSION: ">=2<3" + <<: *common-args + BASE_IMAGE: ubuntu:18.04